You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python 3.15t segfault when importing numpy.random #2171
I was able to reproduce the issue 2171 segfault locally by using the exact GitHub Actions Python distribution from actions/python-versions, rather than a locally built CPython 3.15t.
The failure does not currently look like a cuda_pathfinder implementation bug. The reduced reproducer is:
With that workaround, the full local cuda_pathfinder test suite passed under the same reproduced environment:
973 passed, 6 skipped in 6.71s
This suggests issue 2171 should probably be tracked as an incompatibility between the GitHub Actions Python 3.15t beta build and the custom NumPy 2.4.6 cp315t wheel, exposed by pytest-randomly, rather than as a CUDA pathfinder library discovery failure.
Agent-facing full details
Original failing CI job
The original CI failure was in the PR 2108 GitHub Actions job:
The CI environment installed only cuda_pathfinder's basic test dependency group before the crash, not test-cu13. It also installed a custom NumPy prerelease/free-threaded wheel:
There is no pytest session header. This means the crash happens during Python / pytest / plugin startup, before pytest begins normal collection output.
Fatal Python error: Segmentation fault
<Cannot show all threads while the GIL is disabled>
Stack (most recent call first):
File "/wrk/forked/cuda-python/Py3150b2Venv/lib/python3.15t/site-packages/numpy/random/_pickle.py", line 7 in <module>
File "/wrk/forked/cuda-python/Py3150b2Venv/lib/python3.15t/site-packages/numpy/random/__init__.py", line 180 in <module>
File "/wrk/forked/cuda-python/Py3150b2Venv/lib/python3.15t/site-packages/numpy/__init__.py", line 718 in __getattr__
File "/wrk/forked/cuda-python/Py3150b2Venv/lib/python3.15t/site-packages/pytest_randomly/__init__.py", line 51 in <module>
File "<string>", line 1 in <module>
This passed locally in the reproduced environment:
973 passed, 6 skipped in 6.71s
The skipped tests were expected in this local environment:
SKIPPED [3] tests/conftest.py:43: libnvcudla.so is not loadable via canary subprocess on this host.
SKIPPED [2] tests/test_find_nvidia_headers.py:127: nvidia-cutlass not available on Python 3.15 (scipy missing)
SKIPPED [1] tests/test_utils_env_vars.py:93: Windows-specific case-folding check
The cuda_pathfinder test suite is not required to reproduce the crash. It only encounters the issue because its test dependency group includes pytest-randomly, and pytest auto-loads installed plugins by default.
The reason local testing originally passed is that the locally built CPython 3.15t was not identical to the GitHub Actions Python distribution:
Local non-crashing Python:
Python 3.15.0b2 free-threading build (tags/v3.15.0b2:94a64bbc6ce, Jun 8 2026, 20:42:06) [GCC 13.3.0]
Actions crashing Python:
Python 3.15.0b2 free-threading build (main, Jun 3 2026, 14:43:48) [GCC 11.4.0]
Suggested next steps
For unblocking cuda-python CI, the narrow workaround is to disable pytest-randomly for Python 3.15t jobs, for example by passing:
-p no:randomly
or by setting:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
and explicitly loading only required plugins. The -p no:randomly workaround is smaller and was verified locally.
For root cause, report the minimal reproducer to the owner of the custom NumPy cp315t wheel / NumPy prerelease build process:
Please let me know any questions about the files there.
@leofang What priority would you give to this issue? It seems likely that others will run into the same issue, and it'll get resolved even if we just wait for new Python 3.15.0 releases.
However, would it make sense to bump to 24.04 for our CI, because that Python version works.
Sounds good to me in general, I just looked, there is a 26.04 already, although very recent. Modernizing to 24.04 seems like a good conservative move if we're having issues with 22.04. I'd be surprised though if that didn't tickle some other things that need tweaks and workarounds, but at least worth a try?
In case anyone here was curious: This was actually an UB (memcpy with null pointer) bug in Python that has been fixed. It just seems it showed up randomly across various builds.
Yesterday I noticed that the Python 3.15 and 3.15t pathfinder tests running under ci.yml passed before PR #2376 when using Python 3.15.0b3, then segfaulted (test-linux-64 only) 12/12 times across the PR and post-merge main runs under 3.15.0b4.
In the meantime @mdboom determined (PR #2392) that importing numpy.random triggers the segfault again.
Yeah, probably best to try gh-2401 first (it's needed anyway), sorry I haven't looked at earlier. Both NumPy and Python fixed the previous issue, so this must be new.
I am wondering again if there is a chance of an ABI break between beta 2 (build) and beta 4 (runtime) but I can't see direct evidence (even if it seems what change); if it is ABI 2401 may not help and the build job Python versions may be the next to try bumping.
OK, I dug into it with the help of an agent and finally found that there was an ABI break in b4. The PyThreadState struct got a new field before the current_exception and Cython likes to optimize things like PyErr_Occurred() (which apparently get's called at import time or so).
I'll try to just pin to b2 for the test-time (matching cibuildwheel), but it's annoying of course, latest at the time of rc1 cuibuildwheel will soon after bump to that and we'll have to remove it again (no need for an exact pin at that point).
OK, I dug into it with the help of an agent and finally found that there was an ABI break in b4. The PyThreadState struct got a new field before the current_exception and Cython likes to optimize things like PyErr_Occurred() (which apparently get's called at import time or so).
I'll try to just pin to b2 for the test-time (matching cibuildwheel), but it's annoying of course, latest at the time of rc1 cuibuildwheel will soon after bump to that and we'll have to remove it again (no need for an exact pin at that point).
Thanks for investigating this! The segfault is blocking our CI. So numpy wheel for b4 is not available at the moment?
#2433 works around by testing with beta-2. Not ideal, but cibuildwheel is on beta 2 and downgrading setup-python to this seemed more reasonable then trying to build with beta 4.
NumPy also still builds wheels with beta 2, but that doesn't matter, this isn't a NumPy issue, it's a Python change that all Cython modules get affected by: If NumPy works, cuda.bindings will just crash next.
When the RC comes out this will all get resolved, until then the only thing I could think of is asking cibuildwheel to do a release that uses b4 so both parts are on b4.
As mentioned just to note: When cibuildwheel is updated next time, we'll have to revert gh-2433 and after that 3.15 should be stable and settled (because it'll be RC phase probably, so no more weird breaking 🤞).
Activity
rwgk commentedon Jun 9, 2026
Issue 2171 report: Python 3.15t segfault reproduced locally
Human-targeted summary
I was able to reproduce the issue 2171 segfault locally by using the exact GitHub Actions Python distribution from
actions/python-versions, rather than a locally built CPython 3.15t.The failure does not currently look like a
cuda_pathfinderimplementation bug. The reduced reproducer is:python -X faulthandler -c 'from numpy import random'That segfaults with:
Python 3.15.0b2 free-threading build (main, Jun 3 2026, 14:43:48) [GCC 11.4.0]numpy-2.4.6-cp315-cp315t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whlThe
cuda_pathfindertest crash is an indirect trigger:pyteststarts.pytest-randomlyplugin is auto-loaded.pytest-randomlyimportsfrom numpy import random.numpy.randomsegfaults before pytest prints its session header.As a practical workaround, disabling the
pytest-randomlyplugin avoids the crash:With that workaround, the full local
cuda_pathfindertest suite passed under the same reproduced environment:This suggests issue 2171 should probably be tracked as an incompatibility between the GitHub Actions Python 3.15t beta build and the custom NumPy 2.4.6 cp315t wheel, exposed by
pytest-randomly, rather than as a CUDA pathfinder library discovery failure.Agent-facing full details
Original failing CI job
The original CI failure was in the PR 2108 GitHub Actions job:
The manually downloaded CI job log is available locally at:
The key CI failure was:
The CI environment installed only
cuda_pathfinder's basictestdependency group before the crash, nottest-cu13. It also installed a custom NumPy prerelease/free-threaded wheel:Local reproduction setup
At first, local tests passed with a locally built CPython 3.15t:
That local build did not reproduce the segfault, even after matching:
testdependency grouppytestcommand lineLD_LIBRARY_PATHpointing to the Pythonlibdirectorylocal_cuda.sh offThe decisive difference was the Python distribution itself.
Installing the exact GitHub Actions Python
The exact GitHub Actions Python asset was downloaded from:
The successful install log is:
Successful install summary:
Installed local toolcache path:
The local scripts were then adjusted to use that Python:
The reproduced build log is:
Important build details:
Installed packages in the reproduced environment:
Local segfault reproduction
The reproduced failing test log is:
The failure is very early:
There is no pytest session header. This means the crash happens during Python / pytest / plugin startup, before pytest begins normal collection output.
Reduced reproducer
The first minimal reduction showed:
pytest-randomlyimports NumPy random at module import time:Relevant code:
Further reduction confirms
pytest-randomlyis not necessary for the crash:These all segfaulted in the reproduced environment.
Faulthandler evidence
Representative command:
python -X faulthandler -c 'import pytest_randomly'Representative Python stack:
Representative native stack components:
Loaded extension modules at crash time:
Workaround verification
Disabling the
pytest-randomlyplugin avoids importingnumpy.randomduring pytest startup:This passed locally in the reproduced environment:
The skipped tests were expected in this local environment:
Current interpretation
The most likely causal chain is:
The
cuda_pathfindertest suite is not required to reproduce the crash. It only encounters the issue because itstestdependency group includespytest-randomly, and pytest auto-loads installed plugins by default.The reason local testing originally passed is that the locally built CPython 3.15t was not identical to the GitHub Actions Python distribution:
Suggested next steps
For unblocking cuda-python CI, the narrow workaround is to disable
pytest-randomlyfor Python 3.15t jobs, for example by passing:or by setting:
and explicitly loading only required plugins. The
-p no:randomlyworkaround is smaller and was verified locally.For root cause, report the minimal reproducer to the owner of the custom NumPy cp315t wheel / NumPy prerelease build process:
python -X faulthandler -c 'from numpy import random'with these details:
It may also be useful to compare against:
actions/python-versions3.15t build, if availablerwgk commentedon Jun 9, 2026
Hi @seberg , I assigned this to you because it seems to be a pure Python vs NumPy compatibility issue.
I put everything you need to pick up from where I left off here:
/home/scratch.rgrossekunst_sw/random_stuff/cuda-python_issue2171_2026-06-09+1000/README.mdPlease let me know any questions about the files there.
@leofang What priority would you give to this issue? It seems likely that others will run into the same issue, and it'll get resolved even if we just wait for new Python 3.15.0 releases.
4 remaining items
rwgk commentedon Jun 12, 2026
Sounds good to me in general, I just looked, there is a 26.04 already, although very recent. Modernizing to 24.04 seems like a good conservative move if we're having issues with 22.04. I'd be surprised though if that didn't tickle some other things that need tweaks and workarounds, but at least worth a try?
seberg commentedon Jun 15, 2026
In case anyone here was curious: This was actually an UB (
memcpywith null pointer) bug in Python that has been fixed. It just seems it showed up randomly across various builds.mdboom commentedon Jul 20, 2026
It seems that this (or something very similar) is back? https://github.com/NVIDIA/cuda-python/actions/runs/29724266375/job/88295548096?pr=2390
[-]Python 3.15t pathfinder test collection segfaults[/-][+]Python 3.15t segfault when importing the numpy.random[/+][-]Python 3.15t segfault when importing the numpy.random[/-][+]Python 3.15t segfault when importing numpy.random[/+]rwgk commentedon Jul 21, 2026
Yesterday I noticed that the Python 3.15 and 3.15t pathfinder tests running under
ci.ymlpassed before PR #2376 when using Python 3.15.0b3, then segfaulted (test-linux-64 only) 12/12 times across the PR and post-merge main runs under 3.15.0b4.In the meantime @mdboom determined (PR #2392) that importing
numpy.randomtriggers the segfault again.leofang commentedon Jul 21, 2026
FYI, if #2401 can fix it, we should not try to fix it ourselves
seberg commentedon Jul 22, 2026
Yeah, probably best to try gh-2401 first (it's needed anyway), sorry I haven't looked at earlier. Both NumPy and Python fixed the previous issue, so this must be new.
I am wondering again if there is a chance of an ABI break between beta 2 (build) and beta 4 (runtime) but I can't see direct evidence (even if it seems what change); if it is ABI 2401 may not help and the build job Python versions may be the next to try bumping.
seberg commentedon Jul 28, 2026
OK, I dug into it with the help of an agent and finally found that there was an ABI break in
b4. ThePyThreadStatestruct got a new field before thecurrent_exceptionand Cython likes to optimize things likePyErr_Occurred()(which apparently get's called at import time or so).I'll try to just pin to b2 for the test-time (matching cibuildwheel), but it's annoying of course, latest at the time of
rc1cuibuildwheel will soon after bump to that and we'll have to remove it again (no need for an exact pin at that point).lijinf2 commentedon Jul 28, 2026
Thanks for investigating this! The segfault is blocking our CI. So numpy wheel for
b4is not available at the moment?seberg commentedon Jul 28, 2026
#2433 works around by testing with beta-2. Not ideal, but cibuildwheel is on beta 2 and downgrading
setup-pythonto this seemed more reasonable then trying to build with beta 4.NumPy also still builds wheels with beta 2, but that doesn't matter, this isn't a NumPy issue, it's a Python change that all Cython modules get affected by: If NumPy works,
cuda.bindingswill just crash next.When the RC comes out this will all get resolved, until then the only thing I could think of is asking
cibuildwheelto do a release that usesb4so both parts are on b4.seberg commentedon Jul 28, 2026
As mentioned just to note: When cibuildwheel is updated next time, we'll have to revert gh-2433 and after that 3.15 should be stable and settled (because it'll be RC phase probably, so no more weird breaking 🤞).