scipy: Seg fault when importing torch

In the latest release, if you import scipy and then pytorch, it’ll segfault. This did not happen in 1.3.3. It started at 1.4.0rc2

Reproducing code example:

# From a new virtualenv...
(venv) $ pip3 install torch
Collecting torch
  Using cached https://files.pythonhosted.org/packages/f9/34/2107f342d4493b7107a600ee16005b2870b5a0a5a165bdf5c5e7168a16a6/torch-1.3.1-cp37-cp37m-manylinux1_x86_64.whl
Collecting numpy (from torch)
  Cache entry deserialization failed, entry ignored
  Using cached https://files.pythonhosted.org/packages/9b/af/4fc72f9d38e43b092e91e5b8cb9956d25b2e3ff8c75aed95df5569e4734e/numpy-1.17.4-cp37-cp37m-manylinux1_x86_64.whl
Installing collected packages: numpy, torch
Successfully installed numpy-1.17.4 torch-1.3.1
(venv) $ python3 -c "import scipy;import torch"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'scipy'
(venv) $ pip3 install scipy
Collecting scipy
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/37/9d/a606dc7b17ef0b7326afd128e132b7a483d5611da603334842df75d92d3c/scipy-1.4.0-cp37-cp37m-manylinux1_x86_64.whl (26.1MB)
    100% |████████████████████████████████| 26.1MB 47kB/s 
Requirement already satisfied: numpy>=1.13.3 in ./venv/lib/python3.7/site-packages (from scipy) (1.17.4)
Installing collected packages: scipy
Successfully installed scipy-1.4.0
(venv) $ python3 -c "import scipy;import torch"
Segmentation fault (core dumped)

Error message:

Since it’s a segfault, I posted the GDB stacktrace here: https://gist.github.com/jdavidberger/b1d9870f4501a16fc4346bda46f98413

Scipy/Numpy/Python version information:

1.4.0 1.17.4 sys.version_info(major=3, minor=7, micro=5, releaselevel='final', serial=0)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 21 (14 by maintainers)

Commits related to this issue

Most upvoted comments

We are seeing a segfault with scipy 1.14 in a clean conda environment importing our own library (https://github.com/SeldonIO/alibi/blob/master/setup.py), everything works fine with 1.13. scipy is an indirect dependency so not sure what is going wrong, we don’t use torch but we do use tensorflow.

Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import alibi
[1]    847471 segmentation fault (core dumped)  python

Oops, yes, I failed to mention: Importing torch on it’s own is fine; as is importing torch before scipy.

I can also post an issue on pytorch’s issue tracker, but the thing that changed in my dev environment was going from scipy 1.3.3 to 1.4.0. I don’t know where the bug is exactly; but I figured since 1.4 is just out it’d be good to post here.

The patched wheels are up on PyPI now, so this may help if you use pip:

pip install scipy==1.4.1

Let’s see if our wheel builds are happy with the latest Pybind11: https://github.com/MacPython/scipy-wheels/pull/60

Confirmed that pip install tf-nightly scipy==1.4.1 fixes the TF issues. Thank you

I’m having the same issue:

>>> import transformers
Segmentation fault (core dumped)

root@261246f307ae:~/src# python --version Python 3.6.8

on Ubuntu16.04 running on Docker. I’m investigating why on two different machines I get the error just one one of them…

Nice find @peterbell10, we should release a 1.4.1 built with pybind11 2.4.0 asap I think, a lot of people are going to hit this problem quickly:(