Repository navigation
[DO NOT MERGE][ROCm] Use torch.version.hip to detect ROCm when /opt/rocm is absent - #189229
chinmaydk99 wants to merge 31 commits into
Conversation
Install the full multi-arch TheRock ROCm wheel set for rocm-nightly so the image is no longer tied to a single GPU family index.
Set the rocm-nightly Docker PYTORCH_ROCM_ARCH list to match TheRock multi-arch device support so the image is built against the same targets installed by device-all.
Restore the rocm-nightly Docker build to gfx942 only after the expanded TheRock multi-arch PYTORCH_ROCM_ARCH list caused the source build to exceed the job timeout.
Remove stale /opt/rocm image defaults and redundant TheRock wheel env exports so rocm-nightly discovers ROCm through the generated wheel environment.
Temporarily pin the TheRock ROCm nightly wheel install to the June 12 multi-arch index while keeping gfx942 and gfx950 builds enabled.
Source the ROCm environment and pass CMAKE_PREFIX_PATH so rocm-origami can find HIP when building in the nightly Docker image.
Use the rocm-preview CI tag and Docker image name while keeping the underlying ROCm nightly wheel installation behavior unchanged.
Route the rocm-preview Docker image through ROCM_VERSION=preview so TheRock wheel handling no longer depends on the nightly version tag.
Allow the rocm-preview workflow to be triggered by the existing ciflow/rocm-nightly label until the new preview label config is available on main.
Introduces skipIfRocmVersionAtLeast([7, 14]) and its multiprocess counterpart skip_if_rocm_ver_atleast_multiprocess([7, 14]), then applies them to the tests that fail on ROCm 7.14 but pass on 7.2.x. These skips are dormant on the current 7.2 CI and activate automatically when the rocm-preview lane switches to the TheRock 7.14 wheel, keeping the suite green across the transition. Both decorators mirror the existing lessthan siblings; the common_utils one is built on lazy_skip_if so it is safe on both test methods and whole test classes. Parametrized subcases that a decorator cannot target (CTCLoss in test_modules, log10 in the inductor opinfo properties suite) use inline version-gated skipTest guards instead. Skip set matches TheRock validation branch users/chinmaydk99/add-pt213-rocm-skip-list-june11-pt-validation, which produced an all-green full-suite run on torch 2.13.0a0+rocm7.14.0a20260612.
Skip the ROCm 7.14 preview failures that reproduce in the container environment, including the original focused skips plus the additional default and inductor shard failures identified during validation. The skips remain version-gated so current ROCm 7.2 CI is unaffected.
Keep the TheRock preview workflow aligned with the rocm-preview naming and trigger tags while omitting the legacy use-arc input that no longer exists on this rebased base.
…m_deps`)
Add `_preload_rocm_deps()` in torch/__init__.py, the ROCm analogue of
`_preload_cuda_deps`. At import time (before `import torch._C`), it locates the
`rocm` pip package's `_rocm_sdk_core` via importlib.util.find_spec and
RTLD_GLOBAL-preloads the vendored sysdeps (librocm_sysdeps_*) and the core ROCm
runtime libs from `_rocm_sdk_core/lib{,/rocm_sysdeps/lib}`, wired into
`_load_global_deps()`.
Because it lives in torch source it travels with any build, so a bare
`setup.py` / `python -m build` in a TheRock env yields an importable,
self-contained wheel without relying on LD_LIBRARY_PATH. Guarded to no-op on
non-Linux, on non-ROCm builds (torch.version.hip is None -> CUDA/CPU), and on
OS-managed ROCm where `_rocm_sdk_core` is absent (apt/opt-rocm path).
Made with Cursor
On TheRock ROCm wheels, `import torch` aborts with
`KeyError: 'libamd_smi.so'`: the amdsmi python package installs the native
library as a versioned soname under `_rocm_sdk_core/lib` (e.g.
`libamd_smi.so.26`), which amdsmi's own `find_smi_library()` fails to locate
when `$ROCM_HOME`/`$ROCM_PATH` and the loader path are unset. Its wrapper then
does `_libraries['libamd_smi.so']`, raising `KeyError`, which escapes the
existing guard (only `ModuleNotFoundError` was tolerated) and kills
`import torch`.
Two-part torch-side hardening (mirrors the `_preload_rocm_deps()` philosophy):
1. Make `_amdsmi_cdll_hook` TheRock-aware: locate `_rocm_sdk_core` via
`importlib.util.find_spec` and add its `lib/libamd_smi.so*` (glob, incl.
versioned sonames) as last-resort candidate paths; match names whose
basename starts with `libamd_smi.so` so amdsmi's bare
`CDLL("libamd_smi.so")` is redirected to the real versioned file. Existing
`ROCM_HOME`/`ROCM_PATH` behavior is preserved; guarded to Linux.
2. Make a non-discoverable amdsmi non-fatal: a half-installed amdsmi (python
package present, `.so` undiscoverable) now degrades to `_HAS_AMDSMI=False`
instead of aborting `import torch`, matching the existing missing-module
path.
Downstream follow-up to `_preload_rocm_deps()` (pytorch#188454) for the TheRock
wheels world.
Made with Cursor
test_selections.py detected ROCm only via os.path.exists("/opt/rocm"), which is
false on the TheRock preview-wheel lane (ROCm ships inside the wheel under
_rocm_sdk_devel, not /opt/rocm). That skipped the rocminfo-based
`NUM_PROCS = min(gpu_count, 8)` clamp, so NUM_PROCS stayed at 3 on a 1-GPU
runner. run_test.py's maybe_set_hip_visible_devies() then round-robins
HIP_VISIBLE_DEVICES = _identity % NUM_PROCS across devices {0,1,2}; workers
assigned to the nonexistent indices 1 and 2 see torch.cuda.device_count()==0,
which turns every arch-gated test (skipIfRocmArch -> getRocmArchName ->
_cuda_init) into a "No CUDA GPUs are available" error during collection.
Detect ROCm via torch.version.hip as well so wheel-based lanes reach the clamp.
torch is already imported transitively here; make it explicit and null-guarded.
Verified on an 8x MI300X box against the 7.14 preview wheel: NUM_PROCS now
resolves to the real GPU count (8 unmasked, 1 when masked to a single GPU via
ROCR_VISIBLE_DEVICES), so all pool workers map to device 0 and device_count()
stays nonzero.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189229
Note: Links to docs will display an error until the docs builds have been completed. ❌ 21 New Failures, 5 Unrelated Failures, 6 Unclassified FailuresAs of commit cf3ca78 with merge base 84cc688 ( 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:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
Address the remaining red default shards on the ROCm 7.14 preview lane: - test_nn.py: restore the leading '#' on the Owner(s) line and the missing comma after TEST_MULTIACCELERATOR in the common_utils import; a prior skip edit clobbered both, making the whole module a SyntaxError (CI only surfaced the line-1 error). - test_ops.py: version-gate test_dtypes for sparse.sampled_addmm on ROCm >= 7.14, where bf16/f16 backward now works but the OpInfo dtype metadata is stale. - test_ck_backend.py: skip in setUp when ck4inductor's CMake-generated ck/config.h is absent (TheRock preview wheels ship incomplete CK headers, so every CK kernel compile fails). Keyed on the missing file, not a version, so it auto-clears once the wheel packaging is fixed. - Apply PYFMT (import/call reflow) to the files touched by the earlier skip commits so the lint job is clean.
5a0466a to
7e519d3
Compare
install_rocSHMEM.sh was the only unguarded component in the ubuntu-rocm Dockerfile install block — magma, miopen, and drm all gate on ROCM_VERSION != "preview", but rocSHMEM ran unconditionally. On the preview lane, install_rocm.sh installs ROCm from a TheRock nightly tarball that already ships a matched librocshmem. The unconditional source-build then overwrites it with an April-vintage rocSHMEM (hardcoded commit cb8a2d6) built against a different ROCm ABI. torch links libtorch_rocshmem.so at import time; its HSA topology probe fails against the mismatched base, device_count() returns 0, and the rocm_preflight.py check fails — deterministically on every distributed shard pod. Guard line 61 to match its siblings.
ebe1797 to
c9cb6cc
Compare
|
|
…ostics USE_NVSHMEM=0 on the rocm-preview lane drops the torch_rocshmem linkage whose init can fail HIP fat-binary registration before device enumeration on distributed shards. Adds container-side GPU-visibility diagnostics to rocm_preflight.py to disambiguate a KFD/topology-passthrough gap from a torch/HIP-layer device_count()==0.
da1d638 to
b3daa6d
Compare
_scaled_grouped_mm requires USE_MSLK, which is not built on the ROCm 7.14 preview stack (GroupedBlas.cpp raises NotImplementedError). The existing guard only checks PLATFORM_SUPPORTS_FP8, which is true on this lane, so the test runs and fails deterministically. Gate it with skipIfRocmVersionAtLeast to match the rest of the 7.14 skip stack.
The distributed device_count()==0 failure on the gfx942.4 (sh6px) pool is a torch/HIP-layer problem (rocminfo sees 4 agents, torch sees 0), not a KFD mount gap. To pin the cause, _diag() now also reports the LOADED kernel driver (uname -r, /sys/module/amdgpu/version, kfd interface/topology version) rather than image-baked dpkg metadata (identical on every pod), a torch-free raw hipGetDeviceCount, and an AMD_LOG_LEVEL=3 CLR init tail that names the HIP rejection reason. Diagnostics-only; no change to the preflight gate.
The prior diag used a bare `libamdhip64.so` soname, which is not on the loader path in the wheel container (torch resolves it via its own RPATH), so the raw hipGetDeviceCount probe and the CLR-log capture both failed to load the lib and never produced a reason for device_count()==0. Resolve the actually-loaded libamdhip64 from /proc/self/maps after import torch, call hipGetDeviceCount raw against that path, and capture the AMD_LOG_LEVEL=4 CLR init log from a torch-importing subprocess (widened keyword net for KFD / ioctl / queue / version / topology reject reasons). Diagnostics-only.
Add 3 distributed shards on gfx950.2 alongside the existing gfx942 matrix so one ciflow/rocm-nightly run tests whether the distributed device_count()==0 preflight failure reproduces on MI350. Same wheel (already built for gfx942;gfx950), image, and preflight diagnostics. gfx950 runners are reached via the amd-do runner-determinator experiment (check_experiments: amd-do + amd-do-label-type prefix), matching the proven pattern in periodic-rocm-mi350.yml and trunk.yml. Existing gfx942 shards are unprefixed and unchanged. Scoped to distributed only (not a full mirror) to stay under pytorch's max-queued-jobs cap.
a06bfb9 to
82735b3
Compare
Both gfx942 and gfx950 distributed pods fail identically: raw hipGetDeviceCount counts the GPUs (4 and 2) but torch.cuda.device_count() returns 0 -- across two KMDs (6.12.12 and 6.16.13), falsifying KMD/UMD skew. The fat-binary flood is benign (a GREEN single-GPU shard shows 7502 of them and runs test_cuda fine), so the fault is in torch's device init on the multi-GPU pods, above HIP. Diagnostics to localize the torch-side layer (all zero-cost, no GPU needed): - ungated torch._C._cuda_getArchFlags() (get_arch_list() returns [] when is_available() is False -- i.e. exactly in this failure) - rocminfo agent ISA names vs offload arches grepped from libtorch_hip.so - split counting paths: _C._cuda_getDeviceCount() vs _device_count_amdsmi() / _raw_device_count_amdsmi(); direct amdsmi handle probe; torch.cuda._lazy_init() re-raise (the C++ path swallows the real error into a 0 return) - wheel provenance (torch.__file__, rocm-sdk-core version), hostname (pool is heterogeneous across OS/driver/GPU-count) - CLR child: cwd=/tmp (avoid torch-source shadowing), comgr verbose logs, and the context window BEFORE the first fat-binary failure (the flood drowns the narration that names the reason)
82735b3 to
92e6ae2
Compare
torch.cuda.device_count() consults the smi path (amdsmi on ROCm) and only fell back to the HIP/CUDA runtime count when smi returned < 0. On some ROCm containers amdsmi initializes successfully but enumerates 0 processors -- e.g. pods that mount only /dev/dri/renderD* nodes (enough for HIP compute via /dev/kfd) but not the DRM card* nodes amdsmi discovers through. There _device_count_amdsmi() returns a legitimate 0, `0 < 0` is False, and torch trusts the spurious 0 over the HIP runtime, so device_count() returns 0 while torch._C._cuda_getDeviceCount() correctly reports N. Verified on rocm-preview distributed shards (both gfx942 and gfx950): raw hipGetDeviceCount and _C._cuda_getDeviceCount return N (4/2) while _device_count_amdsmi() and a direct amdsmi_get_processor_handles() both return 0, and device_count() returns 0 -- failing the distributed preflight. Change the guard to `<= 0` so a spurious smi 0 falls back to the runtime count. No regression: on a genuinely 0-GPU host _cuda_getDeviceCount() also returns 0. Symmetric for CUDA/nvml.
…lain amdsmi=0 amdsmi/rsmi returns 0 GPUs while HIP counts N. Per amdsmi source, the count comes from rsmi_num_monitor_devices -> DiscoverAmdgpuDevices(), which walks /sys/class/kfd/kfd/topology/nodes/ and counts a node as a GPU iff gpu_id != 0 AND drm_render_minor is present. HIP walks the same topology but is more tolerant. To find the node HIP-accepts / rsmi-rejects divergence in one run: - dump every KFD topology node: gpu_id, drm_render_minor, simd_count, gfx_target_version, and the exact rsmi_would_count predicate - list /sys/class/drm entries (card vs render sysfs completeness) - cross-check with `amd-smi list` and `rocm-smi --showid` (does the SMI stack itself see the GPUs from inside the container) - print rsmi-relevant env knobs Diagnostics-only. Pairs with the device_count() <=0 fallback fix to first make torch resilient, then name whether the amdsmi=0 root cause is a KFD topology gap in the container or an rsmi node-filter bug.
8b6db13 to
45086a1
Compare
The USE_NVSHMEM=0 hack was based on a hypothesis (torch_rocshmem HIP fat-binary registration failing before GPU enumeration) that was since REFUTED. The real distributed-preflight device_count()==0 cause is amdsmi's socket layer returning a successful 0 when a HIP context is active, and it is handled by the device_count() `<= 0` fallback (commit 1574ec0). Remove the build-time rocSHMEM linkage drop so the preview build is unmodified.
|
Closing this since I have the updated version with newer wheels: #190399 |
Squashed replay of pytorch#188429 (experiment/rocm-preview-wheels-rerun-20260629) onto current main: switch the rocm-preview lane from tarballs to the multi-arch TheRock wheel set, rename rocm-nightly -> rocm-preview, and pin the TheRock nightly ROCm install. Pin bumped from the June-12 (7.14.0a20260612) build used on pytorch#189229 to 7.15.0a20260712 — the wheel consumed by TheRock validation run 29612396655 (torch 2.14.0a0+rocm7.15.0a20260712) on users/chinmaydk99/pytorch-2.14-stabilize.
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 @azahed98