Skip to content

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

Merged
atalman merged 1 commit into
release/2.14from
cherry-pick-189906-by-pytorch_bot_bot_
Aug 17, 2026
Merged

atalman merged 1 commit into
release/2.14from
cherry-pick-189906-by-pytorch_bot_bot_

Conversation

@pytorchbot

@pytorchbot pytorchbot commented Aug 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 @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

#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)
@pytorch-bot

pytorch-bot Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit ba7592f with merge base 73db3ed (image):
💚 Looks good so far! There are no failures yet. 💚

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 Aug 14, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 14, 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 merged commit f746b5f into release/2.14 Aug 17, 2026
158 checks passed
@github-actions
github-actions Bot deleted the cherry-pick-189906-by-pytorch_bot_bot_ branch November 5, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: rocm AMD GPU support for Pytorch open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants