Skip to content

[ROCm] Rewrite bundled-lib NEEDED entries after all libs are copied in - #189906

Closed
jeffdaily wants to merge 1 commit into
mainfrom
jeffdaily/repair-wheel-rocm-needed-rewrite
Closed

jeffdaily wants to merge 1 commit into
mainfrom
jeffdaily/repair-wheel-rocm-needed-rewrite

Conversation

@jeffdaily

@jeffdaily jeffdaily commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

The ROCm manywheel repair step renames bundled ROCm libs to bare .so filenames and rewrites NEEDED references to match. #182696 ported this from build_common.sh to repair_wheel.py and collapsed the shell script's two phases (copy every DEPS_LIST lib into torch/lib, then run replace_needed_sofiles for every soname) into a single per-lib loop that copies a lib and immediately rewrites references to it. replace_needed only visits files present in the wheel at call time, so references from a bundled lib to any lib listed earlier in ROCM_SO_FILES are never rewritten: the dependent has not been copied in yet when its dependency's rewrite pass runs. The 2.13.0+rocm7.2 wheel ships 27 such dangling NEEDED entries (libhiprtc.so -> libamd_comgr.so.3, librocblas.so -> libamdhip64.so.7, libmagma.so -> libhipblas.so.3, ...). Most resolve at runtime by luck (the bundled file keeps its versioned SONAME, so a copy already loaded under that SONAME satisfies the ref) or from a system ROCm install via ldconfig, which is why this went unnoticed until the cold dlopen introduced by #183515 hit the libamd_comgr.so.3 ref on a machine with no ROCm (#189194).

