Repository navigation
The router weight gradient's loads share a basic block, and 64 partitions buy what 256 did - #111
Merged
Merged
Conversation
…ions buy what 256 did `backward.router.weight` was 5.9083 ms of a 316.9499 ms step, reading 144 MiB per layer at 292 GB/s — a tenth of what `rms_norm_backward_weight_fast` achieves beside it on three times the bytes. The PTX says why: every load in the token walk sits in a basic block of its own, fenced by a slice bounds check and by the `expert < e` guard on the gate row, so a warp never has more than one in flight and the kernel is pure latency. The shape is now checked once up front and the walk indexes unchecked, `ROUTER_WGRAD_TOKENS` loads are issued before any of them is multiplied, and a lane owns both halves of one packed word instead of four strided rows, so a warp's load is a full 128-byte sector rather than half of one. 5.9083 ms -> 3.1397. That makes the partition count worth only what it buys. Memory parallelism is `D * SPLITS * TOKENS` loads in flight, which is already past memory rate at 64 partitions; 256 of them bought nothing and cost four times the `[SPLITS, E, D]` partial buffer — 25.2 MiB down to 6.3, and the merge that reads it back 0.8352 ms down to 0.2445. Issue #107's A4 asked for the partial buffer to go entirely, as one accumulating GEMM. It cannot: a `[D, E]` output is 8 columns against a `TC_N_TILE` of 256, so the tcgen05 path would pad 32x and run 12 clusters of the device's 74 against a `dlogits` the router deliberately keeps fp32, and folding the partitions in directly needs atomics — which the byte-identical checkpoint-resume gate in `gpu/model`'s parity binary rejects (measured: every numerical gate passed, that one did not). The fixed ascending-partition order stays, and the item's traffic is bought by shrinking the buffer instead.
feitreim
force-pushed
the
fuse-router-dweight-gemm
branch
from
August 6, 2026 17:26
fe36478 to
7597b2f
Compare
This was referenced Aug 6, 2026
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.
Issue #107 item A4, and an account of why the rest of A4 is not reachable.
What A4 asked for, and what measuring it first found
A4 priced
router_backward_weight_split+router_backward_weight_mergeat0.59 GiB/step and 12 launches — the
[SPLITS, E, D]partial buffer writtenby one and read straight back by the other — and proposed replacing the pair
with one accumulating GEMM against the MN-major view of
ffn_normalized.Measuring the pair first (
./run.sh model profile, B=12, at dc6f533) foundsomething the shape arithmetic could not:
backward.router.weightbackward.router.weight_merge5.9083 ms to read 144 MiB per layer is 292 GB/s.
rms_norm_backward_weight_fastsits three rows below it doing the same kind of work over three times the bytes
(
backward.ffn_norm.weight, 2.2156 ms) at about 2.4 TB/s. The PTX says why:in the token walk every load sits in a basic block of its own, fenced by a
slice bounds check and by the
expert < eguard on the gate row, so a warp neverhas more than one load in flight and the kernel is pure memory latency.
The change
gpu/ops/src/lib.rsand the parity call ingpu/ops/src/main.rs.gpu/modelis untouched — the partial buffer's declared shape follows
ROUTER_WGRAD_SPLITS, so it resizes on its own.so the bounds-check traps leave the loop.
ROUTER_WGRAD_TOKENS = 8loads are issued before any is multiplied. Thetoken loop's trip count is a runtime value NVVM will not unroll, which is the
same fact
MOE_PROBABILITY_SUMS_THREADSalready records for#99.ROUTER_WGRAD_ROWS4 → 2)instead of four strided rows, so a warp's load is a full 128-byte sector
rather than half of one.
so nothing re-enters the loop's control flow.
That makes the partition count worth only what it buys. Memory parallelism is
D * SPLITS * TOKENSloads in flight, already past memory rate at 64, soROUTER_WGRAD_SPLITSdrops 256 → 64. This is A4's traffic, bought adifferent way: the partial buffer goes 25.2 MiB → 6.3 MiB and the merge
reads a quarter as much.
Why A4's single accumulating GEMM is not reachable
Two independent blockers, both measured or structural rather than assumed.
1. The tcgen05 path cannot take this output.
dweightis[D, E]= 3072 x8 columns against a
TC_N_TILEof 256;tcgen05_launch_configassertsn % TC_N_TILE == 0. The GEMM would have to paddlogitsto 256 columns — 32xthe FLOPs, on 12 clusters of the device's 74 — and it would need
dlogitsquantized to bf16, which is exactly the fp32 the router is deliberately kept in
(SPEC §7.1).
2. Folding the partitions in directly needs atomics, and a gate here forbids
them. I implemented that version — one relaxed
atomicAddper output apartition owns, the shape
rms_norm_backward_weight_fastalready uses for everynorm gradient in the model — and ran the gates. Every numerical check passed:
./run.sh ops, the CPU-referenceMoE block{n} router.dwcheck, the MoEoverfits. The byte-identical checkpoint-resume gate did not
(
gpu/model/src/main.rs:1526, "checkpoint resume changed the continuedtrajectory"). The norm gradients get away with atomics because at that binary's
shape their grid.y is 1 and there is no contention; 64 partitions per router
output is real contention. So the fixed ascending-partition order stays, and A4
is delivered as a smaller buffer rather than no buffer.
Fidelity
No tolerance touched, no gate weakened, no assertion removed.
./run.sh ops— green (✓ ops forward/backward parity checks passed),including
split MoE router weight gradient must be bit-identical across launchesand the 2e-6/2e-6 comparison against the serial GPU oracle../run.sh model— green, all 14 checks, includingcheckpoint v5 (bf16 masters) resumes bit-identically.Numbers
Per span —
./run.sh model profile, B=12, quiet B200 containersbackward.router.weightbackward.router.weight_mergebackward.experts.gate_up_weight_gemm(control)backward.ffn_norm.weight(control)Different containers, so the full-step column is not the claim. Summed over the
68 spans that are not the router pair the two runs differ by +2.02%, and
the pair's −50% is an order of magnitude outside that drift while both control
spans sit inside it. A same-container
BASELINE_REF=dc6f533 ./run.sh model profileagrees on direction (pair 5.9799 → 4.1375) but landed on a containerwhose GEMMs were running 5x slow under concurrent load, so it is corroboration
rather than the number.
Registers —
ptxas -v,sm_100arouter_backward_weight_split_bf16router_backward_weight_split(fp32 twin)router_backward_weight_merge0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loadson both sides.At 256 threads a block, 72 → 32 registers is 3 blocks/SM → 8: those are the warps
that hide the loads, and they are half the win. (
ncucannot initialize itscounter library on this driver — "Failed to initialize the profiler:
LibraryNotLoaded" — so this comes from
ptxas -v, likecompute-sanitizerbeing unavailable on B200.)
Throughput —
bin/train.rs, B=16, 30 steps, both arms in one containerCaveat, stated plainly: that container was badly contended — five agents were
holding B200s — and 33.2k tok/s is far under the ~78,300 this machine gives when
it has the GPU to itself. Both arms ran back to back inside it, and +1.39% is the
right order for a 3.36 ms saving against a 316.95 ms step (1.06%), but it wants
re-taking on a quiet pool before it is quoted anywhere.
One ablation worth keeping
The staged token values land in a
.localdepot, because the multiply loop thatreads them stays rolled. Folding the depot away with
#[unroll]— 128straight-line FMAs, no depot at all — measured 4.3205 ms against 3.1397 over
the step's twelve launches. The depot is L1-resident, and the registers it saves
are what keep the warps. It is recorded on
ROUTER_WGRAD_TOKENSso the nextperson does not have to spend the run.
Interaction with the concurrent RMSNorm work
The RMSNorm PR (#107 A1/A2/A5) changes where
ffn_normalizedcomes from — itrecomputes it in the backward instead of loading a saved copy — at the same
buffer and descriptor interface. This PR consumes it through that interface
unchanged and does not touch
gpu/model/src/lib.rsat all, so the two shouldcompose without a conflict.