GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: BLAS setup can silently fail and not be reported in show_config() · Issue #24200 · numpy/numpy

BUG: BLAS setup can silently fail and not be reported in show_config() #24200

New issue
Copy link
New issue
Copy link
Closed
#25063
Closed
BUG: BLAS setup can silently fail and not be reported in show_config()#24200
#25063
Copy link
Labels
00 - BugMesonItems related to the introduction of Meson as the new build system for NumPy
Milestone
1.26.2 release

Description

@larsoner
larsoner
opened on Jul 17, 2023
Issue body actions

Describe the issue:

With 2.0.0dev0 wheel on scientific-python-nightly-wheels there is a big slowdown for @ / dot for us. First noticed a ~1.5x slowdown in MNE-Python CIs, then went through a bunch of stuff with @seberg on Discord (thanks for your patience!). Finally I think I created a minimal example:

$ python3 -m venv ~/python/virtualenvs/npbad
$ source ~/python/virtualenvs/npbad/bin/activate
$ pip install --default-timeout=60 --extra-index-url "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple" "numpy==1.25.0rc1+218.g0e5a362fd"
$ pip list
Package    Version
---------- ------------------------
numpy      1.25.0rc1+218.g0e5a362fd
pip        23.0.1
setuptools 66.1.1
$ which python
/home/larsoner/python/virtualenvs/npbad/bin/python
$ python -m timeit -s "import numpy as np; x = np.random.RandomState(0).randn(300, 10000)" "x @ x.T"
20 loops, best of 5: 18.6 msec per loop
$ pip install --default-timeout=60 --upgrade --extra-index-url "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple" "numpy==2.0.0dev0"
$ python -m timeit -s "import numpy as np; x = np.random.RandomState(0).randn(300, 10000)" "x @ x.T"
1 loop, best of 5: 911 msec per loop

TL;DR: 18.6ms on "1.25.0rc1" from just under a month ago, 911ms on latest 2.0.0dev0 on my machine.

I've tried to reproduce this on main on my machine as well by building myself by setting dispatches, using meson or not, etc. but have only ever managed to get the good/fast time.

Reproduce the code example:

Above

Error message:

N/A

Runtime information:

Above

Context for the issue:

Above

Activity

Next
  1. larsoner
    added
    00 - Bug
    on Jul 17, 2023
  2. rgommers commented on Jul 17, 2023

    @rgommers
    rgommers
    on Jul 17, 2023
    Member
    More actions

    Thanks for the report @larsoner. That is probably simply expected right now, because SIMD support is incomplete in the Meson build. We can leave this open for a while, but I would recommend not investigating anything because looking at anything performance-related for a Meson vs. a distutils build isn't all that useful right now.

  3. rgommers
    added this to the 2.0.0 release milestone on Jul 17, 2023
  4. larsoner commented on Jul 17, 2023

    @larsoner
    larsoner
    on Jul 17, 2023
    ContributorAuthor
    More actions

    FWIW locally I built using the Meson and distutils backends and performance was the same. But maybe I didn't configure options properly to see the slowdown...

    I also kind of expected this to just get sent over to OpenBLAS so didn't think the SIMD / dispatch stuff would matter. So I thought perhaps an OpenBLAS version changed between a month ago and now and that had performance problems.

  5. rgommers commented on Jul 17, 2023

    @rgommers
    rgommers
    on Jul 17, 2023
    Member
    More actions

    TL;DR: 18.6ms on "1.25.0rc1" from just under a month ago, 911ms on latest 2.0.0dev0 on my machine.

    Oh wait, I missed that this was ~50x or so. If you rebuilt and it's both that much slower, maybe the build is silently using lapack_lite instead of OpenBLAS? This seems like a lot.

    We do have a whole bunch of logic in numpy/core/src/umath/matmul.c.src, so it's not always straightforward to determine that one is really library an optimized BLAS library.

  6. larsoner commented on Jul 17, 2023

    @larsoner
    larsoner
    on Jul 17, 2023
    ContributorAuthor
    More actions

    If you rebuilt and it's both that much slower, maybe the build is silently using lapack_lite instead of OpenBLAS? This seems like a lot.

    No it's the opposite rather -- locally I rebuilt using Meson and distutils with my own OpenBLAS that was the same each time (0.3.21 or something?), and it's just as fast as the 1.25.rc wheel from SPNW (no regression): the only problematic case seems to be the 2.0.0dev0 wheel.

    Both the 1.25.rc (fast) and 2.0.0dev0 (slow) show that the OpenBLAS lib used is "OpenBLAS 0.3.23 with 1 thread" when I look using threadpoolctl on my machine (locally I limit it to 1 thread). But if something changed about how that was built or what version was actually used (despite being reported the same) in the last ~30 days that's a good candidate!

  7. rgommers commented on Jul 17, 2023

    @rgommers
    rgommers
    on Jul 17, 2023
    Member
    More actions

    But if something changed about how that was built or what version was actually used (despite being reported the same) in the last ~30 days that's a good candidate!

    • The OpenBLAS builds we use saw some changes: https://github.com/MacPython/openblas-libs/pulls?q=is%3Apr+is%3Aclosed
    • We're also pulling in a different version and there's some wheel build related changes: https://github.com/numpy/numpy/commits/main/tools/openblas_support.py
  8. mattip commented on Jul 17, 2023

    @mattip
    mattip
    on Jul 17, 2023
    Member
    More actions

    How are you locally limiting OpenBLAS to one thread?

  9. mattip commented on Jul 17, 2023

    @mattip
    mattip
    on Jul 17, 2023
    Member
    More actions

    How are you locally limiting OpenBLAS to one thread?

    Nevermind, this reproduces even when not limiting OpenBLAS to one thread

  10. mattip commented on Jul 17, 2023

    @mattip
    mattip
    on Jul 17, 2023
    Member
    More actions

    As far as I can tell, both wheels use the same OpenBLAS site-packages/numpy.libs/libopenblas64_p-r0-7a851222.3.23.so

    Each build in the scheduled wheel build log has artifacts. Perhaps someone could download them and find the point at which the slowdown started.

  11. larsoner commented on Jul 18, 2023

    @larsoner
    larsoner
    on Jul 18, 2023
    ContributorAuthor
    More actions

    I can do it tomorrow morning EDT unless someone beats me to it (feel free!)

  12. larsoner commented on Jul 18, 2023

    @larsoner
    larsoner
    on Jul 18, 2023
    ContributorAuthor
    More actions

    Okay clearly I must have meant tomorrow July 19th EDT :)

  13. larsoner commented on Jul 18, 2023

    @larsoner
    larsoner
    on Jul 18, 2023
    ContributorAuthor
    More actions

    Actually it only took a couple of minutes to bisect using cp311-manylinux_x86_64:

    $ pip install --force-reinstall ~/Desktop/*5367488372/*.whl
    ...
    $ python -m timeit -s "import numpy as np; x = np.random.RandomState(0).randn(300, 10000)" "x @ x.T"
    20 loops, best of 5: 18.8 msec per loop
    $ pip install --force-reinstall ~/Desktop/*5396768625/*.whl
    ...
    larsoner@bunk:~/python/mne-installers$ python -m timeit -s "import numpy as np; x = np.random.RandomState(0).randn(300, 10000)" "x @ x.T"
    1 loop, best of 5: 913 msec per loop
    
    • The good 5367488372
      • commit message "0e2af84 Merge pull request BUG: Ensure __array_ufunc__ works without any kwargs passed #24031 from seberg/array-ufunc-no-kwargs"
      • 0e2af84 from 24 days ago
    • The bad 5396768625
      • commit message "85385d6 Merge pull request BLD: use -ftrapping-math with Clang on macOS in Meson build #24060 from rgommers/clang-floatingpoint-flags"
      • 85385d6 from 21 days ago

    Which I guess gets us this diff: https://github.com/numpy/numpy/compare/0e2af84..85385d6

  14. larsoner commented on Jul 18, 2023

    @larsoner
    larsoner
    on Jul 18, 2023
    ContributorAuthor
    More actions

    ... I am a bit worried about this meson check EDIT: potentially failing in the wheel build:

    https://github.com/numpy/numpy/compare/0e2af84..85385d6#diff-d4017f02419a9799bc2d59ae04399d2c45b9855443bb4a5ff7544ff76b040258

    It passing on my machine and failing in the wheel build (for some reason!) would be a possible explanation for the slowdown because @ might revert to a non-BLAS version...

  15. charris
    added
    09 - Backport-CandidatePRs tagged should be backported
    on Jul 18, 2023
  16. 25 remaining items

  17. rgommers commented on Jul 23, 2023

    @rgommers
    rgommers
    on Jul 23, 2023
    Member
    More actions

    Actually, I think I'll just clean it up straight away. I did a GitHub search and I don't find usage in the wild of the numpy.linalg.lapack_lite module. And since it's clearly broken and we're building the sources twice, let's just get rid of one of them. It's a 5 line diff to add the _ilp64 attribute that we need for testing to umath_linalg.cpp.

  18. rgommers
    added a commit that references this issue on Jul 23, 2023

    TST: fix running the test suite in builds without BLAS/LAPACK

    9480bc5
  19. rgommers commented on Jul 23, 2023

    @rgommers
    rgommers
    on Jul 23, 2023
    Member
    More actions

    Hmm, not entirely true unfortunately - numpy/linalg/tests/test_linalg.py contains a couple of test functions which use lapack_lite. And one of the two is for xerbla, which is a broken test - see #12472 (comment).

  20. rgommers
    added a commit that references this issue on Jul 23, 2023

    TST: fix running the test suite in builds without BLAS/LAPACK

    b59da2d
  21. rgommers commented on Jul 28, 2023

    @rgommers
    rgommers
    on Jul 28, 2023
    Member
    More actions

    gh-24279 adds an -Dallow-noblas=false build switch.

    Reacted by Eric Larson
  22. charris
    added a commit that references this issue on Aug 4, 2023

    TST: fix running the test suite in builds without BLAS/LAPACK

    b2489f2
  23. rgommers commented on Sep 27, 2023

    @rgommers
    rgommers
    on Sep 27, 2023
    Member
    More actions

    gh-24279 adds an -Dallow-noblas=false build switch.

    This caught some issues, but is also tripping folks up. The most annoying consequence is when a package has a transitive build-time dependency on numpy. That will start failing, it typically doesn't matter for building wheels, and it's very difficult to work around the problem because there's no good way to pass the -Dallow-noblas=false to a transitive dependency.

    We'll be reverting to defaulting to true on the 1.26.x branch, and probably also in main later on.

  24. larsoner commented on Sep 27, 2023

    @larsoner
    larsoner
    on Sep 27, 2023
    ContributorAuthor
    More actions

    there's no good way to pass the -Dallow-noblas=false to a transitive dependency.

    Could we make the default "True if env var NUMPY_ALLOW_NOBLAS is set and False otherwise"? Then these wheel builders or whoever can set this env var. Apologies if someone thought of this and discussed it already...

  25. rgommers commented on Sep 27, 2023

    @rgommers
    rgommers
    on Sep 27, 2023
    Member
    More actions

    That is possible, and we may end up doing that in main perhaps. I'm not thrilled about it though, because environment variables are really bad for diagnostics. I got rid of all of them (we had lots of partially documented and untested ones floating around), and right now all of the build options can be found in meson_options.txt, and the build log clearly shows any non-default values that were used. New environment variables bypass all that - it's like programming with globals.

  26. rgommers commented on Oct 12, 2023

    @rgommers
    rgommers
    on Oct 12, 2023
    Member
    More actions

    Update on this: for 1.26.1 we keep the value of -Dallow-noblas as false, in order to get bug reports rather than silent fallbacks to slow code in case anything changed with the updated BLAS/LAPACK detection (see gh-24893). We've had a bunch of complaints about this (see the tracking issue gh-24703), but not so many that it's super urgent to switch the default back.

  27. rgommers
    modified the milestones: 2.0.0 release, 1.26.2 release on Oct 12, 2023
  28. rgommers commented on Nov 3, 2023

    @rgommers
    rgommers
    on Nov 3, 2023
    Member
    More actions

    I just opened #25063 to revert the default to allow-noblas=true. That should land in 1.26.2 and 2.0.

    I decided against the environment variable for now, I really don't like it. The situation after gh-25063 will just go back to how it always was - with the difference that the warning about the slow fallback being used is much more prominent in the build log.

  29. charris
    closed this as completedin #25063on Nov 3, 2023
  30. charris
    added a commit that references this issue on Nov 11, 2023

    TST: fix running the test suite in builds without BLAS/LAPACK

    f6812e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugMesonItems related to the introduction of Meson as the new build system for NumPy

    Type

    No type

    Projects

    No projects

      Milestone

      • 1.26.2 release

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.