← Back to Pull requests

Fix order-dependent fp32 layout-invariance failure on gfx942 #806

Closed
unknown closed this pull request without merging on Nov 18, 2026 05:04 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 03:53 UTC
Author

Problem

tests/pytorch/test_numerics.py::test_transformer_layer_hidden_states_format[126m-2-dtype0]
fails in the test_numerics.ck.gemm-triton queue item (ci/pytorch.sh:130, TEST_LEVEL 3,
NVTE_ROCM_ENABLE_MXFP8=1 NVTE_GEMM_BACKEND=TRITON under the ck attention config):

Mismatched elements: 44 / 3145728
Greatest absolute difference: 1.5467405319213867e-05 at index (0, 1289, 344)  (up to 1e-05 allowed)
Greatest relative difference: 0.0003233453899156302 at index (1, 1427, 467)   (up to 1.3e-06 allowed)

The test asserts layout invariance: the same TransformerLayer, same weights, same data, run
once 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 a torch.compile'd helper using the caller's shape,
so TransformerLayer hands it [s, b, h] for sbhd and [b, s, h] for bshd.
torch.compile specializes per input shape and makes no promise that two specializations round
identically. 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_kernel called tl.dot() without input_precision. Left at the default, tl.dot
resolves to "tf32" wherever the target allows it, and Triton's AMD backend adds "tf32" to
allowed_dot_input_precisions for 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 — pass
input_precision="ieee" to tl.dot in matmul_kernel. Removes the arch-dependent precision
split so gfx942 and gfx950 agree. tl.dot ignores input_precision for fp16/bf16/fp8
operands, so this affects fp32 GEMMs only.

2. Make the fused bias-GeLU bitwise layout-invariant — collapse the leading dimensions to
a single [-1, hidden] view before calling the compiled helper, and restore the shape after.
The helper is elementwise and broadcasts bias over the last dimension only, so the leading
dims 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.py followed by the
target test, in one process, with the ck.gemm-triton environment:

| | 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-triton CI 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 |

Diff: 632 lines (+474 / -158) across 7 files Reviewer: VeeraRajasekhar Review duration: 1511m
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
0.50
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 50.4% (MEDIUM) · Higher = larger blast radius
50.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 21.8% · Safe to merge
21.8%