Skip to content

The PyPI wheel doesn't bundle the right libgomp on Linux #34437

Open

Description

@cakedev0

Warning

This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.

Describe the bug and give evidence about its user-facing impact

The PyPI wheel bundles libgomp.so.1.0.0-8.5.0-28.el8_10.alma.1.x86_64.debug which is probably not what we want.

Despite scikit-learn building in manylinux_2_28, whose docs say the toolchain is GCC 14, the bundled OpenMP runtime is effectively AlmaLinux 8 / GCC 8.5-era libgomp.

Codex suggests to add this repair command around here to the linux build:

          CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
            LD_LIBRARY_PATH=/opt/rh/gcc-toolset-14/root/usr/lib64:$LD_LIBRARY_PATH
            auditwheel repair -w {dest_dir} {wheel}

auditwheel repair decides which concrete shared object to copy into scikit_learn.libs (what is bundled in the PyPi wheel). Without help, it resolves the base AlmaLinux 8 runtime. With LD_LIBRARY_PATH pointing to gcc-toolset first, it should resolve to the newer gcc-toolset libgomp.

Steps/Code to Reproduce

Run from a PiPy sklearn on Linux:

import threadpoolctl

for info in threadpoolctl.threadpool_info():
    if info.get("prefix") == "libgomp":
        print(info["filepath"])
        break

Then in bash:

LIBGOMP="<what was printed by the python snippet>
strings "$LIBGOMP" | grep -E "libgomp.so.1.0.0-|annobin gcc|running gcc"

You'll see something like:

annobin gcc 8.5.0 20210514
running gcc 8.5.0 20210514
libgomp.so.1.0.0-8.5.0-28.el8_10.alma.1.x86_64.debug

Expected Results

N/A

Actual Results

N/A

Versions

System:
    python: 3.12.13 | packaged by conda-forge | (main, Mar  5 2026, 16:50:00) [GCC 14.3.0]
executable: /home/arthur/probabl/scikit-learn-benchmarks/.pixi/envs/sklearn/bin/python
   machine: Linux-6.17.0-35-generic-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.9.0
          pip: None
   setuptools: None
        numpy: 2.4.6
        scipy: 1.17.1
       Cython: None
       pandas: 2.3.3
   matplotlib: 3.11.0
       joblib: 1.5.3
threadpoolctl: 3.6.0
     narwhals: 2.23.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /home/arthur/probabl/scikit-learn-benchmarks/.pixi/envs/sklearn/lib/libopenblasp-r0.3.33.so
        version: 0.3.33
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /home/arthur/probabl/scikit-learn-benchmarks/.pixi/envs/sklearn/lib/python3.12/site-packages/scikit_learn.libs/libgomp-e985bcbb.so.1.0.0
        version: None

Interest in fixing the bug

Yes... Well, I mean I'm interested in doing what Codex suggests and testing it. It seems like it's the proper fix.

