Skip to content

[ROCm] Retry VecISA dlopen probe with import torch on cold load failure - #193601

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

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

Conversation

@pytorchbot

@pytorchbot pytorchbot commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #189194

The ROCm manywheel build bundles the ROCm runtime into torch/lib under unversioned filenames (libamd_comgr.so, libamdhip64.so, ...) and rewrites consumers' DT_NEEDED entries to match, but some entries are missed: in the 2.13.0+rocm7.2 wheel, libhiprtc.so, librocprofiler-sdk.so, and librocroller.so still reference libamd_comgr.so.3, a filename that does not exist in the wheel. After import torch this is harmless: the bundled libamd_comgr.so is already loaded and registered under its unchanged SONAME libamd_comgr.so.3, so those references resolve against the in-process copy. A cold dlopen has no such copy, so on a machine without a system ROCm install the load fails (a ROCm docker image masks the bug because /opt/rocm provides libamd_comgr.so.3 via ldconfig). #183515 changed the VecISA dlopen probe child from import torch + dlopen to a cold dlopen with LD_LIBRARY_PATH=<torch>/lib, so on such a machine every check_build fails and inductor reports "Can't detect vectorized ISA for CPU". Thanks to @karthickai and @atalman for bisecting to #183515 on the issue.

The fix keeps the fast no-import path but retries after import torch if the cold dlopen raises OSError, so whatever loading semantics the wheel relies on are in effect before the second attempt. This also covers the same class of failure for TheRock-based ROCm wheels (ROCm libs preloaded from separate rocm-sdk packages with no rpath) and the latent CUDA case where torch and the nvidia wheels land in different site-packages roots and the $ORIGIN-relative rpaths dangle. The 60s probe timeout from #183515 still bounds the child either way, so the CI hang that change addressed stays fixed. The missed DT_NEEDED rewrites are arguably a wheel packaging bug worth fixing at the source, but the probe fallback repairs wheels already shipped and does not hardcode packaging layout into inductor.

Reproduced and validated with the actual 2.13.0+rocm7.2 test wheel in a venv, using the glibc loader's --inhibit-cache to emulate a machine with no system ROCm: the pre-fix probe script fails with OSError: libamd_comgr.so.3: cannot open shared object file and the fixed script succeeds. The new regression test simulates the layout without needing a ROCm wheel:

python test/inductor/test_codecache.py TestVecISACheckBuild

This PR was authored with Claude (AI assistant).

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben

…re (#189900)

Fixes #189194

The ROCm manywheel build bundles the ROCm runtime into torch/lib under unversioned filenames (libamd_comgr.so, libamdhip64.so, ...) and rewrites consumers' DT_NEEDED entries to match, but some entries are missed: in the 2.13.0+rocm7.2 wheel, libhiprtc.so, librocprofiler-sdk.so, and librocroller.so still reference libamd_comgr.so.3, a filename that does not exist in the wheel. After `import torch` this is harmless: the bundled libamd_comgr.so is already loaded and registered under its unchanged SONAME libamd_comgr.so.3, so those references resolve against the in-process copy. A cold dlopen has no such copy, so on a machine without a system ROCm install the load fails (a ROCm docker image masks the bug because /opt/rocm provides libamd_comgr.so.3 via ldconfig). #183515 changed the VecISA dlopen probe child from `import torch` + dlopen to a cold dlopen with `LD_LIBRARY_PATH=<torch>/lib`, so on such a machine every `check_build` fails and inductor reports "Can't detect vectorized ISA for CPU". Thanks to @karthickai and @atalman for bisecting to #183515 on the issue.

The fix keeps the fast no-import path but retries after `import torch` if the cold dlopen raises OSError, so whatever loading semantics the wheel relies on are in effect before the second attempt. This also covers the same class of failure for TheRock-based ROCm wheels (ROCm libs preloaded from separate rocm-sdk packages with no rpath) and the latent CUDA case where torch and the nvidia wheels land in different site-packages roots and the `$ORIGIN`-relative rpaths dangle. The 60s probe timeout from #183515 still bounds the child either way, so the CI hang that change addressed stays fixed. The missed DT_NEEDED rewrites are arguably a wheel packaging bug worth fixing at the source, but the probe fallback repairs wheels already shipped and does not hardcode packaging layout into inductor.

Reproduced and validated with the actual 2.13.0+rocm7.2 test wheel in a venv, using the glibc loader's `--inhibit-cache` to emulate a machine with no system ROCm: the pre-fix probe script fails with `OSError: libamd_comgr.so.3: cannot open shared object file` and the fixed script succeeds. The new regression test simulates the layout without needing a ROCm wheel:

```
python test/inductor/test_codecache.py TestVecISACheckBuild
```

This PR was authored with Claude (AI assistant).

Pull Request resolved: #189900
Approved by: https://github.com/atalman

(cherry picked from commit 74e49c1)
@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/193601

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

❌ 2 New Failures

As of commit 6dd19bf with merge base 73db3ed (image):

NEW FAILURES - The following jobs have failed:

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

@jansel

jansel commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 9m 19s —— View job


Review: looks correct and appropriately scoped for a 2.14 cherry-pick — one diagnostics gap and two test-robustness nits.

  • Read the diff against origin/release/2.14
  • Review torch/_inductor/cpu_vec_isa.py changes
  • Review the new test in test/inductor/test_codecache.py
  • Verify cherry-pick fidelity vs origin/main
  • Post review
Full review

Cherry-pick fidelity

Both changed files are byte-identical to origin/main:

$ git diff origin/main:torch/_inductor/cpu_vec_isa.py HEAD:torch/_inductor/cpu_vec_isa.py
$ git diff origin/main:test/inductor/test_codecache.py HEAD:test/inductor/test_codecache.py
(no output)

So this is a clean pick with no drift. +66/-1 matches the upstream PR.

The fix itself — torch/_inductor/cpu_vec_isa.py:97-109

The logic is right, and importantly it does not weaken the probe's actual purpose. Per Note [Checking for Vectorized Support in Inductor], the probe exists to catch a libtorch_cpu that was built without the Sleef AVX512 symbols. In that scenario the cold dlopen fails with OSError, and the retry after import torch also fails — importing torch does not conjure missing symbols. So the fallback converts exactly one class of failure (deps that only resolve against an already-loaded in-process copy) into a pass, and leaves genuine ISA failures failing. That is the pre-#183515 semantics, restored only as a second chance.

The non-Linux raise in the handler (line 105-106) is worth keeping rather than falling through: on macOS/Windows import torch already ran at line 99-100, so a retry would be a byte-identical second attempt. Explicitly re-raising avoids a pointless duplicate LoadLibrary and keeps the error surface unchanged on those platforms.

Two consequences worth naming, both of which I think are acceptable but neither is called out in the code:

  1. The 60s budget from [inductor] Harden VecISA dlopen probe (timeout, no import torch) #183515 now covers both attempts, including the slow import torch. The hang that [inductor] Harden VecISA dlopen probe (timeout, no import torch) #183515 fixed was precisely import torch stalling under CI load. On a machine that fails the cold load and has a slow torch import, the probe can now hit the timeout instead of returning a clean False. The outcome is still bounded (_probe_load returns False, and subprocess.run kills the child), so the CI-hang fix holds. But the user-visible symptom degrades from "load failed" to the hung after 60s warning, which points at the wrong root cause. Not a blocker.

  2. Genuine-failure cost doubles. Where the ISA truly doesn't load, every candidate ISA now pays cold-fail + import torch-fail. Bounded by the functools.cache on __bool__impl and the ~4 x86 candidates, and there's no on-disk negative cache (.load_ok is written only on success, cpu_vec_isa.py:221-228), so this repeats once per process. Small, but real on a broken install.

Main suggestion: the failure reason is still thrown away

_probe_load passes stderr=subprocess.DEVNULL (cpu_vec_isa.py:161). That was defensible when there was one failure mode, but now a double failure discards both OSErrors and the user is left with only "Can't detect vectorized ISA for CPU" — the exact unhelpful message from #189194 that cost a bisect to diagnose. Capturing stderr and surfacing it (a warnings.warn, or a debug-level log so the happy path stays quiet) would make the next instance of this self-diagnosing. Python's implicit exception chaining already gives you both errors in the child's traceback, so this is purely about not discarding it.

I'd treat this as a follow-up on main rather than something to add to a release-branch pick — the cherry-pick should stay minimal and identical to what's already validated on main.

Fix this →

Test — test/inductor/test_codecache.py:5275-5325

Good design: it exercises the real _avx_py_load string rather than a reimplementation, and it simulates the ROCm layout with libc10.so so it needs no ROCm wheel. The -Wl,--no-as-needed placement is correct (it precedes -lc10, so it applies to that library), and the comment explaining why it's needed is the kind of non-obvious note worth having. Self-checking the premise at line 5318-5319 — skipping if the loader resolves libc10.so cold — is the right call; without it the test would pass vacuously on hosts where torch's lib dir is in the ldconfig cache.

Two nits:

  • Line 5311, subprocess.run(cmd, check=True) raises on compile/link failure, so an environment problem (compiler present but can't link against libc10.so, e.g. a mismatched libstdc++) surfaces as a test error attributed to this change rather than a skip. Given the test already skips for a missing compiler and a missing libc10.so, catching CalledProcessError and skipping would be consistent with its own posture.
  • Line 5313 strips only LD_LIBRARY_PATH and inherits the rest of os.environ, so the child's import torch depends on ambient PYTHONPATH/site-packages. That's fine in CI and matches how the sibling tests behave, but it does mean the assertion at 5325 can fail for reasons unrelated to loader semantics. The captured stderr in the failure message mitigates this, which is why I'd leave it alone.

Neither warrants changing on a release-branch pick.

CI and process

  • The 2 red jobs are test_forward_ad_linalg_householder_product_cuda_float32, a CUDA linalg forward-AD numerics test with no code path overlap with a CPU VecISA dlopen probe. Unrelated; Dr. CI's verdict agrees.
  • The bot still wants a label — this is a probe-behavior fix with no API surface, so @pytorchbot label "topic: not user facing" is the right one unless you want it in release notes as a ROCm fix.
  • No non-ASCII introduced in new comments (checked the diff), consistent with the repo's comment style rules.
· [Branch](https://github.com/pytorch/pytorch/tree/cherry-pick-189900-by-pytorch_bot_bot_)

@atalman
atalman merged commit f387a6e into release/2.14 Aug 17, 2026
210 of 212 checks passed
@github-actions
github-actions Bot deleted the cherry-pick-189900-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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants