Repository navigation
The expert bins are bf16, and the packed GEMM stores one where it lies - #110
Merged
Merged
Conversation
`gate_up` (`[E, C, 2, FF]`) and `bin_output` (`[E, C, D]`) were the two largest fp32 saved activations a block still owned — 2.75 GiB a block, 16.5 GiB at B=16, more than #108 saved in total. They stayed fp32 for one reason: both are written by an expert GEMM's `f32_store_at`, and the packed-bf16 entry point had no offset store to write one bin of a stacked allocation with. `launch_tcgen05` took no output offset and derived `m` from `output.len()`. So the packed kernel now carries the `c_offset` its fp32 twin already did. It moves the base pointer once, before the item loop, so nothing in the drain carries it and the epilogue is the same instruction stream it was. `Tcgen05Gemm::store_at` is the host form, taking the offset and element count in packed *elements* so both arms of a dtype dispatch pass the same two numbers. The bins themselves become `ExpertBins` — packed where the experts are tcgen05-aligned, wide on the oracle path. Unlike `ExpertPanel` it carries no descriptors: neither buffer is ever a GEMM operand, only an epilogue target and a pointwise kernel's input. Every reader follows the dtype: - `swiglu_forward_interleaved_packed` / `_backward_interleaved_packed` read the gate/up panel packed (two 8-byte loads where there were two 16-byte ones). Panel and bins share one alignment gate, so the packed and wide halves are the only pairings. - `moe_gather_combine_add_quad_packed` reads the bins packed. Packed bins only exist at tcgen05-aligned shapes, which puts D on TC_N_TILE and so on QUAD_LANES — there is no word-wise twin because no shape reaches one. - `moe_scatter_dy_packed` replaces `moe_scatter_dy_bf16`, whose fp32 `expert_output` had no caller left once the saved output was packed. Accumulation is untouched: the GEMM still accumulates in fp32 TMEM, the SwiGLU still computes in fp32 registers, and the gate dot product still sums in fp32. Only the stores round.
feitreim
force-pushed
the
bf16-expert-buffers
branch
from
August 6, 2026 18:46
bfecd61 to
1e455df
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GpuExpertActs::gate_up(fp32[E, C, 2, FF]) andbin_output(fp32[E, C, D]) were the two largest fp32 saved activations left after #108 —16.5 GiB at B=16. Both are written by an expert GEMM's epilogue, and the
packed GEMM had no way to write one bin of a stacked allocation, so they were
blocked rather than skipped.
Rebased onto main after today's six-PR campaign (now
14e5d18). #112landed the batched expert GEMM in the meantime and changes what this PR needs;
the composition is described below and is the one the two PRs pre-negotiated.
The store form, after #112
#112 made the expert the tcgen05 kernel's outermost item axis: one launch
covers all
EGEMMs,a_map/b_mapareexpertsdescriptors, andC'sper-expert band is
tiles_mtile-rows down — derived on device byTileState::origin, not passed.That dissolves the original form of this PR. The first version added a
host-side
c_offsetto the packed kernel plus astore_atentry point, so anE-iteration host loop could aim the epilogue at one bin. Under #112 there isno host loop and nothing to aim: a batched launch writes the whole stack.
So the packed kernel gets the one parameter its fp32 twin already has —
— and one host entry point,
store_batched, built exactly likef32_store_batched. Noc_offset, nostore_at, nooutput_offsetplumbing: every packed caller writes its whole allocation, so an offset
parameter could only ever be zero.
The epilogue itself is unchanged. Batching and store width are independent
— the expert reaches the epilogue only through the row
originderives — whichis why a bin panel that is bf16 and batched needs no new epilogue, only the
entry point.
expert_linear_forwardis one launch whoseCthe bins' dtypepicks:
The buffers
gate_upandbin_outputbecomeExpertBins—Packedwhere the experts aretcgen05-aligned,
Wideon the non-aligned oracle path. UnlikeExpertPanelitcarries no descriptors: neither buffer is ever a GEMM operand, only an
epilogue target and a pointwise kernel's input.
Panel and bins share one alignment gate, so "both packed" and "both wide" are
the only reachable pairings and each match arm says so:
swiglu_forward_interleaved_packed/swiglu_backward_interleaved_packedread the gate/up panel packed, replacing the
_bf16forms — oncegate_upis packed, an fp32-in/packed-out SwiGLU has no caller.
moe_gather_combine_add_quad_packedreads the bins packed. A packed binpanel exists only at tcgen05-aligned shapes, which puts
DonTC_N_TILEand therefore on
QUAD_LANES, so no shape can reach a word-wise packed twin.moe_scatter_dy_packedreplacesmoe_scatter_dy_bf16.Net kernel count: +1. Accumulation is untouched: the GEMM still accumulates
in fp32 TMEM, SwiGLU still computes in fp32 registers, and the gate-gradient
dot still sums in fp32. Only the stores round.
expert_linear_backwardneeded no change — its outputs (weight_gradient,d_bin_input) are fp32 decision-#20 epilogue targets that this PR nevertouched.
Registers and occupancy
--kernel gemmon a B200, against main measured in the same session:gemm_tcgen05_bf16_optimizedgemm_tcgen05_f32_optimizedgemm_tcgen05_f32_accumulateThe packed kernel comes out two registers cheaper than main, and the pin is
ratcheted down to the measured 132 rather than left slack — no budget was
loosened. The original version of this PR reported 134/134/0; dropping the
c_offsetthe batched form made unnecessary is what moved it.Occupancy is unmoved and was never close.
CTAS_PER_SMis 1, set by sharedmemory and tensor memory, not registers.
Memory —
bin/train.rs, B200,sweep_batch12/16/20The accounting closes to 0.01 GiB against
12 blocks × ½ × (E·C·2FF + E·C·D) × 4 B, on the new main, at three independent batch sizes.Both slopes are exactly linear across all three points, and the plane agrees to
0.02 GiB — parameters and optimizer state are untouched, and the fit says so.
Ceiling is
⌊(178.35 − plane) / slope⌋, computed from the slope, not verifiedwith an OOM probe. The whole curve sits one batch higher than the original
measurement (24 → 32 became 25 → 33) because the campaign's other PRs trimmed
main's slope from 4.55 to 4.42; the +8 step is this PR's.
Throughput —
train_ab, same container, B=16, 30 steps, 2 roundsmain+1.27%, MFU +0.50 pt. Three to six times the within-arm spread, so the
effect is real, but it is smaller than the +1.91% the original version
measured against the pre-campaign main — and that is the expected direction.
This PR buys throughput by halving the bytes three touches a step move; #112's
batching and #113/#114's fusions already removed part of the pressure those
touches were creating, so the same bytes saved are worth less on top of them.
The memory saving, which is structural rather than a traffic effect, is
unchanged to the 0.01 GiB.
Fidelity
No tolerance touched, no gate weakened.
--kernel model: all 15 gates green at the existing tolerances(
BF16_ATOL = 3e-3,BF16_RTOL = 3e-2), including both substituted-MoEgates, the aligned expert forward/backward gate, the byte-identical
checkpoint resume, and the convergence gates (aligned MoE overfit
2.949841 → 0.000050; block linears 3.105546 → 0.000075).
--kernel gemm: store/accumulate parity green, budgets green against thetightened pin.
--kernel ops: all 13 green, including the two gates this PR extends —check_swiglu_interleavedfeeds the packed arms a packed panel with gate andup pre-rounded so the comparison stays exact, and
check_moe_scatter_dy_rowsgains a packed arm asserting the bin gradient isthe wide result rounded bit-for-bit.
Caveat carried forward
The original 300-step loss-tracking study against a same-seed control still
stands as the evidence that this tracks: mean Δ +0.007 against the control's
+0.021 and a balanced 32/29 sign split, but a wider max excursion (0.288 vs
0.174) and a +1.75% endpoint offset against a +0.70% floor. The trainer is not
bitwise reproducible, so two runs of main at the same seed differ. That study
was not re-run on the new main. If a longer run shows drift, the first
thing to put back in fp32 is
gate_up— the larger buffer, and the one whoserounding lands before a nonlinearity rather than after a linear map.