LightGBM: [ci] aarch64 python-package job failing: "cannot allocate memory in static TLS block"
Description
For the last few days, I’ve observed the aarch64 CI job (which we run on an x86_64 box, using QEMU for emulation), failing with errors like the following during test collection:
___________ ERROR collecting tests/python_package_test/test_basic.py ___________
ImportError while importing test module '/LightGBM/tests/python_package_test/test_basic.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/root/miniforge/envs/test-env/lib/python3.12/importlib/__init__.py:90: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/python_package_test/test_basic.py:12: in <module>
from sklearn.datasets import dump_svmlight_file, load_svmlight_file, make_blobs
/root/miniforge/envs/test-env/lib/python3.12/site-packages/sklearn/__init__.py:97: in <module>
from .utils._show_versions import show_versions
/root/miniforge/envs/test-env/lib/python3.12/site-packages/sklearn/utils/_show_versions.py:15: in <module>
from ._openmp_helpers import _openmp_parallelism_enabled
E ImportError: /root/miniforge/envs/test-env/lib/python3.12/site-packages/sklearn/utils/../../../../libgomp.so.1: cannot allocate memory in static TLS block
Reproducible example
This is happening across several different PRs, with changesets that are very unlikely to be causing this, suggesting it’s some other change in the environment. For example:
- PR: #6508
- build: https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=16492&view=logs&j=c2f9361f-3c13-57db-3206-cee89820d5e3&t=6c24f9ed-c6ce-5b46-2a4e-317f1b2c686c
Environment info
N/A
Additional Comments
“TLS” in this error refers to “thread-local storage”.
There is lots of prior discussion on similar issues:
- https://bugzilla.redhat.com/show_bug.cgi?id=1722181
- https://github.com/scikit-learn/scikit-learn/issues/28362
- https://github.com/dmlc/xgboost/issues/8488
- https://github.com/dmlc/xgboost/issues/7110#issuecomment-880841484
- https://github.com/pytorch/pytorch/issues/2575
- https://github.com/opencv/opencv/issues/14884
- https://github.com/conda-forge/scikit-learn-feedstock/pull/220
- https://github.com/dask-contrib/dask-sql/pull/1144
All of those are about using libgomp on aarch64.
From https://bugzilla.redhat.com/show_bug.cgi?id=1722181:
The GNU TLS2 model which I’m afraid aarch64 uses unfortunately eats from the same TLS preallocated pool as libraries that require static TLS like libgomp, where it is performance critical to have it as static TLS.
On https://github.com/opencv/opencv/issues/14884, there’s some discussion about this specifically being caused by bundled libgomp in multiple Python packages, and there are suggestions that importing those libraries earlier (and therefore loading their libgomp earlier) can resolve this.
These also have some helpful information:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16
Commits related to this issue
- [ci] restore aarch64 linux builds (fixes #6509) — committed to microsoft/LightGBM by jameslamb 2 years ago
- [ci] restore aarch64 linux builds (fixes #6509) (#6527) — committed to microsoft/LightGBM by jameslamb 2 years ago
- Reduce the MSAN TlS requirements to workaround glibc limitation Workaround issue where older glibc cannot allocate large TLS blocks after the program has started running ("cannot allocate memory in s... — committed to ccotter/llvm-project by ccotter 2 years ago
- Attempting to use heap instead of tls for large arrays Workaround issue where older glibc cannot allocate large TLS blocks after the program has started running ("cannot allocate memory in static TLS... — committed to ccotter/llvm-project by ccotter 2 years ago
I noticed that most of those are pyarrow and its dependencies, which helped me to narrow this down even further from https://github.com/microsoft/LightGBM/issues/6509#issuecomment-2212334291.
Importing just
pyarrowfollowing byscikit-learn(which causeslibgompto be loaded) is sufficient to reproduce the error (in the environment described in https://github.com/microsoft/LightGBM/issues/6509#issuecomment-2212334291):Just switching the order is sufficient to avoid the error, at least in this case.
That matches findings from many of the threads linked in the description of this issue. For example, from https://github.com/pytorch/pytorch/issues/2575.
It’s late in my timezone so I’m going to stop here for tonight. I’ll do some more testing soon. In short, I think that to get around this we should:
scikit-learn(which we know to have alibgomp.sodependency) as early as possiblepandasmanylinux_2_28) foraarch64Linux wheelsA couple of thoughts here:
Probably no great answer right now, but all the more incentive to work on https://discuss.python.org/t/implementation-variants-rehashing-and-refocusing/54884!