Repository navigation
The E=8 expert loop leaves the host: one batched tcgen05 launch a GEMM (#107 A9) - #112
Merged
Merged
Conversation
…pert GEMM `expert_linear_forward` and `expert_linear_backward` dispatched E=8 identically shaped GEMMs from a host loop — 16 forward and 32 backward launches a layer, 576 a step, 48% of the trainer's launch count, and all eight inside one `profiler.measure` span so the profile never showed them. PyTorch issues the same work as one `bmm` apiece. The expert becomes the kernel's outermost item axis. Descriptors move from one allocation each into one allocation of `experts` descriptors (`Bf16PairsTmaMaps`), which is all the kernel needs to reach expert `e`'s operands: their base addresses and row strides were already in the descriptors, so an item's tile coordinates, its operand walk and its `C` band are a single GEMM's, unshifted. The only geometry that differs is `C`, one allocation holding every expert's matrix, where the expert is `tiles_m` tile-rows down — derived rather than passed, so `experts` is the single new kernel parameter. What that buys is the tail, not the launches. The grid is capped at MAX_CLUSTERS either way, so batching does not widen a launch that already filled the device; what it removes is the quantization at the end of one. Six of the eight expert GEMM shapes ran 192 or 384 tiles over 74 clusters — 86.5% last-wave efficiency — and eight experts' worth of the same tiles is 98.8%.
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.
Closes item A9 of #107.
What was there
expert_linear_forwardandexpert_linear_backwarddispatchedE = 8identically shaped tcgen05 GEMMs from a host loop — 16 forward and 32
backward launches a layer, 576 a step, 48% of the trainer's 1206 — and all
eight sat inside one
profiler.measurespan, so the profile never showed them.Inductor issues the same work as one
bmmapiece (2 forward, 4 backward alayer = 72).
What it is now
The expert becomes the kernel's outermost item axis. The descriptors move
from one allocation each into one allocation of
expertsdescriptors(
Bf16PairsTmaMaps), which is all the kernel needs to reach experte'soperands — their base addresses and row strides were already in the
descriptors, so an item's tile coordinates, its operand walk and the transaction
bytes it charges are a single GEMM's, unshifted:
The only geometry that differs is
C, one allocation holding every expert'smatrix, where the expert is
tiles_mtile-rows down. That is derived, notpassed — which is why
expertsis the single new kernel parameter and theproducer/MMA/epilogue loops are otherwise byte-for-byte what they were. The
alternative sketched in the issue — one strided descriptor per operand — needs
four per-operand expert strides instead of one parameter, because the expert
sits on the MN axis of three of the six operands and on the K axis of the other
three (the globally transposed weight is
[columns, E * rows]).Launches: 576 → 72 a step (−504). Trainer total 1206 → 702.
What it buys, and what it does not
Not launch latency. The grid is capped at
MAX_CLUSTERS = 74clusters eitherway, so batching never widens a launch that already filled the device. What it
removes is the tail of one — the same last-wave quantization the kernel's
own module doc names when it explains why 192 tiles over 74 clusters is 86.5%.
./run.sh model profilevsdc6f533(same container, B=12, C=6144), ms:forward.experts.gate_up_gemmforward.experts.down_gemmbackward.experts.down_weight_gemmbackward.experts.down_input_gemmbackward.experts.gate_up_weight_gemmbackward.experts.gate_up_input_gemmforward.experts.swiglubackward.experts.swigluoptimizer.experts.*.adamwThe three that move most are the three whose per-expert tile count put them in
the 86.5% regime (192 or 384 tiles over 74 clusters); the two that barely move
were already at 94–97%. Shape arithmetic alone predicts 0.925 for the group
against the 0.918 measured, so the wave tail is nearly all of it and the
remainder is per-launch fill.
A/B on the shipping binary
bin/train, B=16, TRAIN_STEPS=12 (first discarded, 11 measured), both armsbuilt and run back to back in one container against
dc6f533, two rounds:+2.09% (36.55% → 37.32% MFU). Within-arm spread is 0.07% and 0.03%, so the
effect is thirty times the noise. The profile's −3.9% on the step is the larger
number because that binary synchronizes every span; the trainer's +2.1% is the
one that counts.
Registers
ptxasbudgets, unchanged in every digit — the expert index is a divide and apointer stride an item, not liveness carried through the pipeline:
gemm_tcgen05_bf16_optimizedgemm_tcgen05_f32_optimizedgemm_tcgen05_f32_accumulateFidelity
No tolerance touched, no gate weakened.
./run.sh gemm—fp32 and tcgen05 bf16 GEMM store/accumulate parity passed../run.sh model— every gate green, includingaligned tcgen05 expert forward/backward, zero rows, accumulation, and compute sync, both substitutedMoE model gates, the aux-loss overfit, and the byte-identical checkpoint
resume.
The fp32 oracle path (non-aligned expert shapes) keeps its host loop and is
covered by its own gate unchanged.
Interaction with the concurrent expert-panel bf16 work
That branch changes the store dtype of the expert bin buffers; this one
changes launch structure. They meet in
expert_linear_forward/expert_linear_backwardand in thef32_*adapters' output type, so expectconflicts in exactly those places. The resolution is mechanical: whatever the
output buffer becomes, this side only requires it to be the
expertsstacked[m, n]matricesassert_batched_outputchecks for, and a packed-bf16 outputwould want a
store_batchedbesidef32_store_batchedbuilt the same way.