Skip to content

What to do when receiving "RuntimeError: Polyfit sanity test emitted a warning"? #17253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
solarmist opened this issue Sep 5, 2020 · 14 comments

Comments

@solarmist
Copy link

solarmist commented Sep 5, 2020

I cannot use numpy >1.18.5 on macOS 11.0 (BigSur, but that probably isn't the issue) installed from PyPI because of the check for buggy Accelerate, but there isn't any guidance on how I should resolve this.

Reading some of the threads this is a system library, so I can't just uninstall it... It says to contact the vendor, but you're publishing directly to PyPI as best I can tell.

If I am getting this as an end user what should I do? (For now I've fallen back to 1.18.5, but that's not a permanent fix.). Is there a flag or something I can set to disable it or prefer a home-brew version of OpenBLAS?

Reproducing code example:

pip3 install numpy
python
import numpy

Error message:

Python 3.8.5 (default, Jul 28 2020, 10:47:05)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy
Python(4587,0x11935ae00) malloc: can't allocate region
:*** mach_vm_map(size=18446744071626620928, flags: 100) failed (error code=3)
Python(4587,0x11935ae00) malloc: *** set a breakpoint in malloc_error_break to debug
init_dgelsd failed init
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-d4cdadb62aa7> in <module>
----> 1 import numpy

~/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/__init__.py in <module>
    284                     "that provided NumPy.\n{}\n".format(
    285                         error_message))
--> 286                 raise RuntimeError(msg)
    287     del _mac_os_check
    288

RuntimeError: Polyfit sanity test emitted a warning, most likely due to using a buggy Accelerate backend. If you compiled yourself, see site.cfg.example for information. Otherwise report this to the vendor that provided NumPy.
RankWarning: Polyfit may be poorly conditioned

Numpy/Python version information:

1.19.0 and 1.19.1

@mattip
Copy link
Member

mattip commented Sep 5, 2020

We do not ship a wheel that uses Accelerate. Are you sure you used a binary wheel and did not compile one locally? There should be an OpenBLAS library ~/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/.dylibs/libopenblas.0.dylib. If not, try forcing pip to use a binary wheel and not compile:

python -mpip install --only-binary :all: numpy

@mattip
Copy link
Member

mattip commented Sep 5, 2020

Try using python -m pip instead of pip3 to ensure you are using the pip from the python you want to use, and not some other pip.

@solarmist
Copy link
Author

No luck.

└─(%)    which pip
/Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/bin/pip
└─(%)    which python
/Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/bin/python
└─(🐮%) pip config list
:env:.download-cache='/Users/solarmist/.pip/cache'
global.require-virtualenv='true'
└─(%)    pip --no-cache-dir install numpy
Collecting numpy
  Downloading numpy-1.19.1.zip (7.3 MB)
     |████████████████████████████████| 7.3 MB 2.3 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517) ... done
  Created wheel for numpy: filename=numpy-1.19.1-cp38-cp38-macosx_11_0_x86_64.whl size=4555330 sha256=f79484b0ec7ec4d028474d7ed83f362f3002e0813cb82359eec3f44400bb195b
  Stored in directory: /private/var/folders/5k/x0sc25pn1qjdll5h64vkx6tc0000gn/T/pip-ephem-wheel-cache-2ktgbrfi/wheels/df/b2/64/111c431ca7f7d49afb42126b7351fe1a4894803d75026360de
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.19.1
└─(%)    python
Python 3.8.5 (default, Jul 28 2020, 10:47:05)
[Clang 12.0.0 (clang-1200.0.26.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Python(28965,0x115307e00) malloc: can't allocate region
:*** mach_vm_map(size=18446744071615168512, flags: 100) failed (error code=3)
Python(28965,0x115307e00) malloc: *** set a breakpoint in malloc_error_break to debug
init_dgelsd failed init
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/__init__.py", line 286, in <module>
    raise RuntimeError(msg)
RuntimeError: Polyfit sanity test emitted a warning, most likely due to using a buggy Accelerate backend. If you compiled yourself, see site.cfg.example for information. Otherwise report this to the vendor that provided NumPy.
RankWarning: Polyfit may be poorly conditioned

And using the --only-binary flag showed me this.

└─(%) python -mpip install --only-binary ":all:" numpy
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy
└─(1:%)    python -mpip install --only-binary ":none:" numpy
Processing /Users/solarmist/Library/Caches/pip/wheels/df/b2/64/111c431ca7f7d49afb42126b7351fe1a4894803d75026360de/numpy-1.19.1-cp38-cp38-macosx_11_0_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.19.1
└─(%)    python
Python 3.8.5 (default, Jul 28 2020, 10:47:05)
[Clang 12.0.0 (clang-1200.0.26.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Python(29352,0x10f852e00) malloc: can't allocate region
:*** mach_vm_map(size=18446744072594292736, flags: 100) failed (error code=3)
Python(29352,0x10f852e00) malloc: *** set a breakpoint in malloc_error_break to debug
init_dgelsd failed init
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/__init__.py", line 286, in <module>
    raise RuntimeError(msg)
RuntimeError: Polyfit sanity test emitted a warning, most likely due to using a buggy Accelerate backend. If you compiled yourself, see site.cfg.example for information. Otherwise report this to the vendor that provided NumPy.
RankWarning: Polyfit may be poorly conditioned

The libs don't exist.

└─(🐮%)    ls -la ~/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/.dylibs/
ls: /Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages/numpy/.dylibs/: No such file or directory

The numpy dir is there though.

@mattip
Copy link
Member

mattip commented Sep 5, 2020

The lack of success with --only-binary, mean you are building a local NumPy. This is not good, as you will pick up the buggy Accelerate. The best thing to do is discover why you cannot install with --only-binary. This could lie anywhere with some local environmental variables, access to https://pypi.org/project/numpy/#files, your version of pip, and some problem with macOS. The file you want is numpy-1.19.1-cp38-cp38-macosx_10_9_x86_64.whl. I would advise you to fix the root cause, since you will want to install other packages like matplotlib and scipy without having to rebuild them all.

Another option is to use conda or homebrew instead.

@solarmist
Copy link
Author

Ok, if I bypass the checks and install the wheel directly everything is working fine. It seems like the problem occurs only when installing from source without doing any further configuration.

The -t was just to avoid the tag checks since I'm on macOS 11.
pip install -t /Users/solarmist/Library/Caches/pypoetry/virtualenvs/trowel-_VpiQgrk-py3.8/lib/python3.8/site-packages --upgrade numpy-1.19.1-cp38-cp38-macosx_10_9_x86_64.whl

@mathstuf
Copy link

mathstuf commented Oct 8, 2020

I'm seeing this with a locally-compiled numpy (seen when building scipy). Should I just disable Accelerate in this case (we already have blas/lapack compiled ourselves)?

And no, we can't use wheels in this situation (before anyone suggests it).

@mathstuf
Copy link

mathstuf commented Oct 8, 2020

And I'm seeing this on 10.15, not 11.

@mathstuf
Copy link

mathstuf commented Oct 9, 2020

And we weren't seeing this problem on the same machine with NumPy 1.16.4 (which is the version we were using before).

@seberg
Copy link
Member

seberg commented Oct 9, 2020

The issue is that the failure (sanity check) indicates serious issues that can lead to wrong results for at least some linear algebra functions. So it seems better to error early, rather than potentially give you wrong results.

You mentioned that you have your own blas/lapack, in that case you should be able to set up the site.cfg file so that NumPy is explicitly linked against that version instead of picking up a system blas.

@mathstuf
Copy link

mathstuf commented Oct 9, 2020

We had been doing that. Having read the docs more, it seems that NPY_x_ORDER is preferred now which is my next experiment. We had been using BLAS and LAPACK environment variables before and they seem to now be ignored?

@seberg
Copy link
Member

seberg commented Oct 9, 2020

@mathstuf quick question, are you also setting the rpath? Can you check what ldd on import numpy as np; print(np.core._multiarray_umath.__file__) looks like? I may be missing some mac specific things here, but my thought is that the run-time may be picking up the first cblas it finds due to a missing rpath right now.

@mathstuf
Copy link

mathstuf commented Oct 9, 2020

We have a post-processing step which fixes library references. Everything should be using absolute paths for library ids before that. I'll try and take a peek on the CI machine while it's building.

@seberg
Copy link
Member

seberg commented Oct 9, 2020

@mathstuf there were some issues previously that import order mattered. Some other package picked up the system cblas and then that would cause NumPy to use that as well on macs. (I.e. there were reports where this error happened e.g. in Ipython notebooks or GUIs, but not in a plain python shell.)

I do not know if such a thing might be complicating things for you, nor am I a linking specialist, but it does seem like the issue must be with the linking somewhere.

@mathstuf
Copy link

mathstuf commented Oct 9, 2020

I missed the CI window unfortunately for seeing what it was in-flight :/ . The NPY_*_ORDER variables seem to have worked though. FWIW, these were not mentioned in any changelog that I can see (not that I checked that first either, but something I need to remember to do more often anyways).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants