Issue 1:
🐛 Bug

After upgrading to the latest SciPy (1.4.0, released on Tuesday), importing torch after scipy immediately segfaults. My current workaround is pinning SciPy to <1.4.0, which averts the crash. Oddly, specifically importing scipy first and then torch is the only combination of the two that I've found to crash.

To Reproduce

python3 -m venv build/venv

. build/venv/bin/activate

pip install scipy torch

% python -c 'import scipy, torch'
zsh: segmentation fault (core dumped) python -c 'import scipy, torch'

Using cppyy and glog's signal handler, I was able to get some form of stack trace:

*** Aborted at 1576699991 (unix time) try "date -d @1576699991" if you are using GNU date ***
PC: @ 0x7f96f9542db6 pybind11::detail::make_new_python_type()
*** SIGSEGV (@0x330) received by PID 11372 (TID 0x7f97125fe740) from PID 816; stack trace: ***
@ 0x7f971205af20 (unknown)
@ 0x7f96f9542db6 pybind11::detail::make_new_python_type()
@ 0x7f96f954ce86 pybind11::detail::generic_type::initialize()
@ 0x7f96f96cab5e torch::onnx::initONNXBindings()
@ 0x7f96f94c2eb0 initModule()
@ 0x5fba6f _PyImport_LoadDynamicModuleWithSpec
@ 0x5fbced (unknown)
@ 0x5678ee PyCFunction_Call
@ 0x51171e _PyEval_EvalFrameDefault
@ 0x508245 (unknown)
@ 0x50a080 (unknown)
@ 0x50aa7d (unknown)
@ 0x50c5b9 _PyEval_EvalFrameDefault
@ 0x509d48 (unknown)
@ 0x50aa7d (unknown)
@ 0x50c5b9 _PyEval_EvalFrameDefault
@ 0x509d48 (unknown)
@ 0x50aa7d (unknown)
@ 0x50c5b9 _PyEval_EvalFrameDefault
@ 0x509d48 (unknown)
@ 0x50aa7d (unknown)
@ 0x50c5b9 _PyEval_EvalFrameDefault
@ 0x509d48 (unknown)
@ 0x50aa7d (unknown)
@ 0x50c5b9 _PyEval_EvalFrameDefault
@ 0x509455 _PyFunction_FastCallDict
@ 0x5a55a1 _PyObject_FastCallDict
@ 0x5a65de _PyObject_CallMethodIdObjArgs
@ 0x4f729d PyImport_ImportModuleLevelObject
@ 0x50e4f1 _PyEval_EvalFrameDefault
@ 0x508245 (unknown)
@ 0x5167b9 (unknown)
./run.sh: line 10: 11372 Segmentation fault (core dumped) python reproduce.py

I don't know what SciPy has to do with this or why upgrading it causes segfaults inside PyTorch.

For completeness, here's the reproduce.py script:

import cppyy
cppyy.load_library('glog')
cppyy.include('glog/logging.h')
cppyy.gbl.google.InstallFailureSignalHandler()
import scipy
import torch

Expected behavior

No segmentation fault.

Environment

% python collect_env.py
Collecting environment information...
PyTorch version: 1.3.1
Is debug build: No
CUDA used to build PyTorch: 10.1.243

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.10.2

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.2.89
GPU models and configuration: GPU 0: GeForce GTX 1080
Nvidia driver version: 440.33.01
cuDNN version: Could not collect

Versions of relevant libraries:
[pip3] numpy==1.17.4
[pip3] torch==1.3.1
[conda] Could not collect

Issue 2:
🐛 Bug

Import torch after sklearn causes a segfault.

To Reproduce

import sklearn
import torch
print(torch.__version__)
print(sklearn.__version__)

In reverse order:

import torch
import sklearn
print(torch.__version__)
print(sklearn.__version__)

Environment

PyTorch version: 1.3.1
Is debug build: No
CUDA used to build PyTorch: 10.1.243

OS: Manjaro Linux
GCC version: (GCC) 9.2.0
CMake version: version 3.16.0

Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: 10.2.89
GPU models and configuration: GPU 0: GeForce RTX 2080 Ti
Nvidia driver version: 430.64
cuDNN version: /usr/lib/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip3] numpy==1.17.4
[pip3] torch==1.3.1
[pip3] torchvision==0.4.2
[conda] Could not collect

Additional context

Related closed issues:

#2143

#786

cc @ezyang @gchanan @zou3519