Fix order-dependent fp32 layout-invariance failure on gfx942 #806
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 632 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #806"
general
weight: 0.35
VeeraRajasekhar
Problem
tests/pytorch/test_numerics.py::test_transformer_layer_hidden_states_format[126m-2-dtype0]fails in the
test_numerics.ck.gemm-tritonqueue item (ci/pytorch.sh:130, TEST_LEVEL 3,NVTE_ROCM_ENABLE_MXFP8=1 NVTE_GEMM_BACKEND=TRITONunder theckattention config):The test asserts layout invariance: the same
TransformerLayer, same weights, same data, runonce with
attn_input_format="sbhd"and once with"bshd", must produce the same output.It is deterministic (bit-identical numbers across CI runs) but order-dependent: it passes
when run alone, passes on gfx950, and passes under every other backend config. Because CI's
"re-run failed jobs" narrows a job to only its failing tests, the rerun gives the test a fresh
process and reports green — which is why this hid for so long.
Root cause
Two independent things had to stack. Neither alone fails the test.
1. The trigger — a 1-ULP difference between the two layouts.
bias_gelu_fused()forwards its input to atorch.compile'd helper using the caller's shape,so
TransformerLayerhands it[s, b, h]forsbhdand[b, s, h]forbshd.torch.compilespecializes per input shape and makes no promise that two specializations roundidentically. The two layouts therefore produced results differing by 1 ULP (
2.384186e-07) in~342k of 12.6M elements — but only once enough earlier tests had primed Inductor differently.
Run alone, the difference is exactly
0.0.2. The amplifier — fp32 GEMMs were not running in fp32 on gfx942.
matmul_kernelcalledtl.dot()withoutinput_precision. Left at the default,tl.dotresolves to
"tf32"wherever the target allows it, and Triton's AMD backend adds"tf32"toallowed_dot_input_precisionsfor gfx942 only. So the identical TE source line meant XF32(10-bit mantissa) on MI300/MI325 and IEEE on MI355X. Measured against a float64 reference on
these shapes: ~2.6e-3 max absolute error under XF32 versus ~4e-6 under IEEE.
The reduced mantissa turns the 2.4e-7 input difference into 1.55e-5 at the fc2 output — against
8.9e-8 under IEEE. That is what crosses the 1e-5 tolerance, and why gfx950 was unaffected.
<details>
<summary>How the divergence was localised</summary>
Comparing both paths element-wise after undoing the (s,b)↔(b,s) row permutation, at each GEMM:
| | isolated (pass) | failing run | + IEEE | +
NVTE_TORCH_COMPILE=0||---|---|---|---|---|
| attention output | 0 | 0 | — | 0 |
| fc1 output | 0 | 0 | 0 | 0 |
| fc2 input (activation out) | 0 | 2.384186e-07 | 2.384186e-07 | 0 |
| fc2 output | 0 | 1.546741e-05 → fail | 8.940697e-08 | 0 |
Attention is bitwise identical even in the failing run, so the existing hipBLASLt comment in the
test is not the cause here. The difference is introduced at the activation and amplified by fc2.
Also ruled out: the Triton autotune cache. It selects identical configs in both the passing and
failing runs, and for these fp32 shapes every viable config produces bitwise-identical output.
</details>
Changes
Two separate commits, touching disjoint files, each independently sufficient to make the test pass:
1.
Use IEEE fp32 precision in the Triton dense GEMM kernel— passinput_precision="ieee"totl.dotinmatmul_kernel. Removes the arch-dependent precisionsplit so gfx942 and gfx950 agree.
tl.dotignoresinput_precisionfor fp16/bf16/fp8operands, so this affects fp32 GEMMs only.
2.
Make the fused bias-GeLU bitwise layout-invariant— collapse the leading dimensions toa single
[-1, hidden]view before calling the compiled helper, and restore the shape after.The helper is elementwise and broadcasts
biasover the last dimension only, so the leadingdims carry no meaning; both layouts now hit one specialization and agree bitwise by
construction. The view is free, and a non-contiguous input is left untouched.
Verification
MI300X (gfx942), ROCm 10.1 TheRock CI image, torch 2.13.0+rocm10.1.0, Triton 3.8.0.
Run against the exact failing scenario — tests 1–1386 of
test_numerics.pyfollowed by thetarget test, in one process, with the
ck.gemm-tritonenvironment:| | before | after |
|---|---|---|
| same 1387-test list | 1 failed, 800 passed, 586 skipped | 801 passed, 586 skipped |
| fc2 input divergence | 2.384186e-07 | 0.0 |
| fc2 output divergence | 1.546741e-05 → fail | 0.0 |
Every GEMM operand is now bitwise identical between the two layouts — exact invariance, not just
within tolerance.
Regression coverage on all three
gemm-tritonCI items:| suite | result |
|---|---|
|
triton_kernels/test_gemm_kernel.py| 378 passed, 678 skipped ||
test_fusible_ops.py| 1687 passed, 1941 skipped ||
test_float8_current_scaling_exact.py| 5 passed, 2 skipped |