prefill: adopt upstream's tuned GEMM recipe (~540 TF) — bit-exact fp32 + dst_full_sync variant, one-card probe queued #109

Closed
opened 2026-09-27 19:37:24 +02:00 by Grok · 5 comments
Owner

Desk research + ttsim correctness 2026-09-27. No hardware result yet; probe queued at the end of bench/queues/c68-mrx-then-mtp.txt.

Claim

Prefill projection matmuls run ~300-326 TF/card in-model (docs/notes/prefill-roofline-audit-2026-09-27.md), about 50% of the 608 TF 11x10 LoFi peak. Upstream's tuned GEMM benchmark (tech_reports/GEMM_FLOPS/GEMM_FLOPS.md, tests/ttnn/unit_tests/benchmarks/test_benchmark.py:465-560 @60053f1) reports 483-501 TF bfp4 LoFi at M=2560 and up to 541 TF at M>=5120 (third-party). Matmuls are ~167 ms of a 2048-token chunk, so closing half the gap ≈ −50…−60 ms per chunk (≈ −10% prefill at every context length, estimate). Per-chunk cost, so it scales with prompt length.

Recipe differences (each an arm in the probe)

  1. 2D mcast MatmulMultiCoreReuseMultiCast on the full grid vs our all_gather_minimal_matmul_async (11x8) / 2D row-parallel (8x6).
  2. bf16 dest + packer_l1_acc → 8-tile subblocks vs our fp32 dest (4-tile).
  3. in0 in bfp4/bfp8 vs our bf16.
  4. L1 block-sharded in0/out; square shapes that divide the grid.

ttsim (correctness only, no timing) — bench/runs/prefill-gemm-upstream-recipe-ttsim-smoke-20260927T153136Z.jsonl

  • Upstream 2D with fp32 dest + dst_full_sync_en (8-tile subblocks) is BITWISE equal to the prod output on mlp_down, attn_qkv, attn_wo, gdn_in, gdn_out (smoke sizes). → bit-exact adoption path, no numerics approval needed.
  • bf16 dest: not bitwise (PCC 0.99359-0.99362 vs prod 0.99368); in0 bfp4: PCC 0.9868 — reject.
  • mlp_gate_up not checkable on ttsim (fused SiLU uses an SFPU op ttsim lacks).

Probe

bench/probes/prefill_gemm/run.sh (one card, slot protocol, no model): per shape at M=2048 with bfp4 weights — prod config, prod+8-tile fp32 subblocks, upstream 2D fp32+full-sync (11x8/11x10), upstream exact (bf16 dest; in0 bf16/bfp8/bfp4); ms, TF, PCC vs fp64, bitwise vs prod; plus a calibration rung on upstream's 5120x5632x5632 shape (checks the AICLK bug, docs/HARDWARE.md:91).

Gates

  1. Probe: kill if the bit-exact arm is < 10% faster than prod on the summed per-forward time.
  2. In-model: banner-gated arm (QWEN36_PREFILL_GEMM_2D=1 engaged), workbench prefill profile, equiv gate, then sweep32k PP. Remember bench/runs/prefill-audit-20260912T100217Z.jsonl: a 2.35x standalone win on down-proj was 0% in-model (output placement / L1 contention) — the in-model A/B decides.
  3. Col-parallel roles lose the fused all-gather; the separate AG (~10 MB/chunk/layer) must be charged in the A/B.
Desk research + ttsim correctness 2026-09-27. No hardware result yet; probe queued at the end of `bench/queues/c68-mrx-then-mtp.txt`. ## Claim Prefill projection matmuls run ~300-326 TF/card in-model (docs/notes/prefill-roofline-audit-2026-09-27.md), about 50% of the 608 TF 11x10 LoFi peak. Upstream's tuned GEMM benchmark (`tech_reports/GEMM_FLOPS/GEMM_FLOPS.md`, `tests/ttnn/unit_tests/benchmarks/test_benchmark.py:465-560` @60053f1) reports 483-501 TF bfp4 LoFi at M=2560 and up to 541 TF at M>=5120 (**third-party**). Matmuls are ~167 ms of a 2048-token chunk, so closing half the gap ≈ −50…−60 ms per chunk (≈ −10% prefill at every context length, **estimate**). Per-chunk cost, so it scales with prompt length. ## Recipe differences (each an arm in the probe) 1. 2D mcast `MatmulMultiCoreReuseMultiCast` on the full grid vs our `all_gather_minimal_matmul_async` (11x8) / 2D row-parallel (8x6). 2. bf16 dest + `packer_l1_acc` → 8-tile subblocks vs our fp32 dest (4-tile). 3. in0 in bfp4/bfp8 vs our bf16. 4. L1 block-sharded in0/out; square shapes that divide the grid. ## ttsim (correctness only, no timing) — `bench/runs/prefill-gemm-upstream-recipe-ttsim-smoke-20260927T153136Z.jsonl` - **Upstream 2D with fp32 dest + `dst_full_sync_en` (8-tile subblocks) is BITWISE equal to the prod output** on mlp_down, attn_qkv, attn_wo, gdn_in, gdn_out (smoke sizes). → bit-exact adoption path, no numerics approval needed. - bf16 dest: not bitwise (PCC 0.99359-0.99362 vs prod 0.99368); in0 bfp4: PCC 0.9868 — reject. - mlp_gate_up not checkable on ttsim (fused SiLU uses an SFPU op ttsim lacks). ## Probe `bench/probes/prefill_gemm/run.sh` (one card, slot protocol, no model): per shape at M=2048 with bfp4 weights — prod config, prod+8-tile fp32 subblocks, upstream 2D fp32+full-sync (11x8/11x10), upstream exact (bf16 dest; in0 bf16/bfp8/bfp4); ms, TF, PCC vs fp64, bitwise vs prod; plus a calibration rung on upstream's 5120x5632x5632 shape (checks the AICLK bug, docs/HARDWARE.md:91). ## Gates 1. Probe: kill if the bit-exact arm is < 10% faster than prod on the summed per-forward time. 2. In-model: banner-gated arm (`QWEN36_PREFILL_GEMM_2D=1 engaged`), workbench prefill profile, equiv gate, then sweep32k PP. Remember bench/runs/prefill-audit-20260912T100217Z.jsonl: a 2.35x standalone win on down-proj was 0% in-model (output placement / L1 contention) — the in-model A/B decides. 3. Col-parallel roles lose the fused all-gather; the separate AG (~10 MB/chunk/layer) must be charged in the A/B.
Author
Owner

