Skip to content

Collapse the bf16 compute copies into the masters (follow-up to #57) #58

Closed

Description

@feitreim

Collapse the bf16 compute copies into the masters (follow-up to bf16 masters)

Blocked on #57. Once master dtype == compute dtype, the duplicated weight storage stops paying for itself: every aligned parameter today carries normal + transposed packed-bf16 copies beside the master (Bf16LinearWeights gpu/model/src/lib.rs:427-433, StackedBf16Weights, GpuBf16Head.w/w_t), ~7.9 GiB each across the ~4.23B copy-bearing params.

Step 1 — master becomes the normal copy (~7.9 GiB)

Store the bf16 master packed (DeviceBuffer<u32> pair layout, same as today's copies) and bind the forward/backward TMA maps to it directly. The sync_from_master quantize launches (Bf16LinearWeights::sync_from_master :476-499, StackedBf16Weights::sync_from_master :1048-1068, GpuBf16Head::sync_transposed :2276-2291) and their optimizer-refresh call sites (update_profiled :2705-2713, :2723-2733) disappear — the fused AdamW write-back already updated the bytes the GEMMs read.

Constraint to respect: the TMA maps are created once against fixed device addresses and must never be reallocated (SAFETY comments at :462-464, :2131-2132) — the packed master must be allocated with the same lifetime discipline as today's copies.

Step 2 — drop the transposed copies via descriptor transpose (~7.9 GiB more, evaluate)

#53 proved the tcgen05 transpose_a/transpose_b descriptor route on B200 and landed it for the weight-grad GEMMs (gemm_tcgen05_bf16_optimized transposed=1; geometry: two stacked 64-wide SWIZZLE_128B subtiles, LBO=8192, SBO=1024). The remaining consumers of transposed weight copies are the backward-input GEMMs (dx = dy·Wᵀ). If those flip to reading the normal layout through the descriptor bits, the transposed buffers and their refresh launches go too.

Caveat from #53's measurements: the descriptor route was timing-neutral on DRAM-bound weight-grad spans, but dx GEMMs have different dataflow — A/B this on the model profile before committing; if it regresses, keep the transposed copies (step 1 stands alone).

Accounting

today after step 1 after step 2
bytes/param (copy-bearing) 4 (master) + 2 + 2 2 + 2 2

Combined with the masters issue this is the difference between ~14 GiB and ~30 GiB of free headroom at the canonical config — direct runway for B or C growth. Also removes the optimizer.sync_compute spans from the step entirely.

Rough size: net-negative diff, a few hundred lines deleted against ~100-200 added (TMA plumbing, packed-master accessors).

Activity

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

    @feitreim
    OwnerAuthor

    Landed on main. Step 1 shipped: the packed bf16 master IS the untransposed compute operand — TMA descriptors bind the master's own words; Bf16LinearWeights::normal / StackedBf16Weights::normal / GpuBf16Head::w deleted (2 B × 4.23B copy-bearing params = 7.9 GiB), the copy half of every sync_compute span gone. Checkpoint resume refills masters IN PLACE (read_master_into / GpuBf16Tensor::load_f32_host, decision #25) since replacing the tensor would free the address every TMA map points at. Measured vs 4471225: VRAM 145.7 → 137.8 GiB (headroom 40.5 GiB), step 575.6 → 572.1 ms, experts.sync_compute 7.05 → 4.77 ms. All 14 gates green incl. v5 bit-identical resume.

    Step 2 (drop the transposed copies): implemented, PROVEN at the GEMM level, and reverted. Correction to this issue's premise: the transposed copies feed the FORWARD GEMMs, not dx — dx already reads the master K-major. The conversion needed independent transpose_a/transpose_b bits (built: two-bit mask, per-operand stage walk), and the mixed-mode GEMM is bit-identical to a materialized transpose at three shapes. What killed it: the 1200-step aligned-MoE overfit gate reproducibly (bit-for-bit across reruns, so not the documented flake) lands at 0.0515 vs <0.05, while step 1 reaches 0.00006 — the GEMM being bit-identical means the trajectory shift enters through launch-order-sensitive atomics near the bf16 plateau. A reproducible red gate isn't shippable. Remaining on the table: 7.9 GiB + 5.74 ms of sync spans; SPEC §13.9 records the proven route and the real open question — is that gate measuring convergence or launch-order luck?

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