Skip to content

[ci] aarch64 python-package job failing: "cannot allocate memory in static TLS block"Β #6509

Closed

Description

@jameslamb

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:

Environment info

N/A

Additional Comments

"TLS" in this error refers to "thread-local storage".

There is lots of prior discussion on similar issues:

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 opencv/opencv#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:

Activity

  1. added
    blocking
    on Jun 28, 2024
  2. jameslamb commented on Jun 28, 2024

    @jameslamb
    MemberAuthor

    I recall now that allocation of static TLS was one of the reasons we switched x86_64 wheels to manylinux_2_28 (#5584 (comment))... there were some fixes in newer GLIBC versions related to it.

    Similarly, a comment from August 2020 on https://bugzilla.redhat.com/show_bug.cgi?id=1722181 says:

    the fix in glibc is allowing the installer to run correctly without the LD_PRELOAD workaround

    So it's possible that we'd be less likely to see this if we moved aarch64 builds to a newer GLIBC.

    They're currently using manylinux2014: https://github.com/guolinke/lightgbm-ci-docker/blob/a0df140729a4006b4ff87b880e7aa53934ecc0e7/images/manylinux2014_aarch64/Dockerfile#L1

  3. pinned this issue on Jul 2, 2024
  4. jameslamb commented on Jul 2, 2024

    @jameslamb
    MemberAuthor

    I just tried a rebuild, and this is still happening: https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=16481&view=logs&j=7a417b3a-6502-5a0d-1db8-7ef6155c93de&t=380f8b13-0b2d-5f03-5de0-8353018c7351

    Looking more closely at the logs, I noticed that it is happening whenever a libgomp.so is loaded... sometimes from loading scikit-learn's bundled one

    E   ImportError: /root/miniforge/envs/test-env/lib/python3.12/site-packages/sklearn/utils/../../../../libgomp.so.1: cannot allocate memory in static TLS block
    

    sometimes conda's

    E   OSError: /root/miniforge/envs/test-env/bin/../lib/libgomp.so.1: cannot allocate memory in static TLS block
    

    So I suspect part of the problem is "if you use scikit-learn, it's likely 2 libgomp.so.1s are going to be loaded"... maybe because of some change to the order of imports somewhere down the call stack. I'll keep testing changes.

  5. jmoralez commented on Jul 3, 2024

    @jmoralez
    Collaborator

    Just spitballing here but since we're getting conda's libgomp, we could also try installing conda's c++ compiler in that job and that'd link against that libgomp, which is the one being loaded by numpy and scipy, and maybe that'd solve the issue. WDYT?

  6. jameslamb commented on Jul 3, 2024

    @jameslamb
    MemberAuthor

    It looks like cuml is running into similar issues (also only in its aarch64 builds): NVIDIA/cuml#5949

    It has lots of the same dependencies as lightgbm (like scikit-learn, numpy, scipy, dask, and distributed from conda-forge).


    we could also try installing conda's c++ compiler in that job and that'd link against that libgomp, which is the one being loaded by numpy and scipy

    Interesting idea! Thanks for catching that conda-forge's libgomp is getting pulled into the environment... that might point to a source of the problem.

    I'm nervous about using conda's compilers to build a wheel that's intended to be distributed for use outside of conda.

    conda's toolchain is configured for producing conda packages, and I know it does things like rewriting paths in binaries so that conda's libraries will always be found. (not sure how much of that happens in compilers/linkers vs. in conda-build though).

    BUT... that's testable, and it's worth testing. I can try that to see if it'd help.

    Another thing I'm going to test... I'm going to try reducing the tests to simply import lightgbm and see if that's sufficient to trigger this problem. If it is, that'd narrow it down signficantly.

  7. jmoralez commented on Jul 3, 2024

    @jmoralez
    Collaborator

    Oh sorry, I didn't realize that job was building wheels. We could also go the other way and drop conda from that job, I've used uv a lot lately and it's great.

  8. jameslamb commented on Jul 3, 2024

    @jameslamb
    MemberAuthor

    drop conda from that job

    I like that idea too! Although it could be pretty involved... I suspect conda is doing a LOT of useful environment-resolution work for us that might be difficult to replicate.

    As a start... would you support commenting out this CI job for now so that we can keep making progress in the repo while we investigate this? With the understanding that this would have to be fixed and working again before we do the next release.

    I'm really happy with the recent pace of non-maintainer contributions we've been getting, and I'd like to get those peoples' work merged so we build momentum with them:

    @mayer79 and @nicklamiller in particular have been more patient with us than they should have to be, waiting on various CI issues πŸ˜…

  9. jmoralez commented on Jul 3, 2024

    @jmoralez
    Collaborator

    would you support commenting out this CI job for now so that we can keep making progress in the repo while we investigate this?

    Sure! That shouldn't block our CI since it's just a packaging problem.

  10. jameslamb commented on Jul 3, 2024

    @jameslamb
    MemberAuthor

    put up #6517

    Thankfully we now have that one macOS job still providing coverage of compiling LightGBM on aarch64.

  11. msarahan commented on Jul 3, 2024

    @msarahan

    A couple of thoughts here:

    1. Are you installing scikit-learn from PyPI (a wheel?) If so, is it an option to install that from conda? The conda package should not bundle libgomp, and so should not have this problem.
    2. I wonder if scikit-learn has thought about name-mangling their copy of libgomp to avoid these issues. That would come at the cost of multiple copies of libgomp being loaded in one process, which may explode resource contention.

    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!

  12. jameslamb commented on Jul 3, 2024

    @jameslamb
    MemberAuthor

    Thanks @msarahan ! We're getting scikit-learn from conda-forge.

    Looking at the log more closely, I don't think this has anything to do with scikit-learn bundling its own libgomp. Its conda package doesn't do that (as you said and as we'd expect):

    wget https://anaconda.org/conda-forge/scikit-learn/1.5.1/download/linux-aarch64/scikit-learn-1.5.1-py311haece950_0.conda
    
    mkdir -p ./tmp
    cph extract \
       --dest ./tmp \
       ./scikit-learn-1.5.1-py311haece950_0.conda
    
    find ./tmp -name '*libgomp*'
    # (empty)

    I think I was confused by this log line

    /root/miniforge/envs/test-env/lib/python3.12/site-packages/sklearn/utils/../../../../libgomp.so.1
    

    If you trace back all those relative paths, that's actually /root/miniforge/envs/test-env/lib/libgomp.so.1... the one coming from conda-forge.

  13. removed
    blocking
    on Jul 4, 2024
  14. jameslamb commented on Jul 5, 2024

    @jameslamb
    MemberAuthor

    Had an idea tonight πŸ’‘

    Now that GitHub Actions offers a free aarch64 macOS runner (#6391), we could probably build aarch64 linux wheels on that runner + Docker! That should be much faster than the approach we were using (QEMU emulation of aarch64 on an x86_64 system), because it wouldn't require emulation. πŸ˜€

  15. 4 remaining items

  16. added a commit that references this issue on Jul 8, 2024
    670fcad
  17. added a commit that references this issue on Jul 10, 2024
    fec9afa
  18. unpinned this issue on Jul 12, 2024
  19. github-actions commented on Jul 16, 2025

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity since it was closed.
    To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

  20. locked as resolved and limited conversation to collaborators on Jul 16, 2025
  21. unlocked this conversation on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions