Repository navigation
Description
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"])
breakThen 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: NoneInterest 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
cakedev0 commentedon Jul 6, 2026
Some additional context from #17334 (comment):
[-]The PyPI wheel doesn't bundle the right `libgomp`[/-][+]The PyPI wheel doesn't bundle the right `libgomp` on Linux[/+]ogrisel commentedon Jul 6, 2026
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_LINUXvariable as suggested and the trigger a build with[cd build]and then confirm if the resulting wheel fixes the problem described in #17334 (comment)?david-cortes-intel commentedon Jul 7, 2026
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?
david-cortes-intel commentedon Jul 7, 2026
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
cakedev0 commentedon Jul 8, 2026
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.
ogrisel commentedon Jul 8, 2026
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.
lorentzenchr commentedon Jul 16, 2026
Be aware of lightgbm-org/LightGBM#6595. Bundling openmp is an intricate topic.
cakedev0 commentedon Aug 11, 2026
Some news:
While
GOMP_SPINCOUNT=300000is 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=1is 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_SPINCOUNTis read at init time of libgomp so we can't have a decorator that sets it just for HGB.fit...david-cortes-intel commentedon Aug 12, 2026
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?
cakedev0 commentedon Aug 12, 2026
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.
cakedev0 commentedon Aug 19, 2026
Note: on MacOS, the PyPI wheel bundles libomp (and not libgomp) and it's old too (2021), and hard-pinned, see:
scikit-learn/build_tools/wheels/build_wheels.sh
Lines 20 to 22 in 0c984ae
and what follows.
cakedev0 commentedon Nov 13, 2026
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.fitand CPU tensor operations, in both import orders:sklearn/.dylibs/libomp.dylibProbable 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'slibomp.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_callwaiting in the__kmp_suspend_64of the other libomp image. libomp 11 only shares the 4__kmp_dispatch_deo/dxotemplates 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.