Queue ran the probe (bench/runs/prefill-gemm-probe-20260927T184015Z.jsonl, card 1, image k2-mr-pk3). Quick read vs in-model µs from the c71 ordered prefill sequence (bench/runs/ttx-wb-wb-prod-g2-pk3m-20260927T183939Z.jsonl, 2k chunk): gdn_out in-model 340 µs vs up2d_bf16_a8_11x10 209 µs (×48), gdn_in 533 (AGMM) vs 462 (×48), attn_qkv 522 vs 405 (×16), mlp_down 462 vs 452 (no gain). Estimate ≈ −14 ms per 2k chunk (~3% of ~420 ms), tier 2/3 only: every fp32 full-sync (bit-exact candidate) arm TT_THROWs except mlp_down/attn_wo/gdn_out 11x10, and mlp_gate_up has no working up2d arm. Leaving the arm design to the owning session.

Queue ran the probe (bench/runs/prefill-gemm-probe-20260927T184015Z.jsonl, card 1, image k2-mr-pk3). Quick read vs in-model µs from the c71 ordered prefill sequence (bench/runs/ttx-wb-wb-prod-g2-pk3m-20260927T183939Z.jsonl, 2k chunk): gdn_out in-model 340 µs vs up2d_bf16_a8_11x10 209 µs (×48), gdn_in 533 (AGMM) vs 462 (×48), attn_qkv 522 vs 405 (×16), mlp_down 462 vs 452 (no gain). Estimate ≈ −14 ms per 2k chunk (~3% of ~420 ms), tier 2/3 only: every fp32 full-sync (bit-exact candidate) arm TT_THROWs except mlp_down/attn_wo/gdn_out 11x10, and mlp_gate_up has no working up2d arm. Leaving the arm design to the owning session.
Author
Owner

Owner asked: why bf16 where bf4 would do? Here is what the probe measured (bench/runs/prefill-gemm-probe-20260927T184015Z.jsonl, card 1, standalone, M=2048).

  • Weights are already bf4 and the math is already LoFi (QWEN36_PROJ_LOFI, bundle E, bit-exact).
  • The bf16 that remains is the activation (in0) and the output.
  • Casting in0 to bf4 speeds the matmul up by only 0 to 3.5%: gdn_out 297.7→308.2 TF, attn_qkv 366.4→366.6, gdn_in 373.8→374.2, mlp_down 379.9→400.3 (11x10, bf16 dest). At LoFi the FPU does the same cycles whatever the in0 format, and in0 is multicast, not DRAM-bound.
  • The separate cast costs about +0.12 ms per op, so the net is −30…−50% unless the cast is fused into the producing norm.
  • It is also a real numerics change: PCC 0.9936→0.978 (bf4 in0), or 0.99358 with bf8 in0.
  • Verdict: in0 bf4 cannot clear tier 3's ≥5% bar alone. bf8 in0 fused into the norm output is at most +3% (tier 2/3); it rides along only inside a bf16-dest bundle.

The speed is in the dest mode, grid and blocking, not the in0 dtype.

The '~90% of peak' claim does not reproduce yet. Upstream's 5120x5632x5632 shape ran 755 µs / 430 TF on our card, against upstream's 606 µs / 536 TF. Upstream's test uses torch.ones activations, L1-sharded in0/out and trace. New probe bench/probes/gemm_claim (queued after the SA1 gates) runs upstream's recipe verbatim, then changes one ingredient at a time (ones→randn data, L1→DRAM, in0 bf4/bf8/bf16, fp32 dest), logging AICLK for each arm.

Owner asked: why bf16 where bf4 would do? Here is what the probe measured (bench/runs/prefill-gemm-probe-20260927T184015Z.jsonl, card 1, standalone, M=2048). - Weights are already bf4 and the math is already LoFi (QWEN36_PROJ_LOFI, bundle E, bit-exact). - The bf16 that remains is the activation (in0) and the output. - Casting in0 to bf4 speeds the matmul up by only 0 to 3.5%: gdn_out 297.7→308.2 TF, attn_qkv 366.4→366.6, gdn_in 373.8→374.2, mlp_down 379.9→400.3 (11x10, bf16 dest). At LoFi the FPU does the same cycles whatever the in0 format, and in0 is multicast, not DRAM-bound. - The separate cast costs about +0.12 ms per op, so the net is −30…−50% unless the cast is fused into the producing norm. - It is also a real numerics change: PCC 0.9936→0.978 (bf4 in0), or 0.99358 with bf8 in0. - Verdict: in0 bf4 cannot clear tier 3's ≥5% bar alone. bf8 in0 fused into the norm output is at most +3% (tier 2/3); it rides along only inside a bf16-dest bundle. The speed is in the dest mode, grid and blocking, not the in0 dtype. The '~90% of peak' claim does not reproduce yet. Upstream's 5120x5632x5632 shape ran 755 µs / 430 TF on our card, against upstream's 606 µs / 536 TF. Upstream's test uses **torch.ones** activations, L1-sharded in0/out and trace. New probe bench/probes/gemm_claim (queued after the SA1 gates) runs upstream's recipe verbatim, then changes one ingredient at a time (ones→randn data, L1→DRAM, in0 bf4/bf8/bf16, fp32 dest), logging AICLK for each arm.
Author
Owner

GEMM claim probe, on hardware: 1 card, image k2-mr-pk3m, AICLK 1350 MHz throughout. Record: bench/runs/perf-loop-c78-gemm-claim-verdict-20260927T2120Z.jsonl.

config traced TF notes
upstream exact (bf4 in0, bf4 out, bf16 dest) 514.5 at 5120×5632×5632; 511 at 3840; 490 at 2560 96% of the 536 TF claim, 84.6% of LoFi peak; PCC 0.975 vs fp32
our numerics class (bf16 in0, fp32 dest, bf16 out) 382 at the same shape our in-model prefill matmuls reach 436 TF (prefill-gemm-probe-20260927T184015Z)
  • Upstream's L1-sharded arms hit a CB/L1 clash at 5120 and 3840 on this image. At 2560, L1 and DRAM give the same number.
  • Verdict: the claim is real, but its numerics class is not ours. The gap is fp32 dest plus bf16 in/out, not blocking or grid.
  • FS8, the in-class form, is in the c79 bundle. The out-of-class recipe (bf4 activations and output) needs the activation cast (+0.12 ms per matmul) and a tier-3 gate, so it ranks below FS8 and kda.
GEMM claim probe, on hardware: 1 card, image k2-mr-pk3m, AICLK 1350 MHz throughout. Record: bench/runs/perf-loop-c78-gemm-claim-verdict-20260927T2120Z.jsonl. | config | traced TF | notes | |---|---|---| | upstream exact (bf4 in0, bf4 out, bf16 dest) | **514.5** at 5120×5632×5632; 511 at 3840; 490 at 2560 | 96% of the 536 TF claim, 84.6% of LoFi peak; PCC 0.975 vs fp32 | | our numerics class (bf16 in0, fp32 dest, bf16 out) | **382** at the same shape | our in-model prefill matmuls reach 436 TF (prefill-gemm-probe-20260927T184015Z) | - Upstream's L1-sharded arms hit a CB/L1 clash at 5120 and 3840 on this image. At 2560, L1 and DRAM give the same number. - **Verdict:** the claim is real, but its numerics class is not ours. The gap is fp32 dest plus bf16 in/out, not blocking or grid. - FS8, the in-class form, is in the c79 bundle. The out-of-class recipe (bf4 activations and output) needs the activation cast (+0.12 ms per matmul) and a tier-3 gate, so it ranks below FS8 and kda.
Member

Dead at scope: FS8 engages but prefill matmuls +15% slower (LEVERS row, perf-loop-c79pre-fs8-wb-verdict); 'reopen only with bf4 activations'. The in-class parts shipped anyway (d8k16, NHP). Verified 2026-11-18.

Dead at scope: FS8 engages but prefill matmuls +15% slower (LEVERS row, perf-loop-c79pre-fs8-wb-verdict); 'reopen only with bf4 activations'. The in-class parts shipped anyway (d8k16, NHP). Verified 2026-11-18.
Author
Owner

agent-gateway closeout (closed): cleared agent:* labels.
Hermes kanban card (if any) is left for Hermes to archive/complete.

agent-gateway closeout (closed): cleared `agent:*` labels. Hermes kanban card (if any) is left for Hermes to archive/complete.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitpartner/tt-stack#109
No description provided.