Repository navigation
SwiGLU is the family tiles win on, and it is not the one #70 expected - #73
Merged
Merged
Conversation
…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.
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.
Part of #70. Stacked on #71 (
feat/issue-66-ferro-kittens), which this branches from — retarget tomainonce that merges. Thekittenspin 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 atbin/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:swiglu_forwardswiglu_backward_gateswiglu_backward_upswiglu_forward_bf16There 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 32rectangle, soload_rows/store_rowspair 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_CHUNKat 16/32/64 andSWIGLU_TILE_ROWSat 16/32. 32 columns and 16 rows is the peak; 64 columns falls off a cliff to 0.39x, which is a.localdepot and not the arithmetic (same shape as ferro-kittens'regcountcensus, #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 fiveSWIGLU_TILE_*knobs a--sweepturns. The flat kernels are untouched and stay as the oraclecheck_swiglualready 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'expis 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 MoEWideforward, 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_oneline carrying the rate that decided it, so the next attempt starts from a number: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, asinand acosper 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, includingcheck_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-probesso the negative results are reproducible rather than only reported.