Repository navigation
MoE binning walks in vectors, and the SwiGLU tile arm loses on transaction shape - #128
Merged
Merged
Conversation
…ction shape
**Item 1.** `moe_bin_assign_parallel`'s contract was never the thing holding it
back. Capacity slots are first-come-first-served in flattened `(token, rank)`
order — routing semantics, not numerics, since the order decides *which* tokens
the capacity drops — but that order is a prefix sum, and a prefix sum has as
much parallelism as its memory system will give it. The kernel had none: `E`
blocks is 2048 threads on 148 SMs and a scalar walk at a runtime trip count is
four bytes a lane, so the entire launch had 8 KiB in flight. It now walks
`QUAD_LANES` vectors, `MOE_ASSIGN_FLIGHT` of them at once, and scans with warp
shuffles behind one barrier where a 256-lane Hillis-Steele tree needed sixteen.
Bit-identical slots and counts, gated against the serial oracle.
`moe_bin_assign_atomic` is the full relaxation — one atomic per pair,
first-arrival order — measured as the ceiling and **not launched by anything**.
**Item 2.** The gate is loosened, the conversion still loses, and the kernel is
unchanged. `swiglu_{forward,backward}_interleaved_tile` and the toleranced
`check_swiglu_interleaved_tile` that gates them are in the tree because what
they establish is the result: reaching `exp2_approx` on this family means
reaching it through a `RegTile`, and a `RegTile` costs more here than the
transcendental saves. The one thing that did land is #125's own open lead — the
row split's two runtime divisions are 32-bit now, at no register cost.
feitreim
force-pushed
the
ops-kittens-pass4-moe-swiglu
branch
from
August 7, 2026 03:28
f11c1a9 to
d03422d
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.
Two approved items in
gpu/ops, on #124/#125's method. Item 1 ships and isbit-identical; item 2's gate is loosened, its conversion still loses, and its
kernel is unchanged. Both verdicts are measurements, and item 2's is the one
worth reading: it is the third independent time this campaign has bought bytes
in flight and been refused.
Baseline is
3392830(this branch's merge-base, ferro3ae07a84). B200,B=12 T=2048 D=3072 FF=4096 E=8 K=2 C=6144 L=12.Item 1 — how much parallelism relaxing determinism unlocks: 1.66x, and it is not worth taking
moe_bin_assign_parallelwas 0.830 ms at ~26 GB/s on a grid ofE = 8blocks (1.026 ms in the profile this campaign started from; same kernel, and the
same-container pair below is what the delta is taken against), and the reason
given for the grid was its deterministic-ordering contract.
The contract was never the thing holding it back. Capacity slots are
first-come-first-served in flattened
(token, rank)order, and that is routingsemantics and not numerics — the order slots are handed out in decides which
tokens the capacity drops, so relaxing it moves the loss curve. But it is also,
exactly, a prefix sum, and a prefix sum has as much parallelism as its memory
system will give it. This kernel had none of it, for a reason that has nothing
to do with ordering:
Eblocks is 2048 threads on 148 SMs, so there are no other warps to hidea load behind. What a lane has outstanding is the launch's bandwidth.
lane, 8 KiB in flight for the whole launch. That is the tens of GB/s it
measured, arithmetically.
a launch with nothing to overlap them with.
(#99's "this reduction's only parallelism is its token-loop depth" is about
moe_aux_terms, the neighbour — checked, and it does not transfer: that kernelhas no scan formulation to dodge with.)
(a) The deterministic route — what ships
QUAD_LANESvector loads,MOE_ASSIGN_FLIGHT = 4of them in flight per lane(64 bytes a thread, sixteen times fewer round trips), and a warp-shuffle scan
plus an eight-slot warp-total sum — one barrier where there were sixteen, and
8 shared words where there were 256. Lane ranges are rounded up to whole vectors
so
startisQUAD_LANES-aligned and the walk needs no per-lane head; they staycontiguous, which is all the ordering asks of them.
Bit-identical.
check_moe_bin_assigngates the slots and counts against theserial
moe_bin_assignoracle at 5000 pairs — a shape whose lane ranges are 20pairs, so one whole vector group and a four-pair tail, with a capacity that
four experts fit and the fifth overflows.
check_moe_routing's six-token shapenever reached the vector walk at all.
(b) The full relaxation — measured, and not shipped
moe_bin_assign_atomic:pairs / 256blocks, one thread a pair, one atomicincrement on its expert's counter, first-arrival order. It is the maximally
parallel formulation and it changes which tokens drop, so it breaks
bit-identical resume and needs your explicit sign-off to ship. It is in the tree
as the ceiling, launched by nothing.
The table
bin/bench, 49152 pairs (192 KiB — this launch can never be bandwidth-bound,only latency-bound), same container:
Composed,
BASELINE_REF=origin/main ./run.sh model profile— both arms builtand run back to back in one container:
mainforward.router.assignforward.experts.swiglubackward.experts.swigluA second, earlier pair on the same branch agrees:
backward.experts.swiglu−2.4%, full step −0.39%. The full step is not a claim — the three spans
above account for 0.76 ms of the 2.86 ms it moved, and #124's lesson is that
untouched spans drift further than that on their own.
Verdict: relaxing the contract unlocks 1.66x on a launch that is now 0.02 ms.
Against the deterministic kernel's own 0.357 ms/step that is
0.14 ms/step, or 0.02% of the step, left on the table, for a routing change, a moved loss
curve, and a checkpoint that no longer resumes bit-identically. The parallelism
was never behind the contract; it was behind four bytes a lane.
Item 2 — swiglu to
exp2_approx: gate loosened, conversion loses, kernel unchangedThe old blocker was real:
check_swiglu_interleavedcompares bit-exactly againstlibdevice
expf, and aRegTile'sexpis kittens'Exp—exp2_approx, aclamped degree-3 minimax. The gate is now loosened, and the answer that comes
out the other side is that it did not matter, because the tile is the only way
to reach
exp2_approxon this family and the tile costs more than thetranscendental saves.
The tolerance, derived rather than picked
rtol = 4.0e-3,atol = 2e-5, oncheck_swiglu_interleaved_tile. Both areswept, not guessed —
exp2_approxagainstf64over the whole ±125 range itsclamp admits:
sigmoid(g)silu(g)silu'(g)rtol=2^-8 + 1e-4= 4.0e-3. The1e-4is the transcendental — andnote the sigmoid attenuates
exp2_approx's own 7.5e-5 bound rather thanamplifying it, since
σ_approx ≈ σ·(1 − δ(1−σ)). The2^-8 = 3.9e-3is halfan ulp of a bf16 whose mantissa can be 1.0, and it dominates by fifty
times: these kernels round on the way out, so that is the floor any
comparison against an fp32 oracle has here, tile or not.
atol= 2e-5 is the one that matters.silu'has a zero atg = −1.2785where no relative tolerance is finite; 1.9e-5 is the 7.7e-5 times
max σ(1−σ) = ¼, and it also covers the far tail where the ±125 clamp makesexp2_approxdisagree withexpfby any factor at all on numbers of order1e-38. The gate's range is ±8, not the panel's ±1, so the zero and the tail
are both live in it.
Not 3e-2. Seven and a half times tighter, and every digit is accounted for.
The access pattern, computed before the run
The scalar kernel's accesses are already the ideal shape: two 8-byte loads and
one 8-byte store a thread, a warp's 32 lanes covering one contiguous 256-byte run
with every sector used. A
[16, 32]BaseLdtmtile gives a lane 16 elements ofeach operand instead of 4 — 64 bytes in flight a thread rather than 16 — and
what it costs is the transaction shape: a
BaseLdtmquad is 8 contiguous bf16(16 bytes) and the next quad is a different row, so one access instruction
touches 8 rows and uses half of each 32-byte sector. The other half is the next
value pair of the same row, so the DRAM traffic is unchanged and only the L1
request count doubles — ferro-kittens#222's pole. Four times the bytes
outstanding against twice the requests was the trade.
The requests won
bin/bench,24576 x 4096, same container:swiglu_forward_interleaved_packedswiglu_backward_interleaved_packed#70's stale 0.70x was the split-layout bf16 forward, and re-measured here on
ferro #180's unrolled mover walks the interleaved pair is worse, not better. The
forward's 1.63x slowdown against a predicted 2x request count is the right order
and a slight overshoot — which is what it should be if the requests are most of
the cost and not all of it.
The tile kernels and their toleranced gate stay in the tree, launched by
nothing, on
moe_bin_assign_atomic's footing: what they establish is theresult, and the next reader should not have to rediscover it.
The third measurement, and what it found
If bytes in flight were the limit, coarsening the scalar walk should have won
where the tile lost — same ideal access shape, four of them outstanding. It
loses too:
usizedivisions[16, 32]BaseLdtmregister tilesThree shapes, two of them buying bytes in flight fourfold, both refused. The
kernel was never waiting on memory-level parallelism — which is also, directly,
why a cheaper
expwas never going to move it.What is left is fixed per-thread cost, and the backward beside it is the
evidence: same walk, same row split, twice the bytes an element, 5775 GB/s.
Halving the index math per byte is the only difference. So the one thing that
landed is #125's own open lead, verbatim — the row split's two runtime divisions
by
ff / QUAD_LANESare 32-bit now, "about a third of the instructions at noregister cost at all". Same container, that is −2.6% and −3.4% on the two
expert-SwiGLU spans, 0.29 ms/step, and both kernels keep their bit-exact gates
because the math is untouched.
Loss tracking: not run, and why
#108's protocol is for a change to the forward math. There is no change to the
forward math in this PR. The tile arm that would have carried
exp2_approxinto the model is not launched, and the shipped kernels' sigmoid is the same
libdevice
expfit was — which their unchanged bit-exact gates prove morestrongly than a few hundred steps against a 0.077 noise floor could.
Registers
moe_bin_assign_parallelswiglu_forward_interleaved_packedswiglu_backward_interleaved_packedThe binning kernel's 40 registers are the
MOE_ASSIGN_GROUParray live acrossthe walk, and they cost it two resident blocks — which on a grid of
E = 8blocks over 148 SMs costs nothing at all. No spills anywhere.
Gates
./run.sh opsgreen, including the two new ones:check_moe_bin_assign(bit-identical slots and counts against the serial oracle; relaxed kernel checked
for the counts and the slot-set it still promises, and deliberately not for the
order it gave up) and
check_swiglu_interleaved_tile(the toleranced one).compare_trainis unhealthy, so nothing here is a composed-step claim beyond thesame-container profile pair above.