Skip to content

The fused RMSNorm backward on register tiles, and the forward that measured worse - #124

Merged
feitreim merged 3 commits into
mainfrom
ops-kittens
Aug 7, 2026
Merged

feitreim merged 3 commits into
mainfrom
ops-kittens

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

The first gpu/ops conversion onto kittens register tiles, picked by profile
span 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 profile on B200, B=12 T=2048 D=3072 FF=4096 E=8 K=2 L=12; full
step 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; % peak is
against B200 HBM at 8 TB/s.

span ms GB/s % peak kernel verdict
backward.ffn_norm 7.166 1802 23% rms_norm_backward_fused_bf16 converted, neutral
backward.attention_norm 6.845 1886 24% rms_norm_backward_fused_bf16 converted, neutral
backward.experts.swiglu 6.410 4523 57% swiglu_backward_interleaved_packed already saturated
backward.qkv_proj.join 5.682 2870 36% join_group3_rope_bf16 open
forward.experts.swiglu 4.802 3019 38% swiglu_forward_interleaved_packed kept — numerics, below
forward.router.logits 4.024 453 6% router_logits_bf16 open, worst in the set
backward.loss.fused_classifier 3.375 2204 28% fused_classifier_backward_in_place_bf16 open
backward.router.weight 3.192 591 7% router_backward_weight_split_bf16 kept — #111's depot
forward.router.scatter 2.857 2537 32% moe_scatter_packed_quad kept — indexed
backward.router.gather_dx 2.733 2651 33% moe_gather_dx_add_quad kept — indexed
forward.router.gather 2.633 2753 34% moe_gather_combine_add_quad_packed kept — indexed
forward.attention_residual_norm 2.461 3681 46% rms_norm_forward_residual_bf16 kept — traffic, below
backward.router.scatter_dy 2.242 3232 40% moe_scatter_dy_packed kept — indexed
backward.router.input 1.849 1960 25% router_backward_input open
forward.attention_norm 1.758 2061 26% rms_norm_forward_fast_bf16 reverted — measured worse
forward.loss.fused_classifier 1.700 1458 18% fused_classifier_forward_bf16 open
forward.final_norm 0.156 1935 24% rms_norm_forward_fast_bf16 reverted — measured worse

What ships: rms_norm_backward_fused_tile_bf16

The 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_sum
gives the chunk's columns summed over the warp's rows, and the four lanes
holding distinct columns pay one atomic each. That is dim atomics per sixteen
rows — 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_CHUNK is 32 where the forward's is 64, for the reason that
constant'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 its
build-and-run pass, C its measured pass); B is a plain profile of each branch
in its own container.

span A B C
backward.ffn_norm +1.9% −2.5% −1.5%
backward.attention_norm −5.7% −8.8% −7.3%
both, combined −0.7% −5.5% −4.3%

Five of six negative, and the two spans keep their rank in every round —
attention_norm gains three to five times what ffn_norm does, which is the
same 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 is
neutral-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:

kernel regs threads blocks/SM threads/SM
rms_norm_backward_fused_bf16 64 256 4 1024
rms_norm_backward_fused_tile_bf16 80 128 6 768

That 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_bf16

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.

span A B C
forward.attention_norm +7.8% +13.8% +7.7%
forward.final_norm +7.7% +9.2% +6.8%

Six 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_bf16 was among the thirteen lib.rs kernels the
gpu/ops gate never compared — its only coverage was whole-model parity.
check_rms_norm_tile_bf16 now compares the tile arm against it at the fp32
RMSNorm gate's own tolerances (dx 3e-5, dweight 5e-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: dweight came back 8.0000x high,
which is the size of a column group. RegTile::col_reduce is not the lane-local
half of the fold — it is the whole of it, and the extra column_group_reduce was
summing 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 that
    verdict 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' Exp is exp2_approx(x·log₂e), not libdevice's, and
    check_swiglu_interleaved compares the packed kernels bit-exactly. A tile
    arm 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 the
    win 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 .local depot as the faster arrangement (4.3205 ms
    against 3.1397 unrolled). Not touched blind.
  • The MoE scatter/gather family (10.5 ms over four spans, 2537–3232 GB/s) is
    indexed per (token, rank) through slots/selected_experts. There is no
    rectangle 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_profile and run.sh model profile compiled the same source into
materially different binaries, and the difference was 2.45x of step time:

build path bf16_optimized f32_optimized f32_accumulate full step
./run.sh model profile 132 regs, 0 spill 168, 0 146, 0 296.996 ms
BASELINE_REF=… ./run.sh model profile 172 regs, 4224 spill 168, 4224 193, 4224 727.152 ms

Both arms inside a compare_profile run agreed with each other (both spilled),
so the A/B stayed internally valid — but every compare_profile number was taken
at 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 points
is 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_bf16 is the standout: 453 GB/s, 6% of peak, 4.024 ms, worst
in the set by a factor of three. A skinny [N,D]×[D,8] GEMM whose
ROUTER_GEMM_BN is the expert width — a blocking problem, not a mover problem.
After it, fused_classifier forward+backward (5.075 ms at 18%/28%) has the
clearest tile shape left: a row band over the padded vocabulary with an online
(max, sum) that RegVec carries directly and right_fill masks the padding
tail with.

@feitreim feitreim changed the title The two RMSNorm kernels the step spends 16 ms in, on register tiles The fused RMSNorm backward on register tiles, and the forward that measured worse Aug 7, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant