Skip to content

gemm: replay only the dense MMA cells of an exceptional row or column - #711

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:fix-gemm-dense-mma-isolate
Oct 23, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:fix-gemm-dense-mma-isolate

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

GB10의 BF16, MXFP8, FP8_B128 prompt 행렬곱에서 값 하나가 텐서코어 범위를 벗어나면 같은 타일의 다른 칸까지 F32 값으로 바뀌던 결함을 고쳐서, 각 칸이 자기 행과 열의 값에만 따르게 하는 수정입니다.

Part of #565. Tracked in #699.

What and why

On GB10 the dense prompt products for BF16, MXFP8 and FP8_B128 weights run on tensor cores (bf16_mma_gemm, mxfp8_mma_gemm, fp8_b128_mma_gemm). When one staged operand is outside the range the tensor cores take (mma_fits), the tile is recomputed on the exact F32 path. Before this change the recompute replaced every cell of the 128 by 128 tile, so a single subnormal activation changed the output bits of the other tokens in that tile. A normal token's bits therefore depended on which other tokens shared its ubatch, which breaks the per-token bit contract in the wide38.rs module doc.

The cause is in bf16_mma_body. With ISOLATE=false, the block vote in MmaTile::needs_replay ran replay::<_, false>, which rewrote the whole tile through f32_tile_at::<_, _, false>. Only bf16_mma_gemm_columns (HC down) and the fused HC up mix marked cells per row and column. The defect came in with c7f7f41 (BF16 tensor cores for GB10 dense prompt products) and a0baef9 (replay of exceptional dense MMA tiles), both merged in #668.

crates/gpu/src/gemm/f32tile.rs is now the one owner and the ISOLATE parameter is gone.

  • MmaTile keeps each thread's refused staged lines (lines: u32, one bit per weight and activation line) instead of one retry flag.
  • MmaTile::needs_replay takes the block vote as before. Only when some warp voted does it write the line flags to the unused stage and mark the cells whose row or column is flagged. A tile with no refused operand pays one vote and writes no flags.
  • bf16_mma_body stores after the vote. With no replay it stores plainly. With a replay it stores the marked cells as NaN, takes a barrier, and replay recomputes only those cells on the F32 path.
  • bf16_mma_gemm_columns is removed, because it is now the same kernel as bf16_mma_gemm. enqueue_bf16_prompt and enqueue_bf16_mma lose their const parameter, and their callers in site.rs, hc_gated.rs, kernels32.rs and the gates follow.
  • The PTX pin tables drop the bf16_mma_gemm_columns rows, and the sm_86 spill pin of hc_gated_up_mma_mix_4 moves from 920 to 0 with a PIN(2026-10-23) line. The unsafe ratchet for gpu moves from 2256 to 2254.

Inputs with no refused operand keep their bits. Cells next to an exceptional row or column change from the F32 value to the MMA value, which is the rule the HC paths already used.

Release notes: Fixed: on GB10, a dense BF16, MXFP8 or FP8_B128 prompt product recomputes only the cells of an out-of-range row or column in F32, so a token's output no longer depends on the other tokens in its tile.

Code shape

  • No second copy. The cell marking lives in MmaTile::needs_replay, shared by the dense formats and the HC up mix. The duplicate kernel bf16_mma_gemm_columns is removed.
  • Model code holds only architecture facts. No model file changed.
  • Dead code is gone. The ISOLATE const parameter, the MARKED parameter of replay, bf16_mma_gemm_columns and its pin rows are removed.
  • No silent failure. The new gate helper returns its verdict and propagates launch errors.
  • Comments state what is true now.
  • No relaxed gate. No band or tolerance moved. The sm_86 spill pin of hc_gated_up_mma_mix_4 is lowered to the value the scan reads, with a PIN(2026-10-23) line.
  • cargo fmt --all -- --check is clean. I did not run cargo clippy.

Duplication found or removed (path:line): bf16_mma_gemm_columns in crates/gpu/src/q8f32.rs:1861 duplicated bf16_mma_gemm once the marking moved into the shared tile; it is removed.

What I ran

The new gate clauses were added first, on the old API, and run against main with only those clauses. Then the same gates ran on the fix.

  • gate_gemm --case dense_mma: a 130 by 130 output at K = 128 per format (bf16, mxfp8, fp8_b128), unit weights, activations 1 + 2^-10 (BF16 rounds them to 1, F32 keeps them). Column 129 can hold one subnormal activation and row 64 one weight of 2^60. Three clauses: no odd line, a column, a column and a row. Every other cell must equal K exactly, and the odd lines must equal the exact tile.
  • mma.neighbours in gate_bf16 and gate_mxfp8 (through site::gemm, compute capability 12.1): a subnormal first value in column 1 must leave every other column's output bits equal to the run without it.

Each just gate-gpu-* line below names the recipe whose last step I ran, bash tools/gpu-gate.sh <binary>, on binaries built from the fix and, for the FAIL-first, from main plus the new clauses.

FAIL-first, on main plus the new clauses:

dense_mma bf16 cells rows=130 K=128 n=130 row64_odd=false col129_odd=true others_kept_k=false odd_lines_exact=true FAIL
dense_mma mxfp8 cells rows=130 K=128 n=130 row64_odd=false col129_odd=true others_kept_k=false odd_lines_exact=true FAIL
dense_mma fp8_b128 cells rows=130 K=128 n=130 row64_odd=true col129_odd=true others_kept_k=false odd_lines_exact=true FAIL
bf16 clause=mma.neighbours shape=blk.3.attn_q.weight rows=8192 k=2560 m=64 subnormal_column=1 other_columns_bits=false FAIL
mxfp8 clause=mma.neighbours shape=blk.3.attn_q_b rows=16384 k=1536 m=64 subnormal_column=1 other_columns_bits=false FAIL
fp8_b128 clause=mma.neighbours shape=blk.3.attn_q_b rows=16384 k=1536 m=64 subnormal_column=1 other_columns_bits=false FAIL

On main the log marks six cells rows FAIL (each format, with an odd column) and leaves the three rows with no odd line without a FAIL. All four BF16 mma.neighbours rows and six of the twelve MXFP8 and FP8_B128 rows are marked FAIL. The six scale-edge shapes of gate_mxfp8 leave the odd column's own row exceptional, so main already replays every column there and they do not distinguish the two behaviours.

On the fix, GB10 card and gates:

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
just gate-gpu-gemm --case dense_mma
gpu-gate.sh: gate_gemm ran 13 s (exit 0)
dense_mma fp8_b128 cells rows=130 K=128 n=130 row64_odd=true col129_odd=true others_kept_k=true odd_lines_exact=true PASS
just gate-gpu-hc-gated
gpu-gate.sh: gate_hc_gated ran 1 s (exit 0)
wide[bf16-cell-range] mma_kept_and_masked_replayed=true PASS
just gate-gpu-bf16
gpu-gate.sh: gate_bf16 ran 4 s (exit 0)
bf16 clause=mma.neighbours shape=blk.3.attn_q.weight rows=8192 k=2560 m=64 subnormal_column=1 other_columns_bits=true PASS
just gate-gpu-mxfp8
gpu-gate.sh: gate_mxfp8 ran 17 s (exit 1)
mxfp8 clause=mma.neighbours shape=blk.3.attn_q_b rows=16384 k=1536 m=64 subnormal_column=1 other_columns_bits=true PASS

Totals over the full head logs: gate_gemm 70 PASS, 0 FAIL; gate_hc_gated 125 PASS, 0 FAIL; gate_bf16 309 PASS, 0 FAIL; gate_mxfp8 342 PASS, 1 FAIL (see below). Every dense_mma ... eager_graph_bits row on the fix reads true.

Normal inputs keep their bits. A kernel micro run on this GB10 (M = 4096 columns, three warmups, ten timed calls, main and head alternated) gives equal output digests on all eight in-range shapes. The largest shape:

MMA_MICRO format=bf16 odd=false M=4096 N=10240 K=2560 repeats=10 ms=4.967929 TFLOPS=43.227 finite=true digest=8a67d7e152498f57
MMA_MICRO format=bf16 odd=false M=4096 N=10240 K=2560 repeats=10 ms=4.968134 TFLOPS=43.225 finite=true digest=8a67d7e152498f57

I ran cargo fmt --all -- --check and tools/check-unsafe.sh, and the workspace cargo check --workspace --all-targets compiled every crate without a warning. I did not run cargo clippy, the other tools/check-*.sh scripts or tools/ptx-compare.sh; those are the maintainers' checks. The gates were run on the commits before the final rebase onto current main. The rebase left every crates/ line of this change as it was and changed only table hunks around the removed rows.

Hardware

One DGX Spark (NVIDIA GB10, driver 595.84, CUDA 13.3), the gate and micro runs above. No other GPU was used. The sm_86 spill pin was read from a build for that architecture, run through the driver JIT on the GB10; no sm_86 card was used, so the jit_local value of the cc 8.6 row keeps its existing pin.

What I ran into

These do not block this PR.

  • gate_mxfp8 still reports sel.refusal as FAIL. The gate expects "a q8_0 or fp8_b128 stack" while site::resident_sel_f32 now says "a q8_0, fp8_b128 or nvfp4 stack" after qwen38: load the checkpoint folder MTP draft in its stored formats #682. This change does not touch either side, so I left the gate as it is.
  • replay still recomputes the full tile on the F32 path and stores only the marked cells, so a tile with one odd column costs several times a normal tile. That only matters for inputs with subnormal or very large values, and it is the same cost as before.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 23, 2026
The dense prompt MMA (bf16_mma_gemm, mxfp8_mma_gemm, fp8_b128_mma_gemm)
replayed a whole 128 by 128 tile on the exact F32 owner when one operand of
the tile left the tensor cores' range, so every other cell of the tile took
the F32-activation value instead of its MMA value: a token's outputs changed
with what its neighbours in the ubatch held. Every dense MMA product now
marks the cells whose row or column staged such an operand, replays those
alone and keeps every other cell's MMA bits, as the HC prompt products
already did; bf16_mma_gemm_columns and the const parameters that picked a
mode go. The marks are made only when the block's vote finds an exceptional
operand, so a tile without one runs as before.

The PTX pins follow the GB10 scans: bf16_mma_gemm_columns leaves the tables,
the three dense entries stay at 0/0 on sm_86, sm_121 and sm_121a, and
hc_gated_up_mma_mix_4 reads 0 sm_86 spill bytes (was 920) with its sm_121
260/96 and sm_86 JIT 96 unchanged.
github-actions[bot]
github-actions Bot previously approved these changes Oct 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: The replay mask preserves cells outside exceptional rows and columns.

Non-blocking

⚠ Complete the numeric evidence: crates/gpu/src/gemm/f32tile.rs:1015 changes healthy cells beside exceptional operands from F32 replay to MMA precision. The float precision class requires the gate-gpu-e2e count pin and timed A/B; the supplied timing covers ordinary inputs. Add the end-to-end result and an exceptional-input A/B with both tested commit hashes.

⚠ Report the first failed cell: crates/gpu-gates/src/bin/gate_gemm.rs:7015 prints only aggregate booleans. A failed mask requires another probe to locate the error. Include the first failing row, column and MMA/exact bits in this existing report to supply the fix's debuggability layer.

Optimization headroom

  • E, Less work: crates/gpu/src/gemm/f32tile.rs:769 still recomputes unmarked subtiles. Skip those subtiles: one refused column in a full 128×128 tile leaves 24 of 32 exact passes unnecessary, including 24×(K/64+1) block barriers [derived].

Checked

Duplicates: 1 new function checked, no duplicate owner. The dryer pair is two format-specific kernel entries calling the same core.
Complexity: dense_mma_case 48→76 adds fixture construction, execution and assertions to an existing function; site_case 40→41 and e4m3_case 28→29 extend existing clauses.
Silent failure: 1 marker path followed: NaN store → barrier → exact replay before consumption; launch/readback errors propagate.
Tests, static mutation: f32tile.rs:718 changing || to && fails exceptional-line assertions; :779 changing marked replay to whole-tile writes fails kept and mma.neighbours; shifting coordinates at :639 fails layout bounds.
Gates: dated PINs explain the narrowed exact assertion, kernel-name replacement and tighter spill pin; no tolerance moved.
Escape catalog: no pattern matched.

Notes

The supplied gate logs omit the tested commit hashes, so GPU evidence is incomplete. Validation here was static; GPU gates were not run.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/gate_hc_gated.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Filed outside this PR: #712

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review, the kernel patch is unchanged. The interdiff replaces the old unsafe-pin edit with a count for the rebased tree.

Verdict: CLEAN: The rebased unsafe pin matches the source count and has a dated reason.

Non-blocking

⚠ Complete the numeric evidence — still open: crates/gpu/src/gemm/f32tile.rs:1015 changes healthy cells beside exceptional operands from F32 replay to MMA precision. The supplied timing covers ordinary inputs. Add the float-precision class's gate-gpu-e2e count-pin result and an exceptional-input timed A/B, with both tested commit hashes, to verify the engine-level effect.

⚠ Report the first failed cell — still open: crates/gpu-gates/src/bin/gate_gemm.rs:7015 still reports aggregate booleans. Each mask failure requires another probe to locate the error. Include the first failing row, column and MMA/exact bits in this existing report.

Checked

Duplicates: 0 new Rust items in the interdiff. Dryer pair read: the two format-specific kernel entries delegate to the same core; no duplicate computation.
Complexity: dense_mma_case 48→76 adds fixture/execution/assertion work; site_case 40→41 and e4m3_case 28→29 extend clauses. All are unchanged since the previous review.
Silent failure: 0 new sites. The replay marker path still has a barrier before exact replay.
Tests: no new or changed tests in the interdiff; prior mutation checks remain applicable. No GPU gates run here.
Gates: gpu blocks tighten 2268→2266 with PIN(2026-10-23) and the kernel-removal reason. Independent recounts match both trees, including unchanged 278 functions and 10 impls; the removed kernel contains exactly two blocks.
Escape catalog: no pattern matched.

Notes

GPU evidence remains incomplete because the supplied runs omit their tested commit hashes. Dryer did not search gpu-gates; the interdiff adds no Rust code there.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/gate_hc_gated.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit e14cd46 into midagedev:main Oct 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant