Skip to content

SwiGLU is the family tiles win on, and it is not the one #70 expected - #73

Merged
feitreim merged 3 commits into
mainfrom
feat/issue-70-swiglu-tiles
Aug 3, 2026
Merged

feitreim merged 3 commits into
mainfrom
feat/issue-70-swiglu-tiles

Conversation

@feitreim

@feitreim feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Part of #70. Stacked on #71 (feat/issue-66-ferro-kittens), which this branches from — retarget to main once that merges. The kittens pin is #71's and unchanged here.

#70 puts the RMSNorm and classifier families in the port-first tier, on the strength of ferro-kittens having a direct reference kernel for each (examples/src/layernorm.rs, examples/src/softmax.rs), and SwiGLU in the measure-first tier because "the current flat kernels may already be at bandwidth". Measured on a B200 at bin/train.rs's shapes, that ordering is backwards. This PR ports the family that won; the two that lost are recorded on #70 with their numbers and stay flat.

What the clock says

modal run modal_app.py::main --kernel ops --bin bench, 24576 x 4096 fp32, three warmups and twenty timed iterations per row, one container:

kernel shipped tile
swiglu_forward 0.4937 ms, 2447 GB/s 0.4166 ms, 2900 GB/s 1.185x
swiglu_backward_gate 0.5323 ms, 3026 GB/s 0.4619 ms, 3487 GB/s 1.152x
swiglu_backward_up 0.4943 ms, 2444 GB/s 0.4121 ms, 2931 GB/s 1.199x
swiglu_forward_bf16 0.2863 ms, 3516 GB/s — 0.696x measured, not ported

There is no reduction anywhere in this family and no row statistic to share, so the tile buys exactly one thing: a warp owns a SWIGLU_TILE_ROWS x SWIGLU_TILE_CHUNK = 16 x 32 rectangle, so load_rows/store_rows pair adjacent columns into one 8-byte access and a lane carries a chunk's worth of them in flight where the flat kernel carries one. On a kernel sitting at 2447 GB/s against the 5630 the RMSNorm backward reaches on the same card, that one thing is the whole gap.

The bf16 forward staying flat is the same explanation read backwards, and it is why this is four kernels and not five: that kernel already stores a packed pair per thread, so it already had the access width, and at 3516 GB/s there is nothing left to buy. Its tile version measured 0.696x and is not in this diff.