Activity

  1. added
    Needs Triage
    on Jul 6, 2026
  2. cakedev0 commented on Jul 6, 2026

    @cakedev0
    MemberAuthor

    Some additional context from #17334 (comment):

    • conda-forge scikit-learn comes libgomp from GCC 15.2, so having the libgomp from GCC 14 in the PyPi wheel would be more consistent.
    • More recent libgomp comes with GOMP_SPINCOUNT=1 instead of GOMP_SPINCOUNT=300000 which can damage performance of cases with many small OMP regions (which is something to avoid anyway, as it still scales counter-productively with GOMP_SPINCOUNT=300000). I will soon have some scaling measures of HGB under different builds, this should help evaluating the impact.
  3. moved this to Todo in Labson Jul 6, 2026
  4. changed the title [-]The PyPI wheel doesn't bundle the right `libgomp`[/-] [+]The PyPI wheel doesn't bundle the right `libgomp` on Linux[/+] on Jul 6, 2026
  5. added
    Needs Investigation
    and removed
    Needs Triage
    on Jul 6, 2026
  6. ogrisel commented on Jul 6, 2026

    @ogrisel
    Member

    Thanks for investigating, this is very promising.

    In the threadpoolctl Python snippet, you probably need to "import sklearn.ensemble" explicitly to trigger the link of the openmp runtime before calling threadpoolctl.threadpool_info().

    Could you please open a draft PR that configures the CIBW_REPAIR_WHEEL_COMMAND_LINUX variable as suggested and the trigger a build with [cd build] and then confirm if the resulting wheel fixes the problem described in #17334 (comment)?

  7. david-cortes-intel commented on Jul 7, 2026

    @david-cortes-intel
    Contributor

    What would happen if another library using OMP is loaded before importing sklearn? For example, xgboost also ships its own libgomp (same e985bcbb).

    Would it perhaps make sense to issue a warning if it detects a libgomp with potentially harmful settings?

  8. david-cortes-intel commented on Jul 7, 2026

    @david-cortes-intel
    Contributor

    More recent libgomp comes with GOMP_SPINCOUNT=1 instead of GOMP_SPINCOUNT=300000

    That sounds like it might be a bug, since the documentation states otherwise. This is the documentation for the latest version:
    https://gcc.gnu.org/onlinedocs/gcc-16.1.0/libgomp/GOMP_005fSPINCOUNT.html

  9. cakedev0 commented on Jul 8, 2026

    @cakedev0
    MemberAuthor

    It's not a bug, it's because on hybrid CPUs (with P-cores & E-cores), the default is 1 not 300k. See this for instance.

    I just learned that, which is very interesting because this is a direction we have been hesitating to take or not : have some special policies for hybrid CPUs. I'll try to find the initial discussion but at first sight, it seems to have been a benchmark-driven decision.

  10. ogrisel commented on Jul 8, 2026

    @ogrisel
    Member

    Could you please open a draft PR that configures the CIBW_REPAIR_WHEEL_COMMAND_LINUX variable as suggested and the trigger a build with [cd build] and then confirm if the resulting wheel fixes the problem described in #17334 (comment)?

    While we could fix the problem for scikit-learn wheels only, xgboost, lightgbm and other projects that builds OpenMP native extensions will have the same problem and it might better want to fix the problem upstream to vendor a consistent version of OpenMP in all manylinux wheels generated from the same version of the manylinux image.

  11. lorentzenchr commented on Jul 16, 2026

    @lorentzenchr
    Member

    Be aware of lightgbm-org/LightGBM#6595. Bundling openmp is an intricate topic.

  12. cakedev0 commented on Aug 11, 2026

    @cakedev0
    MemberAuthor

    Some news:

    While GOMP_SPINCOUNT=300000 is highly inefficient for high-frequency BLAS/OpenMP alternance (relatively rare in our code, honestly I don't think a lot of real use-cases hit this, even if some probably do), it's highly beneficial for repeated OpenMP regions which we have for a typical fit of HGB (we have it a lot! like 100x32x5 pranges for default parameters).

    I am making some HGB scaling benchmarks with various sklearn builds (PyPi, conda-forge, etc.), and basically GOMP_SPINCOUNT=1 is catastrophic! (2 to 10x slower for default number of threads on a laptop, depending on the dataset size).
    I will post links to some dashboards.

    Note: GOMP_SPINCOUNT is read at init time of libgomp so we can't have a decorator that sets it just for HGB.fit...

  13. david-cortes-intel commented on Aug 12, 2026

    @david-cortes-intel
    Contributor

    Some news:

    While GOMP_SPINCOUNT=300000 is highly inefficient for high-frequency BLAS/OpenMP alternance (relatively rare in our code, honestly I don't think a lot of real use-cases hit this, even if some probably do), it's highly beneficial for repeated OpenMP regions which we have for a typical fit of HGB (we have it a lot! like 100x32x5 pranges for default parameters).

    I am making some HGB scaling benchmarks with various sklearn builds (PyPi, conda-forge, etc.), and basically GOMP_SPINCOUNT=1 is catastrophic! (2 to 10x slower for default number of threads on a laptop, depending on the dataset size). I will post links to some dashboards.

    Note: GOMP_SPINCOUNT is read at init time of libgomp so we can't have a decorator that sets it just for HGB.fit...

    Is this performance issue in the scenario of repeated OMP regions perhaps solvable by setting number of threads to physical cores instead of logical threads?

  14. cakedev0 commented on Aug 12, 2026

    @cakedev0
    MemberAuthor

    We already set the number of threads to physical cores 😅

    For info, the 3 laptops I know have (physical cores / logical cores): 16/16, 14/14, 12/16.

  15. cakedev0 commented on Aug 19, 2026

    @cakedev0
    MemberAuthor

    Note: on MacOS, the PyPI wheel bundles libomp (and not libgomp) and it's old too (2021), and hard-pinned, see:

    # Make sure to use a libomp version binary compatible with the oldest
    # supported version of the macos SDK as libomp will be vendored into the
    # scikit-learn wheels for macos.

    and what follows.

  16. cakedev0 commented on Nov 13, 2026

    @cakedev0
    MemberAuthor

    A data point on the macOS side, in case we consider updating the pinned libomp there: a recent libomp crashes next to the PyPI PyTorch wheel, and the old one protects us from that.

    I hit it in cakedev0/sklearn-contrib-emeans#15, whose macOS wheels vendor conda-forge's llvm-openmp 23.1.5. Then I reproduced it with scikit-learn alone (macOS 27 arm64, Python 3.12, scikit-learn 1.9.1 and torch 2.15.0 from PyPI), alternating HistGradientBoostingRegressor.fit and CPU tensor operations, in both import orders:

    sklearn/.dylibs/libomp.dylib Result
    as published (libomp 11) OK, 6 runs out of 6
    replaced by conda-forge llvm-openmp 23.1.5 4 segfaults, 2 deadlocks

    Probable cause: recent libomp builds export weak symbols for C++ template instantiations of the runtime internals (__kmp_suspend_64<...>, __kmp_resume_64<...>, __kmp_execute_tasks_64<...>, ..., 22 in total, the same in llvm-openmp 23.1.5 and in PyTorch's libomp.dylib). dyld coalesces weak symbols across images, so the two runtimes end up calling into each other. The stack of a deadlocked process shows PyTorch's __kmpc_fork_call waiting in the __kmp_suspend_64 of the other libomp image. libomp 11 only shares the 4 __kmp_dispatch_deo/dxo templates with PyTorch's.

    So on macOS, updating the bundled libomp needs either a build that doesn't export these symbols, or a check next to the PyTorch wheel. I only tested arm64. Details in the linked issue.

    Investigated with Claude Code.

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

    BugNeeds Investigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions