Skip to content

Precision audit: bf16 activation & gradient buffers where accumulation allows #59

Closed

Description

@feitreim

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)

Prime candidates (largest first)

  1. 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 at 4·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.
  2. Expert gradient bins — GpuExpertScratch.d_* (:1793-1801): d_bin_output is written once by moe_scatter_dy and read by weight-grad GEMMs that quantize it to bf16 staging; same single-writer/single-reader test applies.
  3. 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.

Activity

  1. added
    enhancement
    on Jul 25, 2026
  2. feitreim commented on Jul 26, 2026

    @feitreim
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions