Repository navigation
studio: extend the _grouped_mm null-kernel guard to Linux ROCm RDNA4 (gfx1201) - #7292
Conversation
torch._grouped_mm has a null HIP kernel on RDNA4 (gfx1200/gfx1201) at ROCm <= 7.12 (fixed in 7.13; ROCm/TheRock #5284). The existing guard that registers a Python mm/bmm fallback was win32-only, so Linux gfx1201 (e.g. R9700 Pro on Ubuntu) hits the null kernel -> illegal instruction during training. Extract the fallback registration into a module-level helper (_install_grouped_mm_cpu_fallback) and add a Linux branch that installs it, gated on gfx1200/gfx1201 AND HIP < 7.13 so NVIDIA/CUDA and every non-RDNA4 AMD arch are untouched, and it is a no-op on fixed runtimes. The Windows path now calls the same helper with identical behavior.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a9db488b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _hip_parts = [ | ||
| int(x) | ||
| for x in str(getattr(_torch_lin.version, "hip", "") or "").split(".")[:2] | ||
| if x.isdigit() | ||
| ] |
There was a problem hiding this comment.
Detect ROCm version when torch.version.hip is absent
On supported AMD SDK/Radeon ROCm wheels that encode an affected version such as +rocm7.12 only in torch.__version__, torch.version.hip is unset (the Windows branch explicitly handles this case). Here _hip_parts becomes empty, so this guard skips the fallback even when _hw.IS_ROCM is true and the GPU is gfx1200/gfx1201; those Linux installations still dispatch to the null kernel and crash during training. Parse the embedded ROCm version or fail conservatively for recognized ROCm builds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request refactors the ROCm _grouped_mm CPU fallback logic into a reusable helper function and extends this patch to Linux ROCm systems running on RDNA4 architectures (gfx1200/gfx1201) with ROCm versions <= 7.12. Feedback recommends wrapping the nested attribute resolution of _torch_lin.version.hip in a try/except block to safely handle potential AttributeErrors if those attributes are missing.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if sys.platform.startswith("linux") and _hw.IS_ROCM: | ||
| try: | ||
| _torch_lin = sys.modules.get("torch") | ||
| if _torch_lin is not None and _torch_lin.cuda.is_available(): | ||
| _lin_arch, _ = _rocm_classify_unified_memory( | ||
| _torch_lin.cuda.get_device_properties(0) |
There was a problem hiding this comment.
Accessing _torch_lin.version.hip directly can raise an AttributeError if version or hip is missing. Instead of using verbose nested getattr checks with None defaults, wrap the attribute resolution in a try/except AttributeError block to handle potential missing attributes cleanly.
| if sys.platform.startswith("linux") and _hw.IS_ROCM: | |
| try: | |
| _torch_lin = sys.modules.get("torch") | |
| if _torch_lin is not None and _torch_lin.cuda.is_available(): | |
| _lin_arch, _ = _rocm_classify_unified_memory( | |
| _torch_lin.cuda.get_device_properties(0) | |
| try: | |
| _hip_str = _torch_lin.version.hip | |
| except AttributeError: | |
| _hip_str = None | |
| _hip_parts = [ | |
| int(x) | |
| for x in str(_hip_str or "").split(".")[:2] | |
| if x.isdigit() | |
| ] | |
| _hip_lt_713 = len(_hip_parts) == 2 and (_hip_parts[0], _hip_parts[1]) < (7, 13) |
References
- When resolving nested attributes using getattr where intermediate objects may be None, wrapping the resolution chain in a try/except block is an acceptable way to handle potential AttributeErrors, making verbose inline None checks redundant.
…for PR #7292 AMD SDK / Radeon ROCm wheels leave torch.version.hip empty and encode the version only in torch.__version__ (e.g. +rocm7.12). The Linux gfx120X guard parsed version.hip only, so those affected installs skipped the fallback and still hit the null _grouped_mm kernel. Mirror the Windows parse: version.hip, then the embedded rocmX.Y, then assume affected unless a post-fix rocmsdk wheel.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4a166db08
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if _lin_arch.lower() in ("gfx1200", "gfx1201") and _hip_lt_713: | ||
| _WINDOWS_ROCM_GROUPED_MM_LIB = _install_grouped_mm_cpu_fallback( | ||
| _torch_lin, logger, "Linux ROCm gfx120X" |
There was a problem hiding this comment.
Add a fallback for RDNA4 devices without arch metadata
On Linux Radeon/AMD SDK wheels that do not expose gcnArchName (or the other arch properties), _rocm_classify_unified_memory() returns an empty arch; its name fallback only recognizes gfx1150/gfx1151 APUs. Consequently this condition skips the workaround even for an affected gfx1200/gfx1201 device, so training still reaches the null _grouped_mm HIP kernel and crashes. Detect the known RDNA4 device names or use another available ROCm arch source before deciding to skip.
Useful? React with 👍 / 👎.
| _lin_arch, _ = _rocm_classify_unified_memory( | ||
| _torch_lin.cuda.get_device_properties(0) | ||
| ) |
There was a problem hiding this comment.
Check every visible GPU for the RDNA4 workaround
When a training job selects multiple GPUs and device 0 is a non-RDNA4 AMD card while another visible device is gfx1200/gfx1201 on ROCm <= 7.12, this probe only inspects device 0 and leaves the CUDA-dispatch override uninstalled. Studio uses device_map="balanced" for multi-GPU selections, so model layers can execute on the later RDNA4 device and still hit the null kernel. Scan the visible devices and install the process-wide override if any selected device is affected.
Useful? React with 👍 / 👎.
|
Addressed both review points in dca7d6f:
|
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
/gemini review |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
* ROCm/AMD CI coverage: arch-table parity, native-Linux lib prepend, RDNA4 grouped_mm, discovery-based shell suite
Three merged ROCm fixes shipped without tests, and the CI wiring that
would have run them was gated on files the fixes do not touch.
Tests added (113):
tests/studio/install/test_rocm_arch_table_parity.py (27)
diffs the four duplicated gfx -> AMD pip-index tables across
install.sh, install.ps1, studio/setup.ps1 and install_python_stack.py,
plus the GPU-name -> arch tables and the torch 2.11 pin allowlist.
tests/studio/install/test_rocm_native_linux_lib_dirs.py (26)
covers #7233: system-ROCm lib dirs prepended ahead of bundled
libggml-hip, the /dev/kfd + not-WSL + libhsa gate, the opt-out env
var, root resolution order, and source parity between the two copies.
studio/backend/tests/test_grouped_mm_rdna4_fallback.py (46)
covers #7292: registration on the CUDA dispatch key, grouped and
ungrouped numerics, bias/dtype promotion, and the Linux HIP<7.13 +
RDNA4 name gate, executed from the shipped source rather than a copy.
tests/studio/test_ci_shell_suite_coverage.py (14)
fails if either shell runner goes back to a hardcoded list or skips
a file without a recorded reason.
CI wiring:
studio-backend-ci.yml: add install.sh / install.ps1 to the path filter
(the suites it runs assert against those two files, so install-only
changes -- the shape most AMD/ROCm routing fixes take -- skipped it),
and replace the 13-file hardcoded shell list with directory
discovery. That list had fallen seven files behind, including
test_strixhalo_wsl_reroute.sh, the only shell coverage of the ROCm
WSL reroute, which had never run on a PR.
tests/run_all.sh: same discovery loop so local and CI agree.
* Test review fixes: assert on outcomes, not on the code under test
Self-review of the previous commit found four tests that passed for the
wrong reason.
1. The arch-table parity test pinned expected gfx ids copied out of the
shipped tables, which enshrined three upstream inaccuracies as
correct: RX 9070 (non-XT) is gfx1201 not gfx1200, RX 7800 XT is
gfx1101 not gfx1100, and PRO V710 is gfx1101 not gfx1102 per AMD's
ROCm compatibility matrix. The expectation is now the AMD pip index
leaf -- the thing the tables exist to produce, and what a wrong
answer costs the user. The three known drifts are listed explicitly
with a test asserting they stay cosmetic, i.e. that the wrong and
right ids still map to the same wheel index. That test turns red the
day one of them starts routing users to the wrong wheel.
2. The RDNA4 device-name test extracted the regex from worker.py and
then matched with it, so it could not fail. Widening the pattern --
the dangerous edit, since it forces the slow Python mm fallback onto
RDNA3 users -- would have been silently accepted. It now reads the
live pattern and checks it against fixed cases, plus asserts the
name match stays guarded by `not _lin_arch` and that the name is
lowercased before matching.
3. The CI-coverage test matched a verbatim line of studio-backend-ci.yml,
so reindenting the step would fail the build while a real regression
to a hardcoded list could slip past a reformat. It now parses the
YAML, finds the step by name, and asserts on the glob plus the
absence of individual filenames. The path-filter test likewise reads
the parsed trigger instead of scanning raw text.
4. A set comprehension in the parity helper had a ternary whose branches
were identical.
Mutation-tested: widening the RDNA4 regex, desyncing one copy of the
name table, dropping install.sh from the path filter, and re-skipping
the ROCm WSL shell suite each fail at least two tests. Verified on
Linux (WSL Ubuntu 24.04) with CI's torch pin: 86 + 48 pass.
* Fix three wrong gfx ids in the GPU-name arch tables
The name -> gfx tables disagreed with AMD's ROCm compatibility matrix on
three entries. Corrected against the "Radeon GPU" list at
rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html:
RX 9070, RX 9070 GRE gfx1200 -> gfx1201 (Navi 48, same die as the XT)
RX 7800 XT, RX 7700 XT gfx1100 -> gfx1101 (Navi 32, not Navi 31)
PRO W7700 gfx1100 -> gfx1101
PRO V710 gfx1102 -> gfx1101 (Navi 32, not Navi 33)
No wheel changes for anyone: gfx1200/gfx1201 both resolve to gfx120X-all
and gfx1100/gfx1101/gfx1102 all resolve to gfx110X-all, in all four copies
of the index-family map. That collapse is why the errors survived being
copied into six places -- the leaf-level tests could not see them.
It was not purely cosmetic, though. install.sh's second copy feeds
"Tip: set UNSLOTH_ROCM_GFX_ARCH=<arch>", so a 7800 XT user following the
printed advice exported gfx1100 and made a wrong id authoritative for
every later run. It would also have become a real misroute the moment AMD
split a family across index leaves, as they already do for gfx1151/gfx1150.
Fixed in all six places, which is two more than the table's own "kept in
sync with" comments claim exist:
install.sh _infer_amd_gfx_arch_from_gpu_name
install.sh case "$_gpu_disp_mkt" (banner + env tip; undocumented)
studio/setup.sh
install.ps1
studio/setup.ps1
studio/install_python_stack.py
Ordering is preserved: the gfx1102 arm still precedes gfx1101 in the shell
copies so "RX 7700S" cannot fall onto the "RX 7700" glob, and the
PowerShell copies keep the (?!S) lookahead.
Test changes:
- test_rocm_arch_table_parity.py gains _AMD_DOCUMENTED_ARCH, exact gfx
ids transcribed from AMD rather than from the tables. Agreement between
six copies proves nothing when all six were transcribed from the same
mistake, so the ground truth has to come from outside. Verified it
catches the bug: against the pre-fix tables it fails 6 tests.
- The parity check now covers all six copies. It had four; the two
install.sh copies were being treated as one, and
_WIN_GPU_NAME_ARCH_TABLE was not checked at all.
- test_rocm_support.py's TestGfxArchNameFallback pinned two of the wrong
ids as expected values; updated, and extended with a 9060 XT and a
7900 XTX case so each RDNA3/4 die is represented.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Guard against unregistered copies of the GPU-name arch table
Counting the copies by hand is what let them drift: the in-code "kept in
sync with" comments claimed four, the arch-id fix found six, and scanning
the tree turns up a seventh.
TestNoUnregisteredArchTable rediscovers the copies from the source tree
instead of trusting a hand-maintained list. A table line is one that names
a card and gives its arch; real tables score 9-17 such lines and the only
other hits in the repo are two single-line prose comments, so the
three-line threshold is not load-bearing. A companion test asserts the
scan still finds the known copies, so the heuristic cannot go blind and
pass by finding nothing.
The seventh copy is tests/_zoo_rocm_spoof.py, the fixture other ROCm tests
build their fake AMD host from. It states the mapping backwards (gfx ->
the name torch should report), which makes it an independent witness: it
had gfx1101 -> RX 7800 XT and gfx1201 -> RX 9070 XT right while all six
installer copies were wrong, and nothing compared the two. Now they are
round-tripped against each other.
RX 6700 XT is pinned as a known divergence rather than normalised. AMD's
compatibility matrix documents no consumer RX 6000 card and no gfx1031 at
all, the installer arm is commented "gfx103X family", and gfx1031 appears
only as an index-family key, never as a value a name table emits. With no
external source to correct against, changing shipped behaviour would be
guesswork. A test fails if the divergence ever disappears, so the
exemption cannot go stale.
Also adds the reverse of the AMD-matrix check: a documented card that
matches no arm anywhere is a silent CPU fallback rather than a wrong id.
This cannot detect hardware nobody transcribed, which would need a live
fetch of AMD's matrix and a non-hermetic suite; the docstring says so
rather than implying coverage that is not there.
Verified on Linux: 478 passed, plus all five new guards mutation-tested
to confirm each fails when its invariant is broken.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Docstring said six copies; the list under it now has seven
* tests: run discovered shell tests with bash, not sh
tests/run_all.sh discovered tests/sh/ instead of listing files, but still
invoked each one with sh. Every file there declares a bash shebang, and on
Debian/Ubuntu /bin/sh is dash: test_apt_distro_prompt.sh,
test_studio_home_node_dir.sh and test_with_llama_cpp_dir_link_behavior.sh
fail on bashisms under dash and pass under bash. The old hand-written list
happened to name only dash-clean files, so switching to discovery is what
surfaced it. Backend CI already used bash, so this was a local-only break.
Guarded by a new test asserting both runners invoke tests/sh/ with bash.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix Krackan Point (Radeon 860M/840M) routed to the gfx1150 wheel index
The GPU-name tables map 860M/840M and the Ryzen AI 7 350 / AI 5 340 CPU
strings to gfx1150, but Krackan Point is gfx1152. AMD's own lemonade table
(src/cpp/server/system_info.cpp) maps both Krackan iGPUs to gfx1152.
Unlike the three ids already fixed here, this one is not wheel-neutral:
repo.amd.com publishes gfx1150 and gfx1152 as separate index leaves with
separately built torch wheels, so these laptops were installing wheels
built for a different LLVM target. gfx1152 was absent from the codebase
entirely, so it needed the index-family maps, the torch 2.11 floor lists
(same _grouped_mm bug as gfx1150/1151), the Strix reroute set and the
Windows arch allowlist as well as the seven name tables.
The parity test added in this PR did not catch it because its AMD-matrix
expectations stopped at 890M/880M. Added the APU rows, so the case that
actually changes a wheel is now covered: reverting the tables fails 9
tests naming 860M, 840M and Krackan.
gfx1153 (Ryzen AI 5 430 era) is left alone; AMD publishes no gfx1153
wheel family, so there is nothing to route it to.
Verified: bash -n on both shell installers, PowerShell AST parse on both
.ps1 files, python ast.parse on all touched modules, install suite 1334
passed with no new failures against main, shell suite 20 files.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add gfx1152 to unified-memory classifiers, make parity allowlist set-based
Krackan Point (gfx1152, Radeon 860M/840M) is the third RDNA 3.5 APU and
shares one GPU/system-RAM pool exactly like Strix Point (gfx1150) and
Strix Halo (gfx1151), but only the installers knew about it. The two
runtime classifiers still had two-element arch sets, so a Krackan laptop
got the 0.90 discrete headroom factor on a shared pool and ran llama.cpp
without GGML_CUDA_ENABLE_UNIFIED_MEMORY.
- worker.py _rocm_classify_unified_memory: add gfx1152 to the arch set,
and 860m/840m to the device-name fallback. The NVIDIA GeForce 840M
cannot collide there: the function is only reached under _hw.IS_ROCM.
- llama_cpp.py _amd_apu_wants_unified_memory: add gfx1152 to the arch set.
- Tests for both, including the :sramecc-:xnack- suffix form.
TestGfx211AllowlistParity compared four hardcoded allowlist strings, so
adding gfx1152 to all four installers correctly turned three assertions
red without any installer actually disagreeing with another. Each test
now extracts the set its installer holds and compares it to one EXPECTED
constant. Order and spacing are free, membership is not, and the next
leaf is a one-line edit instead of four.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
What
torch._grouped_mmhas a null HIP kernel on RDNA4 (gfx1200/gfx1201) at ROCm <= 7.12 (fixed in ROCm 7.13; ROCm/TheRock#5284). The training worker already registers a Python mm/bmm fallback to bypass it, but the guard was win32-only. Linux RDNA4 (e.g. R9700 Pro AI on Ubuntu 24.04) therefore hit the null kernel and crashed with an illegal-instruction during training (reported on r/unsloth).How
_install_grouped_mm_cpu_fallback(torch_mod, logger, label). The Windows path now calls it with identical behavior (sameLibrary("aten", "IMPL"), same_grouped_mmCUDA-key override, same GC-retention handle).sys.platform.startswith("linux")and_hw.IS_ROCM, and{gfx1200, gfx1201}(via the existing_rocm_classify_unified_memoryarch parse), andtorch.version.hip < 7.13.So NVIDIA/CUDA, Mac, and every non-RDNA4 AMD arch are never touched, and it is a no-op on fixed runtimes (ROCm 7.13+). Studio's installer already pins gfx1201 to
torch>=2.11.0,<2.12.0(rocm7.13), so this is belt-and-suspenders for that path and the real fix for manual/older ROCm <= 7.12 Linux installs.Verification
ast.parseclean.gfx1201+7.12 -> patch,gfx1201+7.13 -> skip,gfx1200+6.3 -> patch,gfx1151/gfx1100+7.12 -> skip, missing/unparseable HIP -> skip.