Repository navigation
The fused RMSNorm backward on register tiles, and the forward that measured worse - #124
Merged
Merged
Conversation
The block-per-row pair pays for its row statistics in shared memory: a 256-lane tree is eight barriers, and the fused backward runs that tree once per row for all sixteen rows it owns -- 160 barriers a block, to produce two numbers a row. On tiles a warp owns the sixteen rows at once and both statistics are row_sum: two shuffles, no shared memory, no barrier anywhere in either kernel. The weight gradient is the axis that does not fit that picture, and it is why this kernel needed ferro #179's per-column statistic rather than only its mover: col_sum gives the chunk's columns summed over the warp's rows, column_group_reduce makes the eight replicas agree, and the four lanes holding distinct columns pay one atomic each. That is dim atomics per sixteen rows, which is exactly what the shared accumulator already paid -- it was never buying fewer of them, only spreading them over a block that owned the same sixteen rows. rms_norm_forward_fast_bf16's own note argued this dtype had nothing to gain, that packing the stream already doubles the elements a lane carries. The arithmetic does not support it: at dim 3072 the block-per-row lane holds six words, twelve elements, and a [16, 64] band gives it thirty-two. Packing recovers a sixth of the gap rather than closing it. Both kernels were in the thirteen the ops gate never compared -- their only coverage was whole-model parity -- so they get one here, against the block-per-row kernels they replace, at the fp32 RMSNorm gate's own tolerances rather than widened ones.
…d dweight The new gate caught it on its first run: dweight came back 69.7227 against 8.715337, which is 8.0000x, and eight is the size of a column group -- the lanes sharing a column under BaseLdtm, which col_of reaches by ignoring lane/4. The mistake was reading RegTile::col_reduce as the lane-local half of the fold. It is the whole of it: it folds across the column group itself, so the eight lanes holding a column already agree on the complete sum over the warp's rows. The extra column_group_reduce then summed eight copies of a finished number. What the four representative lanes owe dweight is one atomic of the value col_sum already handed them.
…oes back rms_norm_forward_fast_bf16's note said a warp-per-band forward had nothing to gain once the stream is packed. I overturned it on arithmetic -- twelve elements a lane against thirty-two -- and the arithmetic was answering the wrong question. Two rounds, same-container and across containers: forward.attention_norm +7.8% and +13.8%, forward.final_norm +7.7% and +9.2%. Four measurements, one sign. What the band buys is loads in flight, and this kernel was not short of them. At 24 registers the block-per-row forward holds 8 blocks of 256 on an SM; the tile holds 8 of 128. The rewrite halves the threads hiding the latency to buy a lane more of it, and on a kernel this light the threads were worth more. The kernel and its half of the gate come out rather than staying as dead code the next reader has to re-litigate; the note goes back with the numbers behind it instead of the argument.
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.
The first
gpu/opsconversion onto kittens register tiles, picked by profilespan and by how far each span is from HBM rather than by how hand-rolled it
looks. One kernel converted, one converted and reverted with the numbers, and
a ranked triage of the other fifteen. The headline is a null: the RMSNorm
family was never barrier-bound, and moving it onto tiles does not move the step.
The survey
Baseline is
a47aa22(this branch's merge-base)../run.sh model profileon B200, B=12 T=2048 D=3072 FF=4096 E=8 K=2 L=12; fullstep 296.996 ms. GB/s is computed from the shapes each span launches,
counting a re-read of the same row inside one block as L1-resident;
% peakisagainst B200 HBM at 8 TB/s.
backward.ffn_normrms_norm_backward_fused_bf16backward.attention_normrms_norm_backward_fused_bf16backward.experts.swigluswiglu_backward_interleaved_packedbackward.qkv_proj.joinjoin_group3_rope_bf16forward.experts.swigluswiglu_forward_interleaved_packedforward.router.logitsrouter_logits_bf16backward.loss.fused_classifierfused_classifier_backward_in_place_bf16backward.router.weightrouter_backward_weight_split_bf16forward.router.scattermoe_scatter_packed_quadbackward.router.gather_dxmoe_gather_dx_add_quadforward.router.gathermoe_gather_combine_add_quad_packedforward.attention_residual_normrms_norm_forward_residual_bf16backward.router.scatter_dymoe_scatter_dy_packedbackward.router.inputrouter_backward_inputforward.attention_normrms_norm_forward_fast_bf16forward.loss.fused_classifierfused_classifier_forward_bf16forward.final_normrms_norm_forward_fast_bf16What ships:
rms_norm_backward_fused_tile_bf16The block-per-row kernel pays for its two row statistics in shared memory: a
256-lane tree is eight barriers, and it runs that tree once per row for all
sixteen rows a block owns — 160 barriers a block, to produce two numbers a row.
On tiles a warp owns the sixteen rows at once and both statistics are
row_sum:two shuffles, no shared memory, no barrier anywhere in the kernel.
The weight gradient is the axis that does not fit that picture, and it is why
this needed ferro #179's per-column statistic and not only its mover.
col_sumgives the chunk's columns summed over the warp's rows, and the four lanes
holding distinct columns pay one atomic each. That is
dimatomics per sixteenrows — exactly what the shared accumulator already paid. It was never buying
fewer of them, only spreading them over a block that owned the same sixteen
rows.
NORM_BACKWARD_TILE_CHUNKis 32 where the forward's is 64, for the reason thatconstant's own note gives for stopping at 64: this kernel carries three bands at
once where the forward carries one.
It also drops a 16 KiB shared allocation and with it the
dim ≤ NORM_MAX_COLUMNS(4096) shape cap, which was a property of the column-partials array and nothing
else.
The measurement
Three rounds. A and C are the two arms of one
BASELINE_REF=main ./run.sh model profile(same container, same GPU — A is itsbuild-and-run pass, C its measured pass); B is a plain profile of each branch
in its own container.
backward.ffn_normbackward.attention_normFive of six negative, and the two spans keep their rank in every round —
attention_normgains three to five times whatffn_normdoes, which is thesame kernel at the same shape entering with a different cache state (one follows
the flash backward, the other the expert backward).
So: a real sign, a small magnitude. −4.3% of 12.5 ms is −0.54 ms, and in that
same round untouched spans moved further than that on their own —
flash_kv−0.845,gate_up_gemm−0.595,flash_q−0.580. The claim isneutral-to-slightly-better, not a win, and the composed full step (723.39 →
717.45, −0.8%) is mostly those untouched spans.
Registers, no spills either way:
rms_norm_backward_fused_bf16rms_norm_backward_fused_tile_bf16That is a step down, and −0.54 ms is thin justification for it. It ships on
the code — no barriers, no shared memory, no shape cap — with the number here so
the next reader does not have to rediscover that the barriers were free. What
these kernels wait on is memory, and both arms issue the same bytes: the two-pass
structure is unchanged, so a mover rewrite was never going to move the traffic
that sets the 1.8 TB/s. That is the lesson worth more than the 0.54 ms.
What was reverted:
rms_norm_forward_tile_bf16rms_norm_forward_fast_bf16's note said a warp-per-band forward had nothing togain once the stream is packed. I overturned it on arithmetic — twelve elements a
lane against thirty-two — and the arithmetic was answering the wrong question.
forward.attention_normforward.final_normSix measurements, one sign. At 24 registers the block-per-row forward holds
8 blocks of 256 on an SM; the tile holds 8 of 128. The rewrite halves the threads
hiding the latency to buy a lane more of it, and on a kernel this light the
threads were worth more. The kernel and its half of the gate are removed rather
than left as dead code; the note goes back with the numbers behind it.
Parity
rms_norm_backward_fused_bf16was among the thirteenlib.rskernels thegpu/opsgate never compared — its only coverage was whole-model parity.check_rms_norm_tile_bf16now compares the tile arm against it at the fp32RMSNorm gate's own tolerances (
dx3e-5,dweight5e-6/2e-5), not widened ones.Nothing existing was loosened.
./run.sh model(17 checks) is green.The gate earned its keep on its first run:
dweightcame back 8.0000x high,which is the size of a column group.
RegTile::col_reduceis not the lane-localhalf of the fold — it is the whole of it, and the extra
column_group_reducewassumming eight copies of a finished number.
Nulls, with the number
swiglu_backward_interleaved_packed(6.410 ms) is already at bandwidth —4523 GB/s over 29.0 GB. Reported, not attempted.
swiglu_forward_interleaved_packed(4.802 ms) stays hand-rolled.swiglu_tiles' note records the bf16 forward measuring 0.70x (Evaluate/port gpu/ops and gpu/tensor-gpu kernels onto ferro-kittens tiles — measure first #70), and thatverdict predates ferro #180 — the fix that moved the fp32 norm tile from 0.280x
to 1.246x — so it is a stale null worth re-running. What blocks it here is
numerics: kittens'
Expisexp2_approx(x·log₂e), not libdevice's, andcheck_swiglu_interleavedcompares the packed kernels bit-exactly. A tilearm needs that gate moved to a tolerance, which is a loosening and belongs in
its own change with its own argument.
rms_norm_forward_residual_bf16(2.461 ms) stays hand-rolled. Already 46%of peak, and the tile shape is structurally worse: it stages the rounded row in
shared memory so its second pass costs no traffic, where a tile version must
re-read
sum(10 → 12 B/element) or recompute it (10 → 16). The depot is thewin here, the same way The router weight gradient's loads share a basic block, and 64 partitions buy what 256 did #111's was.
router_backward_weight_split_bf16(3.192 ms, 591 GB/s) stays hand-rolled.Low, but The router weight gradient's loads share a basic block, and 64 partitions buy what 256 did #111 measured the
.localdepot as the faster arrangement (4.3205 msagainst 3.1397 unrolled). Not touched blind.
indexed per (token, rank) through
slots/selected_experts. There is norectangle for a tile walk to cover.
For the ptxas-reproducibility investigation (already fixed by #123)
Every number above was taken on
a47aa22, before #123 landed. On that commit,compare_profileandrun.sh model profilecompiled the same source intomaterially different binaries, and the difference was 2.45x of step time:
./run.sh model profileBASELINE_REF=… ./run.sh model profileBoth arms inside a
compare_profilerun agreed with each other (both spilled),so the A/B stayed internally valid — but every
compare_profilenumber was takenat a GEMM-spilled operating point the shipping binary never reached. This branch
is rebased onto #123, whose
#[launch_bounds(192, 1)]on the GEMM entry pointsis exactly the "stop letting the driver derive the block" fix that shape calls
for. Recorded as an independent sighting of the symptom #123 names, not as an
open issue.
Still open, ranked
router_logits_bf16is the standout: 453 GB/s, 6% of peak, 4.024 ms, worstin the set by a factor of three. A skinny
[N,D]×[D,8]GEMM whoseROUTER_GEMM_BNis the expert width — a blocking problem, not a mover problem.After it,
fused_classifierforward+backward (5.075 ms at 18%/28%) has theclearest tile shape left: a row band over the padded vocabulary with an online
(max, sum)thatRegVeccarries directly andright_fillmasks the paddingtail with.