Skip to content

[CD][ROCm] Ship bare .so alias to fix intermittent import torch deadlock - #189114

Closed
atalman wants to merge 1 commit into
pytorch:mainfrom
atalman:fix-rocm-rocprofiler-kfd-deadlock
Closed

atalman wants to merge 1 commit into
pytorch:mainfrom
atalman:fix-rocm-rocprofiler-kfd-deadlock

Conversation

@atalman

@atalman atalman commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

import torch from ROCm 2.13 wheels intermittently hangs forever on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where amdgpu/amdkfd isn't loaded). Fixes #189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

Root cause (native backtrace)

import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS

Why it regressed here (and why 0513 was fine but 0514 hangs)

This is a packaging regression from the ROCm manywheel pipeline port (#182696), not the rocSHMEM binary:

bundled libnuma dlopen("libnuma.so") from $ORIGIN result
old build_rocm.sh (0513) libnuma.so (bare) resolves ✅ no exit() → never hangs
new repair_wheel.py (0514+) libnuma.so.1 only fails (no bare name in-wheel) ❌ exit(1) → rocprofiler atexit deadlock → intermittent hang

The old build_rocm.sh renamed bundled OS deps to bare sonames, so torch/lib shipped libnuma.so. repair_wheel.py keeps them versioned (libnuma.so.1). rocSHMEM's NUMAWrapper global ctor does dlopen("libnuma.so") (bare) via libtorch_rocshmem.so's $ORIGIN RPATH — with only libnuma.so.1 present it fails and exit(1)s at load, tripping a racy rocprofiler-sdk atexit finalize() deadlock (hence the intermittency; the agent.cpp:608 kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled libnuma filename differs.

Fix

When bundling a versioned OS dep, also create a bare-name symlink (libnuma.so → libnuma.so.1, etc.), restoring build_rocm.sh behavior. The bare symlink satisfies rocSHMEM's dlopen; the versioned file still satisfies NEEDED references.

Verified: adding this symlink to an installed wheel makes import torch succeed deterministically on a no-kfd host (loop-tested; the hang no longer reproduces).

Follow-ups (upstream)

The underlying rocSHMEM bug — NUMAWrapper must not exit() from a global constructor, and should dlopen("libnuma.so.1") — is already fixed upstream after PyTorch's pinned commit (cb8a2d6): ROCm/rocm-systems #5918 (runtime numalib check) and #6640 (link numa directly, no dlopen — removes numa_wrapper.cpp). Bumping ROCSHMEM_VERSION in .ci/docker/common/install_rocSHMEM.sh would also fix it and is worth doing separately. The rocprofiler-sdk atexit finalize() deadlock ("does not exit cleanly") is a separate AMD-side bug.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot

pytorch-bot Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189114

Note: Links to docs will display an error until the docs builds have been completed.

❌ 4 Unclassified Failures

As of commit c625920 with merge base 9f9df93 (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

  • linux-binary-manywheel / manywheel-py3_15-rocm7_1-build / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a post-build wheel repair script that adds symlinks), while the failure is a compile-time Cython version detection error ("Cython requires Python 3.8+") that occurs during the build phase before repair_wheel.py would ever execute.

    Full reasoning on HUD →

  • linux-binary-manywheel / manywheel-py3_15-rocm7_2-build / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.

    AI verdict: AI verdict: not related

    The failure is a Docker image environment issue where pkg-config finds system Python 3.6 instead of the target Python 3.15, causing Cython's sanity check to fail. The suspect commit only adds .so symlinks in repair_wheel.py and has no connection to Python version detection, NumPy/Cython installation, or Docker image configuration.

    Full reasoning on HUD →

  • linux-binary-manywheel / manywheel-py3_15t-rocm7_1-build / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.

    AI verdict: AI verdict: not related

    The Cython/Python 3.15 build failure pre-dates the suspect commit. The same job was already failing on commits from July 6 (before the suspect merged July 7), and the suspect only adds a symlink in repair_wheel.py (a post-build step), which cannot cause a Cython compilation error during the build phase.

    Full reasoning on HUD →

  • linux-binary-manywheel / manywheel-py3_15t-rocm7_2-build / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.

    AI verdict: AI verdict: not related

    The commit only modifies repair_wheel.py (post-build symlink creation), but the failure occurs during the build phase when installing numpy - Cython's sanity check picks up system Python 3.6 headers instead of the target Python 3.15t. This is a Docker image environment issue unrelated to the code change.

    Full reasoning on HUD →

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Jul 7, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@atalman
atalman marked this pull request as ready for review July 7, 2026 01:53
@atalman
atalman requested a review from a team as a code owner July 7, 2026 01:53

@huydhn huydhn left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Is this a hot fix until the issue is addressed properly?

@atalman
atalman force-pushed the fix-rocm-rocprofiler-kfd-deadlock branch from 62cd6a3 to 5e0422f Compare July 7, 2026 02:02
@atalman atalman changed the title [CD][ROCm] Do not bare-alias rocprofiler sonames (fixes no-GPU import deadlock) [CD][ROCm] Rewrite bundled-lib NEEDED entries in a final pass (fixes no-GPU import deadlock) Jul 7, 2026
@atalman atalman added the ciflow/binaries Trigger all binary build and upload jobs on the PR label Jul 7, 2026
@atalman
atalman marked this pull request as draft July 7, 2026 05:24
…ch` deadlock (pytorch#189110)

`import torch` from ROCm 2.13 wheels intermittently hangs forever on hosts
without a usable GPU / kfd (CPU-only nodes, or GPU nodes without amdgpu/amdkfd
loaded). Root cause chain (native backtrace):

  import torch -> dlopen(_C) -> static init of libtorch_rocshmem.so
    -> rocshmem::NUMAWrapper::NUMAWrapper()   (upstream rocSHMEM global ctor)
       -> dlopen("libnuma.so")  == NULL       -> exit(1)
          -> atexit -> rocprofiler::registration::finalize()
             -> ThreadPool::destroy_threadpool() -> std::thread::join()   # HANGS

Why it regressed at pytorch#182696: the old build_rocm.sh renamed bundled OS deps to
bare sonames, so torch/lib shipped `libnuma.so`. The new repair_wheel.py keeps
them versioned (`libnuma.so.1`) only. rocSHMEM's NUMAWrapper ctor does
`dlopen("libnuma.so")` (bare) via libtorch_rocshmem.so's $ORIGIN RPATH; with
only `libnuma.so.1` present that dlopen fails and NUMAWrapper calls exit() at
library-load time, which trips a racy rocprofiler-sdk atexit finalize deadlock
(hence the intermittency). The good (0513) wheel shipped bare `libnuma.so` and
never hangs; the bad (0514+) wheel ships only `libnuma.so.1` and does.

Fix: when bundling a versioned OS dep, also create a bare-name symlink
(libnuma.so -> libnuma.so.1, etc.), restoring build_rocm.sh behavior. The bare
symlink satisfies rocSHMEM's dlopen while the versioned file still satisfies
NEEDED references. Verified: adding this symlink to an installed wheel makes
`import torch` succeed deterministically on a no-kfd host.

The underlying rocSHMEM bug (NUMAWrapper must not exit() from a global ctor;
should dlopen "libnuma.so.1") is fixed upstream after our pinned commit
(ROCm/rocm-systems pytorch#5918, pytorch#6640) and should be picked up via a pin bump too.
@atalman
atalman force-pushed the fix-rocm-rocprofiler-kfd-deadlock branch from 5e0422f to c625920 Compare July 7, 2026 12:48
@atalman atalman changed the title [CD][ROCm] Rewrite bundled-lib NEEDED entries in a final pass (fixes no-GPU import deadlock) [CD][ROCm] Ship bare libnuma.so alias to fix intermittent import torch deadlock Jul 7, 2026
@atalman
atalman marked this pull request as ready for review July 7, 2026 12:57
@malfet
malfet requested a review from jeffdaily July 7, 2026 14:01

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@atalman atalman changed the title [CD][ROCm] Ship bare libnuma.so alias to fix intermittent import torch deadlock [CD][ROCm] Ship bare .so alias to fix intermittent import torch deadlock Jul 7, 2026
@atalman

atalman commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge -f "lint and rest of the jobs look ok"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
pytorchmergebot pushed a commit to atalman/pytorch that referenced this pull request Sep 14, 2026
ROCm 7.14 wheels print this to stderr on every `import torch`:

```
E-001h rocSHMEM Could not open libnuma. Returning	NUMAWrapper@src/gda/numa_wrapper.cpp:48
```

The machinery to prevent it already exists. `repair_wheel.py`'s
`rocm_os_deps()` lists `/usr/lib64/libnuma.so.1`, `rocm_bundle()` copies it
into `torch/lib`, and pytorch#189114 adds a bare `libnuma.so` symlink beside it so
rocSHMEM's `dlopen("libnuma.so")` resolves via `$ORIGIN` on its RPATH.
Verified on the shipped artifact:

    $ readelf -d torch/lib/libtorch_rocshmem.so
    RPATH: $ORIGIN/../../_rocm_sdk_core/lib:...:$ORIGIN

What was missing is the library itself on the build machine. `install_rocm.sh`
installs `libnuma-dev` in `install_ubuntu()` -- with a comment naming rocSHMEM
as the reason -- but `install_almalinux()`, which the manywheel builder uses,
installs nothing. So `rocm_os_deps()` returns a path that does not exist, and
the loop skips absent deps, so the wheel ships without libnuma and without the
symlink.

That also explains why CI never saw this: the Ubuntu test image has libnuma,
the AlmaLinux wheel builder does not. Only users of the wheels are affected.

Install `numactl-libs` (provides `/usr/lib64/libnuma.so.1`) in the AlmaLinux
branch, matching what the Ubuntu branch already does.

Also warn when an OS dep is absent rather than skipping in silence. A missing
entry here yields a wheel that imports fine and misbehaves later; this one
reached both nightlies and the 2.14 release candidate unnoticed. Left as a
warning rather than a hard failure, since some deps in that list are
legitimately absent on some builders.

Not just cosmetic: pytorch#189110 reports the same failed dlopen making rocSHMEM call
`exit()` at load, tripping a rocprofiler-sdk atexit deadlock that hangs
`import torch` on hosts without a GPU or kfd.

Fixes pytorch#195670

Test Plan:
- Confirmed the wheel currently ships no libnuma at all. Read the central
  directory of `torch-2.14.0+rocm7.14-cp312-cp312-manylinux_2_28_x86_64.whl`
  (1.39GB, 13,287 entries) over HTTP range requests: the only `numa` matches
  are `torch/include/c10/util/numa.h` and the unrelated `torch/numa/` Python
  package. No `torch/lib/libnuma.so` and no `torch/lib/libnuma.so.1`.
- Extracted `torch/lib/libtorch_rocshmem.so` from that wheel and confirmed via
  `readelf -d` that `$ORIGIN` is on its RPATH, so a bundled `torch/lib/libnuma.so`
  is found, and that libnuma is absent from its NEEDED entries -- it is reached
  only through `dlopen`, which is why the SONAME rewrite never covered it.
- `bash -n .ci/docker/common/install_rocm.sh` passes; `repair_wheel.py` parses.
- Occurrence counts in the affected jobs: 5 in the nightly
  `manywheel-py3_15t-rocm7_14-test`, 7 in test-infra's release/2.14
  `manywheel-py3_12-rocm7_14`, 0 in ROCm 10.0 and 0 in the Ubuntu ROCm CI job.

The real check is the next ROCm 7.14 nightly: `torch/lib/libnuma.so` and
`torch/lib/libnuma.so.1` present in the wheel, and no rocSHMEM line in the
binary smoke test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries Trigger all binary build and upload jobs on the PR Merged module: rocm AMD GPU support for Pytorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ROCm] release/2.13: import torch deadlocks at load on hosts without /dev/kfd (librocprofiler-sdk topology thread never returns; regression vs 2.12)

4 participants