Skip to content

fix(rocm): key the HIP JIT cache by the gfx target (#4815) - #4826

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4815
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4815

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4815.

TorchOpsJitExtension._cache_fingerprint() -> _cuda_cache_fingerprint_payload()
covered only CUDA inputs: TORCH_CUDA_ARCH_LIST (hipcc ignores it),
torch.cuda.get_device_capability() (coarse on ROCm: gfx1201/gfx1200 both
(12,0), gfx90a/gfx908 both (9,0)), and resolved_cuda_arch_flags() (empty on
ROCm). PYTORCH_ROCM_ARCH and the device gcnArchName — the values that pick
hipcc's code objects — were missing, so a HIP binary built for one gfx target was
reused on another and every launch failed with invalid device function.

Change

_cuda_cache_fingerprint_payload() branches on torch.version.hip first and
returns ["cuda_ext=1", "hip=<version>", "rocm_arch_list=<targets>"]:

  • PYTORCH_ROCM_ARCH wins; split the way torch does, trimmed/lowercased,
    deduped and sorted so ordering/spacing cannot fork the cache.
  • Otherwise the sorted, suffix-stripped gcnArchName of visible devices
    (utils.arch.normalize_arch), mirroring torch's _get_rocm_arch_flags.
  • No get_device_capability() on ROCm; rocm_arch_list=none when no target is
    available.

The CUDA path is untouched (only reached when torch.version.hip is falsy), so
existing CUDA cache keys are byte-identical — pinned by golden tests.

Tests

New tests/test_hip_jit_cache_target_4815.py (CPU-only, no ROCm hardware):
env change -> different key (gfx1200 vs gfx1201); same value reordered/spaced/
uppercased -> same key; HIP version in the key; TORCH_CUDA_ARCH_LIST does not
mask the gfx target; unset env -> sorted suffix-stripped device gcnArchName;
two-machine NFS scenario differs; no GPU -> stable rocm_arch_list=none;
non-HIP payload goldens unchanged.

pytest tests/test_hip_jit_cache_target_4815.py -> 9 passed
pytest <5 JIT suites> -> 117 passed, 1 failed

The failure (test_exllamav3_import_does_not_set_arch_list_env) is pre-existing
and environmental: its subprocess fakes 2 GPUs on a 1-GPU host, so torchao's
triton probe raises before reaching the changed code; it fails identically on
the parent commit.

Red on parent (source reverted, test kept): 7 failed, 2 passed — the env value
was ignored, HIP version was not in the key, and the payload had no ROCm target.

ruff: clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant