Repository navigation
Studio: judge the compiled ROCm W8A8 linear per card, not once per process - #17078
Merged
Merged
Conversation
…ocess The RDNA arch check read the current device and its refusal (or a compile failure) was cached process-wide, so with two ROCm cards the first card decided for both: an RDNA2 / CDNA card could get the compiled linear after an RDNA3 card used it, and an RDNA3 card stayed eager after another card refused. Eligibility and failures are now keyed by the input's card (AUTO W8A8 reads the target's card), and a compile failure on one card leaves the others on the compiled linear.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci]
The per-card check read the current card's arch for a CPU input too, so on a ROCm torch with no visible card (HIP masked) every CPU call was refused as 'ROCm unknown arch'. Only the current card (no device) and HIP inputs are judged now. [skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 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". |
[skip ci]
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Nov 9, 2026
… own arch (follow-up to unslothai#17078) (unslothai#17195) ## Summary Follow-up to unslothai#17078. That PR made the compiled int8 W8A8 linear decide per card on ROCm: an RDNA3 / RDNA4 card runs it, and any other arch (for example CDNA gfx942) stays eager. The production routing is correct. The real two-card test it added still assumed both cards run the compiled linear: - it checked readiness only on the current card (`_require_the_compiled_linear()`) - it required `calls + 1` on both cards - it required `devices == {"cuda:0": None, "cuda:1": None}` On a mixed ROCm host with an RDNA card 0 and a CDNA card 1, card 1 correctly stays eager. The call count then does not move, so the test fails even though production behaves as intended. With a CDNA card 0 and an RDNA card 1, the test is skipped entirely and the RDNA card is never checked. ## Change (test only) - The test asks production for each card's own decision (`_fused_w8a8(torch.device("cuda", i))`). It skips only when neither card can run the compiled linear. - On CUDA, where no card is refused by arch, it still requires both cards to be ready. - For each card it expects `calls + 1` only where that card is ready. Output must be bit-identical to eager on every card. - The final per-card state must match: `None` for a ready card, a refusal reason for the others. No product code changes. ## Testing - `pytest -o addopts= tests/test_diffusion_native_quant_fused.py` on CPU: 48 passed, 5 skipped. The skipped tests, this one included, need real cards. - I had no two-card host here, mixed ROCm or otherwise, so the changed test did not execute in this PR. The failure on main follows directly from the old assertions and the routing in `_fused_w8a8` (`diffusion_native_quant.py`, the `_rocm_fused_w8a8_refusal` branch), which records a refusal for the non-RDNA card and returns no compiled function there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#16825 enabled the compiled int8 W8A8 linear on ROCm RDNA3 / RDNA4 only (gfx11xx / gfx12xx), and #17013 lets AUTO pick W8A8 on those cards. The architecture check read the current device, and its answer was cached for the whole process in one slot:
ROCm gfx942) stuck for the process, so a later RDNA3 card stayed eager and AUTO never picked W8A8 for it;So on a host with two different ROCm cards, which card ran first decided the path for both, even when each load was correctly placed on its own card.
Change
_fused_w8a8(device)takes the input's device (the linear's forward passesx.device), reads that card's arch once, and caches the answer under that card. The compiled function itself is still built once.rocm_rdna_w8a8_ready(ordinal)answers for the target's card. AUTO W8A8 passestarget.ordinal(current card when unset, as before).fused_w8a8_state()keepsfailed(the process-wide reason, else the first card's) and addsdevices(each card's answer).UNSLOTH_NATIVE_INT8_FUSED=0kill switch. NVIDIA keeps the compiled linear as before.torch.compile(not torch.compiler.is_compiling()), so the per-card lookup adds no guards. Its cost: 0.68 µs per call on main, 0.84 µs here (CPU,timeit, 3 x 5 x 200k calls).Tests
test_diffusion_native_quant_fused.py(CPU, HIP arch and compile runtime mocked):rocm_rdna_w8a8_readyis True for the RDNA card and False for the CDNA one.test_diffusion_native_quant_fused.py+test_diffusion_native_quant.pya174823)The torchao failure (
AffineQuantizedTensorhas noqdata) comes from the torchao version on this host and fails the same way on main. The RDNA / AMD / W8A8 cases intest_diffusion_backend.pypass (13).On gfx1151 (Strix Halo, ROCm)
Two jobs, base
49453f39avs head9e86484b7on the same runner:test_diffusion_native_quant_fused.py+test_diffusion_native_quant.py. The GPU job presents the one real card as two HIP devices (a second ordinal on the same gfx1151), so the per-card bookkeeping runs against real HIP indices.On the GPU job,
test_each_real_card_runs_the_compiled_linear_bit_identical_to_eagerran oncuda:1andcuda:0: the compiled linear engaged on each and matched eager bit for bit. The 5 failures on both arms (test_eager_w8a8_chunks_long_inputs_without_changing_the_result, two torchao offload tests, and the two ROCmtest_cuda_engagement_tests_skip_where_production_stays_eagercases) pre-date this PR.An earlier gfx1151 run of this branch caught a case the CPU tests missed. On a ROCm torch with no visible card, a CPU input was judged by the current card's arch (unreadable, so a refusal). Fixed in
9e86484b7: only the current card (no device given) and HIP inputs are judged.Not covered