The fix restores the two-phase structure: copy all bundled libs (and their bare-name dlopen symlinks from #189110) first, then run the rewrite passes. A new check_no_dangling_bundled_needed pass then fails the build if any lib in torch/lib still references a versioned soname whose stem is bundled but whose exact name is not shipped, so a future ordering or list regression breaks the build instead of shipping a wheel that silently depends on a system ROCm install.

This complements #189900, which makes the inductor VecISA probe recover from such wheels at runtime; this change makes newly built wheels self-contained again.

Validated by running the real repair_wheel() from before and after the change on a minimal fake torch wheel bundling actual ROCm libs in the regression order (libhsa-runtime64 listed before libroctracer64, which NEEDs libhsa-runtime64.so.1): the old code ships the stale versioned ref with no error, the new code rewrites it to libhsa-runtime64.so and the new check passes. Aiming check_no_dangling_bundled_needed at the torch/lib of the actual torch==2.13.0+rocm7.2 wheel fails the build listing all 27 dangling references, including the libamd_comgr.so.3 ones from #189194.

This PR was authored with Claude (AI assistant).

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

@jeffdaily
jeffdaily requested a review from a team as a code owner July 14, 2026 18:17
@pytorch-bot

pytorch-bot Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Unrelated Failure, 6 Unclassified Failures

As of commit 9e642bc with merge base 5a7eae4 (image):

NEW FAILURES - The following jobs have failed:

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-s390x-binary-manywheel / manywheel-py3_10-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp310-cp310/bin/../lib/python3.10/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a ROCm-specific wheel repair script). The failure is a C++ compilation error in complex_utils.h:45 on s390x. There is no causal path from a ROCm wheel repair Python script to an s390x C++ compilation error.

    Full reasoning on HUD →

  • linux-s390x-binary-manywheel / manywheel-py3_11-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp311-cp311/bin/../lib/python3.11/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a ROCm-specific Python script). The failure is a C++ compilation error in torch/headeronly/util/complex_utils.h:45 on s390x, a file introduced by a different earlier commit (34d4a28, PR Use METH_FASTCALL for Inductor C++ Python bindings #192287).

    Full reasoning on HUD →

  • linux-s390x-binary-manywheel / manywheel-py3_12-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp312-cp312/bin/../lib/python3.12/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a ROCm wheel repair script). The failure is a C++ compilation error in torch/headeronly/util/complex_utils.h:45 on s390x, a file introduced by a different commit (34d4a28, PR Use METH_FASTCALL for Inductor C++ Python bindings #192287) two days earlier.

    Full reasoning on HUD →

  • linux-s390x-binary-manywheel / manywheel-py3_13-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp313-cp313/bin/../lib/python3.13/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a ROCm-specific wheel repair script). The failure is a C++ compilation error in complex_utils.h:45 on s390x, a file the suspect never touches. The error is caused by a different commit or a pre-existing s390x compiler incompatibility.

    Full reasoning on HUD →

  • linux-s390x-binary-manywheel / manywheel-py3_14-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp314-cp314/bin/../lib/python3.14/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (ROCm wheel repair logic). The failure is a C++ compilation error in complex_utils.h on s390x architecture, completely unrelated to ROCm wheel packaging.

    Full reasoning on HUD →

  • linux-s390x-binary-manywheel / manywheel-py3_14t-cpu-s390x-test / test (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /opt/python/cp314-cp314t/bin/../lib/python3.14t/site-packages/torch/include/torch/headeronly/util/complex_utils.h:45:21: error: ‘v’ was not declared in this scope

    AI verdict: AI verdict: not related

    The suspect commit only modifies .ci/manywheel/repair_wheel.py (a ROCm wheel repair script). The failure is a C++ compilation error in complex_utils.h:45 ('v' not declared in scope) on s390x, a file the suspect never touches. The file was introduced by an earlier commit (34d4a28, Aug 12).

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 14, 2026

@atalman atalman 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.

lgtm

@atalman atalman added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR labels Jul 14, 2026

@jithunnair-amd jithunnair-amd 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.

ooh, nice find ... subtle bug

@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

The ROCm manywheel repair step renames bundled ROCm libs to bare .so filenames and rewrites NEEDED references to match. #182696 ported this from build_common.sh to repair_wheel.py and collapsed the shell script's two phases (copy every DEPS_LIST lib into torch/lib, then run replace_needed_sofiles for every soname) into a single per-lib loop that copies a lib and immediately rewrites references to it. replace_needed only visits files present in the wheel at call time, so references from a bundled lib to any lib listed earlier in ROCM_SO_FILES are never rewritten: the dependent has not been copied in yet when its dependency's rewrite pass runs. The 2.13.0+rocm7.2 wheel ships 27 such dangling NEEDED entries (libhiprtc.so -> libamd_comgr.so.3, librocblas.so -> libamdhip64.so.7, libmagma.so -> libhipblas.so.3, ...). Most resolve at runtime by luck (the bundled file keeps its versioned SONAME, so a copy already loaded under that SONAME satisfies the ref) or from a system ROCm install via ldconfig, which is why this went unnoticed until the cold dlopen introduced by #183515 hit the libamd_comgr.so.3 ref on a machine with no ROCm (#189194).

The fix restores the two-phase structure: copy all bundled libs (and their bare-name dlopen symlinks from #189110) first, then run the rewrite passes. A new check_no_dangling_bundled_needed pass then fails the build if any lib in torch/lib still references a versioned soname whose stem is bundled but whose exact name is not shipped, so a future ordering or list regression breaks the build instead of shipping a wheel that silently depends on a system ROCm install.

This complements #189900, which makes the inductor VecISA probe recover from such wheels at runtime; this change makes newly built wheels self-contained again.

Test Plan:

Ran the real repair_wheel() from before and after the change on a minimal fake torch wheel bundling this host's actual ROCm libs in the regression order (libhsa-runtime64 listed before libroctracer64, which NEEDs libhsa-runtime64.so.1): the old code ships the stale versioned ref with no error, the new code rewrites it to libhsa-runtime64.so and the new check passes. Aimed check_no_dangling_bundled_needed at the torch/lib of the actual torch==2.13.0+rocm7.2 wheel (installed from download.pytorch.org/whl/test/rocm7.2): it fails the build listing all 27 dangling references, including the libamd_comgr.so.3 ones from #189194.

```
python validate_repair_wheel.py  # A/B harness driving repair_wheel() from both revisions
```

Authored with Claude (AI assistant).
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased jeffdaily/repair-wheel-rocm-needed-rewrite onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout jeffdaily/repair-wheel-rocm-needed-rewrite && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the jeffdaily/repair-wheel-rocm-needed-rewrite branch from fc064a6 to 9e642bc Compare August 13, 2026 19:47
@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 13, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 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.

Details for Dev Infra team Raised by workflow job

@jeffdaily jeffdaily added the release notes: rocm mandatorylabel label Aug 13, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@pytorchbot cherry-pick --onto release/2.14 -c critical

@pytorchbot

Copy link
Copy Markdown
Collaborator

Cherry picking #189906

The cherry pick PR is at #193600 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

atalman pushed a commit that referenced this pull request Aug 17, 2026
#193600)

[ROCm] Rewrite bundled-lib NEEDED entries after all libs are copied in (#189906)

The ROCm manywheel repair step renames bundled ROCm libs to bare `.so` filenames and rewrites NEEDED references to match. #182696 ported this from build_common.sh to repair_wheel.py and collapsed the shell script's two phases (copy every DEPS_LIST lib into torch/lib, then run replace_needed_sofiles for every soname) into a single per-lib loop that copies a lib and immediately rewrites references to it. `replace_needed` only visits files present in the wheel at call time, so references from a bundled lib to any lib listed earlier in ROCM_SO_FILES are never rewritten: the dependent has not been copied in yet when its dependency's rewrite pass runs. The 2.13.0+rocm7.2 wheel ships 27 such dangling NEEDED entries (`libhiprtc.so -> libamd_comgr.so.3`, `librocblas.so -> libamdhip64.so.7`, `libmagma.so -> libhipblas.so.3`, ...). Most resolve at runtime by luck (the bundled file keeps its versioned SONAME, so a copy already loaded under that SONAME satisfies the ref) or from a system ROCm install via ldconfig, which is why this went unnoticed until the cold dlopen introduced by #183515 hit the `libamd_comgr.so.3` ref on a machine with no ROCm (#189194).

The fix restores the two-phase structure: copy all bundled libs (and their bare-name dlopen symlinks from #189110) first, then run the rewrite passes. A new `check_no_dangling_bundled_needed` pass then fails the build if any lib in torch/lib still references a versioned soname whose stem is bundled but whose exact name is not shipped, so a future ordering or list regression breaks the build instead of shipping a wheel that silently depends on a system ROCm install.

This complements #189900, which makes the inductor VecISA probe recover from such wheels at runtime; this change makes newly built wheels self-contained again.

Validated by running the real `repair_wheel()` from before and after the change on a minimal fake torch wheel bundling actual ROCm libs in the regression order (libhsa-runtime64 listed before libroctracer64, which NEEDs libhsa-runtime64.so.1): the old code ships the stale versioned ref with no error, the new code rewrites it to libhsa-runtime64.so and the new check passes. Aiming `check_no_dangling_bundled_needed` at the torch/lib of the actual torch==2.13.0+rocm7.2 wheel fails the build listing all 27 dangling references, including the `libamd_comgr.so.3` ones from #189194.

This PR was authored with Claude (AI assistant).

Pull Request resolved: #189906
Approved by: https://github.com/atalman, https://github.com/jithunnair-amd

(cherry picked from commit 4973620)

Co-authored-by: Jeff Daily <[email protected]>
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
pytorch#189906)

The ROCm manywheel repair step renames bundled ROCm libs to bare `.so` filenames and rewrites NEEDED references to match. pytorch#182696 ported this from build_common.sh to repair_wheel.py and collapsed the shell script's two phases (copy every DEPS_LIST lib into torch/lib, then run replace_needed_sofiles for every soname) into a single per-lib loop that copies a lib and immediately rewrites references to it. `replace_needed` only visits files present in the wheel at call time, so references from a bundled lib to any lib listed earlier in ROCM_SO_FILES are never rewritten: the dependent has not been copied in yet when its dependency's rewrite pass runs. The 2.13.0+rocm7.2 wheel ships 27 such dangling NEEDED entries (`libhiprtc.so -> libamd_comgr.so.3`, `librocblas.so -> libamdhip64.so.7`, `libmagma.so -> libhipblas.so.3`, ...). Most resolve at runtime by luck (the bundled file keeps its versioned SONAME, so a copy already loaded under that SONAME satisfies the ref) or from a system ROCm install via ldconfig, which is why this went unnoticed until the cold dlopen introduced by pytorch#183515 hit the `libamd_comgr.so.3` ref on a machine with no ROCm (pytorch#189194).

The fix restores the two-phase structure: copy all bundled libs (and their bare-name dlopen symlinks from pytorch#189110) first, then run the rewrite passes. A new `check_no_dangling_bundled_needed` pass then fails the build if any lib in torch/lib still references a versioned soname whose stem is bundled but whose exact name is not shipped, so a future ordering or list regression breaks the build instead of shipping a wheel that silently depends on a system ROCm install.

This complements pytorch#189900, which makes the inductor VecISA probe recover from such wheels at runtime; this change makes newly built wheels self-contained again.

Validated by running the real `repair_wheel()` from before and after the change on a minimal fake torch wheel bundling actual ROCm libs in the regression order (libhsa-runtime64 listed before libroctracer64, which NEEDs libhsa-runtime64.so.1): the old code ships the stale versioned ref with no error, the new code rewrites it to libhsa-runtime64.so and the new check passes. Aiming `check_no_dangling_bundled_needed` at the torch/lib of the actual torch==2.13.0+rocm7.2 wheel fails the build listing all 27 dangling references, including the `libamd_comgr.so.3` ones from pytorch#189194.

This PR was authored with Claude (AI assistant).

Pull Request resolved: pytorch#189906
Approved by: https://github.com/atalman, https://github.com/jithunnair-amd
@github-actions
github-actions Bot deleted the jeffdaily/repair-wheel-rocm-needed-rewrite branch November 4, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants