Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Precision audit: bf16 activation & gradient buffers where accumulation allows
Independent of the master-weights work (shares the review, not the code). The activation/scratch pool scales ~6.5 GiB per 2048 tokens of batch, and most of it is fp32 that exists only to feed or drain bf16 tcgen05 GEMMs. Audit each buffer against one question: is anything accumulated or compared here, or is it pure storage between kernels? Pure storage can be bf16; accumulation stays fp32.
Non-negotiable fp32 (the "numerically necessary" list, all standing decisions)
- tcgen05 epilogue store/accumulate (decision Optimize RMSNorm with block-parallel kernels #20) and every GEMM accumulator
- Router buffers end-to-end:
router_logits,dlogits,router_dx,router_dweight_partials,gate_gradients(decision Implement Muon CPU reference optimizer #22, re-affirmed by Router fp32 kernels run ~30x off bandwidth-bound at D=3072 #44/perf: retile router fp32 kernels for D=3072 (#44) #52 determinism constraints) - Softmax / cross-entropy internals, RMSNorm reduction accumulation
d_model_0..4residual-stream gradient: it accumulates across the reverse block loop (resident inscratch.d_model_1) — bf16 would lose low-order bits L times- Embedding/norm
dw(device-atomic accumulation)
Prime candidates (largest first)
- Expert bins double-storage —
GpuExpertActs(bin_input,gate,up,activated,bin_output, all fp32,gpu/model/src/lib.rs:1763-1769) plus separate packed-bf16 staging: the scratch doc (:1786-1791) prices it at4·E·C·(2D+7FF)fp32 bytes +6·E·C·max(D,FF,2FF)bf16 bytes. Where a buffer is quantized to bf16 staging anyway before the GEMM consumes it, storing it fp32 first is pure overhead — store once in bf16 and delete the quantize launch (same pattern as the scatter_dy phase 2: vectorized row copy + fold zero_dy_bins #55/Weight-gradient GEMMs phase 2: MN-major operands via tcgen05 descriptor transpose #53 deletions). Watch the two real consumers that want fp32: the SwiGLU backward pointwise math and the scatter/gather+=paths. - Expert gradient bins —
GpuExpertScratch.d_*(:1793-1801):d_bin_outputis written once bymoe_scatter_dyand read by weight-grad GEMMs that quantize it to bf16 staging; same single-writer/single-reader test applies. - Linear/expert staging quantize pairs left after Weight-gradient GEMMs phase 2: MN-major operands via tcgen05 descriptor transpose #53 (
GpuLinear::forward_into:675, backward:720/:726, grouped:825/:881/:887, experts:1213/:1318/:1324): each is evidence the fp32 buffer feeding it is a bf16 candidate.
Ground rules
- One buffer at a time, parity-gated; the overfit gates (rerun-once discipline for the known atomics flake) are the accept/reject signal, tolerances only loosened where a dtype change genuinely forces it, documented per buffer.
- Measure with
BASELINE_REF run.sh model profile: VRAM plus the quantize-span deltas (deleted launches are step-time wins, as in Weight-gradient GEMMs phase 2: MN-major operands via tcgen05 descriptor transpose #53's lm-head transposes going to zero). - Anything rejected gets a one-line note in SPEC §7 so it isn't re-attempted blind.
Rough size: incremental, ~50-150 lines per converted buffer; the survey table in SPEC is the first deliverable.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
docs: SPEC 7.1 activation/gradient precision audit table (#59)
perf(#59): store expert `activated` panel as packed bf16
perf(#59): store expert `bin_input` panel as packed bf16
perf(#59): store expert `d_gate_up` panel as packed bf16
perf(#59): store expert `d_bin_output` panel as packed bf16
perf(#59): delete the expert bf16 operand staging
docs: SPEC 7.1 + 13.9 measured results for the expert bf16 panels (#59)
docs: SPEC 7.1/13.9 use the measured back-to-back profile pass (#59)
Merge branch 'perf/issue-59-precision-audit': bf16 expert panels, -10…
Merge branch 'main' into feat/issue-57-bf16-masters: bf16 masters + b…
Merge branch 'feat/issue-57-bf16-masters': bf16 master weights + #59 …
feitreim commentedon Jul 26, 2026
Landed on main (31e1a9c, merge 8f81ad9). The survey (SPEC §7.1) classified every fp32 activation/gradient buffer by one test — accumulated/compared vs pure storage between kernels. Converted to packed bf16: expert 'activated' [E,C,FF], 'bin_input' [E,C,D], 'd_gate_up', 'd_bin_output', plus deletion of the expert bf16 operand staging entirely (no expert GEMM stages an operand any more). Six quantize launches gone. Kept fp32 with recorded reasons: gate/up (SwiGLU reads 3×), tcgen05 epilogue targets (decision #20), d_gate/d_up (double-rounding), residual-stream d_model_* (accumulates across the reverse loop), everything router (decision #22), norm reductions. Zero rejections, zero tolerance changes; router gradients bit-identical (gate dot still fp32 in the same lane order). Measured: VRAM 164.3 → 153.9 GiB (−10.4), step 603 → 563 ms (−6.6%) — the wins surface inside the GEMM spans since the deleted quantizes ran there (gate_up_weight_gemm 53.6 → 43.7 ms), which also sharpens #53's conclusion: those spans are operand-DRAM-bound. Deferred with evidence into SPEC: the ~20 GiB attention-side candidates (q/k/v, attended, attention_normalized) share scratch with the lm-head and flash backward and need their own pass. New kernels: swiglu_forward_bf16, moe_scatter_bf16, join_group2_bf16, moe_scatter_dy_bf16, moe_zero_dead_bins_bf16.
Merge branch 'main' into chore/issue-56-cuda-oxide-b099f64