<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">After upgrading to the latest SciPy (1.4.0, released on Tuesday), importing <code class="notranslate">torch</code> after <code class="notranslate">scipy</code> immediately segfaults.  My current workaround is pinning SciPy to &lt;1.4.0, which averts the crash.  Oddly, specifically importing <code class="notranslate">scipy</code> first and then <code class="notranslate">torch</code> is the only combination of the two that I've found to crash.</p>
<h2 dir="auto">To Reproduce</h2>
<ol dir="auto">
<li><code class="notranslate">python3 -m venv build/venv</code></li>
<li><code class="notranslate">. build/venv/bin/activate</code></li>
<li><code class="notranslate">pip install scipy torch</code></li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="% python -c 'import scipy, torch'
zsh: segmentation fault (core dumped)  python -c 'import scipy, torch'"><pre class="notranslate"><code class="notranslate">% python -c 'import scipy, torch'
zsh: segmentation fault (core dumped)  python -c 'import scipy, torch'
</code></pre></div>
</li>
</ol>
<p dir="auto">Using <code class="notranslate">cppyy</code> and <code class="notranslate">glog</code>'s signal handler, I was able to get some form of stack trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="*** Aborted at 1576699991 (unix time) try &quot;date -d @1576699991&quot; 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"><pre class="notranslate"><code class="notranslate">*** 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
</code></pre></div>
<p dir="auto">I don't know what SciPy has to do with this or why upgrading it causes segfaults inside PyTorch.</p>
<p dir="auto">For completeness, here's the <code class="notranslate">reproduce.py</code> script:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import cppyy
cppyy.load_library('glog')
cppyy.include('glog/logging.h')
cppyy.gbl.google.InstallFailureSignalHandler()
import scipy
import torch"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">cppyy</span>
<span class="pl-s1">cppyy</span>.<span class="pl-en">load_library</span>(<span class="pl-s">'glog'</span>)
<span class="pl-s1">cppyy</span>.<span class="pl-en">include</span>(<span class="pl-s">'glog/logging.h'</span>)
<span class="pl-s1">cppyy</span>.<span class="pl-s1">gbl</span>.<span class="pl-s1">google</span>.<span class="pl-v">InstallFailureSignalHandler</span>()
<span class="pl-k">import</span> <span class="pl-s1">scipy</span>
<span class="pl-k">import</span> <span class="pl-s1">torch</span></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">No segmentation fault.</p>
<h2 dir="auto">Environment</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="% 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"><pre class="notranslate"><code class="notranslate">% 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
</code></pre></div>
<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">Import <code class="notranslate">torch</code> after <code class="notranslate">sklearn</code> causes a segfault.</p>
<h2 dir="auto">To Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sklearn
import torch
print(torch.__version__)
print(sklearn.__version__)"><pre class="notranslate"><code class="notranslate">import sklearn
import torch
print(torch.__version__)
print(sklearn.__version__)
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/11019190/71001688-15df3680-20de-11ea-8441-16a58497c70b.png"><img src="https://user-images.githubusercontent.com/11019190/71001688-15df3680-20de-11ea-8441-16a58497c70b.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">In reverse order:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
import sklearn
print(torch.__version__)
print(sklearn.__version__)"><pre class="notranslate"><code class="notranslate">import torch
import sklearn
print(torch.__version__)
print(sklearn.__version__)
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/11019190/71001720-255e7f80-20de-11ea-9338-5f4adcf1ac2c.png"><img src="https://user-images.githubusercontent.com/11019190/71001720-255e7f80-20de-11ea-9338-5f4adcf1ac2c.png" alt="image" style="max-width: 100%;"></a></p>
<h2 dir="auto">Environment</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<h2 dir="auto">Additional context</h2>
<p dir="auto">Related closed issues:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="243779309" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/2143" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/2143/hovercard" href="https://github.com/pytorch/pytorch/issues/2143">#2143</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="208695074" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/786" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/786/hovercard" href="https://github.com/pytorch/pytorch/issues/786">#786</a></p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a></p>