Shape was swept — SWIGLU_TILE_CHUNK at 16/32/64 and SWIGLU_TILE_ROWS at 16/32. 32 columns and 16 rows is the peak; 64 columns falls off a cliff to 0.39x, which is a .local depot and not the arithmetic (same shape as ferro-kittens' regcount census, #167 there).

What is in the diff

  • gpu/ops/src/lib.rs: swiglu_forward_tile, swiglu_backward_gate_tile, swiglu_backward_up_tile, and the five SWIGLU_TILE_* knobs a --sweep turns. The flat kernels are untouched and stay as the oracle check_swiglu already gates against the CPU module.
  • gpu/ops/src/main.rs: check_swiglu_tile, each tile kernel against the flat one it would replace at a shape that divides the tile. Tolerance is looser than the flat gate's against the CPU, for one reason named in the source: kittens' exp is not libdevice's, and every kernel here is a sigmoid.
  • gpu/model/src/lib.rs: swiglu_tiles(rows, columns) returns a launch only when the shape divides. The tile kernels bounds-check nothing, so this is the single place that is decided, and the flat kernels are the arm anything else takes. Four call sites — the dense forward and backward, the MoE Wide forward, the MoE backward.
  • gpu/ops/src/bin/bench.rs, new: the crate had no bench binary, which is why nobody knew these rates.

The bench binary is the point as much as the port

Every family #70 names is in it at the training shape, whether or not it has a tile row. A family that was left flat is a report_one line carrying the rate that decided it, so the next attempt starts from a number:

rms_norm forward                (906 MB)   0.2174 ms   4167 GB/s
rms_norm backward_x            (1510 MB)   0.2680 ms   5634 GB/s
fused_classifier forward bf16  (2479 MB)   1.4790 ms   1676 GB/s
swiglu forward bf16            (1007 MB)   0.2863 ms   3516 GB/s
rope forward                    (604 MB)   0.6539 ms    924 GB/s

That last line is a finding on its own and #70 asked for it: RoPE moves comparable traffic to SwiGLU at 924 GB/s against 2447, because its arithmetic is a powf, a sin and a cos per element. It is not a memory kernel, and no tile shape changes that — a precomputed cos/sin table would.

Gates, all on a B200

  • modal run modal_app.py::main --kernel ops — parity, including check_swiglu_tile. Green.
  • modal run modal_app.py::main --kernel ops --bin bench — the table above.
  • modal run modal_app.py::main --kernel model — the full Dense + MoE forward/backward/optimizer parity suite, 14 checks, green with the tile arms live in the training path.

The exploration this PR is the surviving quarter of — the RMSNorm and classifier tile kernels, their gates, and the bench rows that priced them — is pushed as feat/issue-70-tile-probes so the negative results are reproducible rather than only reported.

feitreim and others added 3 commits August 3, 2026 13:10
…nt surface

`gpu/kittens` was frozen at the 2026-07-26 extraction while ferro-kittens took
~167 PRs on top of the same snapshot. Replace it with a pinned git dependency
(`caa6075`) and bump cuda-oxide b099f64 -> 20a5616 in all seven remaining
`gpu/*` manifests, their lockfiles, `modal_app.py`, and the SPEC citations —
the pins have to match, since kittens takes cuda_device/cuda_core types in its
signatures.

ferro-kittens' `[lib] name` is still `kittens`, so no import path moves. What
moved is the surface:

- `ldst::store_fragment_bf16` -> element-generic `store_fragment`.
- `Semaphore::multicast_alias` -> `Semaphore::at_rank(0)`, returning a
  `ClusterSemaphore` that may be arrived at but not waited on. Only rank 0
  charges, now via `TransactionBytes::across_ranks`.
- Every TMA load hands back a `#[must_use]` `TransactionBytes` and
  `expect_tx` takes only that, so the byte counts the kernels wrote by hand
  are gone: the charge is summed from the loads that earned it. Partial-height
  loads need `tma_load_at::<TILE>` (feitreim/ferro-kittens#168).
- `RegVec<N>`/`RegTile<S, V>` count logical rows and columns against a layout
  now, not per-thread slots: `RegVec<32, BaseLdtm>`, `RegTile<32, 128,
  BaseLdtm>`. `value_column(v)` folds into `BaseLdtm::column(lane, v)` and
  `add_assign` into `bin_map_assign::<Add>`.
- `mma_*` derive element, accumulator and both transpose flags from the
  operands and the entry point, so all fifteen instruction-descriptor builders
  collapse to one shape — `MMA_SHAPE` in flash-attn, a literal in gemm — and
  the four MMA helpers lose a parameter that had become a constant.
- `pipeline::Job` gained a defaulted `RANKS` and `run` deals items by
  `%clusterid`; at this kernel's one-CTA cluster both degenerate to the loop
  already written.

Refs #66.
Not drift from the kittens swap — `gpu/model/src/bin/sample.rs` is byte
identical to main here and has not compiled since 0ec4ad6 (2026-07-23), which
added the `L` layer count and split `GpuDenseWorkspace` into
`GpuMoeWorkspace`. Nothing builds this binary: `modal_app.py` runs `train` and
`profile`, and no host without a CUDA toolkit can `cargo check` it, so the
arity rotted in silence for three days before ferro-kittens existed.

`checkpoint::load` takes thirteen const generics and was given twelve;
`GpuDenseWorkspace` takes eight and was given eleven, and is not what
`GpuDense::forward` accepts anyway. Follow train.rs: `GpuMoeWorkspace` with
`L`, and the canonical 12-block MoE configuration both other bins run — the
old 1_536-wide/64-head numbers would have failed the checkpoint header check
at runtime even once the types lined up.

Refs #66.
…#70)

#70 puts the RMSNorm and classifier families in the port-first tier, on the
strength of ferro-kittens having a direct reference kernel for each, and SwiGLU
in the measure-first tier because "the current flat kernels may already be at
bandwidth". Measured on a B200 at the training shapes, that ordering is exactly
backwards, and this ports the family that won.

At 24576 x 4096 fp32, against the flat kernel that gives one output element to
one thread:

| kernel | shipped | tile | |
| --- | --- | --- | --- |
| `swiglu_forward` | 2447 GB/s | 2900 GB/s | **1.19x** |
| `swiglu_backward_gate` | 3026 GB/s | 3487 GB/s | **1.15x** |
| `swiglu_backward_up` | 2444 GB/s | 2931 GB/s | **1.20x** |
| `swiglu_forward_bf16` | 3516 GB/s | — | 0.70x, not ported |

There is no reduction anywhere in this family and no statistic to share, so the
tile buys exactly one thing: a warp owns a `16 x 32` rectangle, so adjacent
columns pair into one 8-byte access and a lane carries a chunk's worth of them
in flight instead of one. On a kernel that was 2447 GB/s against the 5630 the
RMSNorm backward reaches on the same card, that one thing is what was missing.

The bf16 forward stays flat, and it is the same explanation read the other way:
that kernel already stores a packed pair per thread, so it already had the
access width, and at 3516 GB/s it has nothing left for a tile to buy. Its tile
version measured 0.70x and is not in this diff.

`gpu/model` takes the tile arm through `swiglu_tiles`, which returns a launch
only when the shape divides the tile — the kernels bounds-check nothing, and
this is the one place that is decided. Every shape in `bin/train.rs` divides
(dense `24576 x 4096`, MoE `49152 x 4096`); the flat kernels stay as the arm
anything else takes, which is also what keeps them as the oracle `check_swiglu`
already gates against the CPU module.

`gpu/ops` gains a `bench` binary, which it did not have. Every family #70 names
is in it at the training shape, whether or not it has a tile row — a kernel that
was left flat is a `report_one` line with the rate that decided it, so the next
attempt starts from a number instead of from an intuition. It is also what says
`rope_forward` is not a memory kernel at all: 924 GB/s where SwiGLU moves
comparable traffic at 2447, because the arithmetic is a `powf`, a `sin` and a
`cos` per element and no tile shape moves that.

Gates, on a B200: `--kernel ops` (the tile kernels against the flat ones,
looser than the flat gate against the CPU because kittens' `exp` is not
libdevice's), `--kernel ops --bin bench` for the table above, and `--kernel
model` — the full Dense and MoE forward/backward parity suite, 14 checks, green
with the tile arms live.

Stacked on #71 (`feat/issue-66-ferro-kittens`), which this branches from; the
`kittens` dep is pinned at that branch's rev and unchanged by this PR.
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