feat(gemma4): decode the global family through a generated split-KV kernel over a folded 640-column pool - #1055
Conversation
…ernel over a folded 640-column pool Signed-off-by: Feathbow <feathbow@gmail.com>
|
A numeric comparison cannot hold this: the race needs the losing schedule, which is why your repro had to inject one. Re-run on the fixed kernels: gates green, oracles 0.5 / 2.6875 / 2.28125, unchanged from before the fix. That is not evidence the fix works -- it says the race does not surface in natural execution here, which matches your own note. The barrier in the emitted CUDA and the generation gate are the evidence. On the decode tolerance you are right that one prompt is not a basis, and measuring it changed the answer rather than the number. Over sixteen cells -- three prompts at 512, 1500 and 3000 tokens, plus a length sweep around 3000 -- the generated decode reaches 7.91 and the folded pool 7.06, so the 4.0 in the body does not hold at 3000. The incumbent's own gap under a difference already accepted as neutral, a walk against a single prefill of the tokens it walked, reaches 5.75 on the same rows. Neither quantity tracks prompt or length: lengths one page apart differ sevenfold (1.13 at 3072 against 7.91 at 3008) and the worst row lands anywhere from the prompt row to the last, so page alignment is not behind it either. A maximum over a walk of these is a draw from a heavy tail, and no constant fitted to it is a correctness bound. So the gates now separate the two. The argmax is the correctness they carry, equal to the incumbent's on every row of every cell for both arms. The raw-logit gap became a drift line at 12.0, above the measured spread rather than at its edge. What bounds the kernels' own error stays the AOT gate, at 0.002 against an fp32 reference on hostile cases. Both decode gates sweep the nine cells and print each one's gap beside the neutral figure, and the runner's per-gate output window went from twenty lines to forty, since a nine-cell table was being truncated to five with nothing to show it had been. The body gains the run entry points: |
5eea335 to
fcd80a6
Compare
Description
Closes #1053.
The decode read was moving bytes it never used. Gemma 4's global layers rotate a quarter of the head, so a split K|V row of 1024 columns carries 384 columns of K that only the norm weight touches, and the incumbent decode read at 163K spent 4.5 ms per step where its bytes set a floor of 2.5 ms.
The page format is an axis of the layout.
PagedKvLayoutcarries aKvFormat:Splitis the row every existing kernel reads;Foldedholds K only where the rotation touches it, V in full, and folds K's norm weight into the query at prep time, 640 columns per token per head. The hd512 prep writes either form; the format is the pool's for its whole life.Two generated kernels, two formats each. Beside the generated prefill, a split-KV decode kernel (partial over key chunks, merge in two levels) is generated for the global family, both in split-row and folded-row variants; the folded row streams as one tile.
PEGAINFER_GLOBAL_ATTN=tilelangserves prefill and decode through the generated kernels on the split pool,tilelang640on the folded pool; unset oroffis the incumbent kernel on the split pool, byte-identical to before. The server reports the global pool's bytes at start-up.Gated on both formats. The AOT gates run every case in both formats against the JIT twin and an fp32 reference with hostile padding past the plan; the serving oracles hold the generated decode against the incumbent and the folded pool against the split one on the checkpoint.
Test Env
Verification
Bound to the tip of this range; every run on the box above.
tilelang640against vLLM is E2EL +3.0% at 10,602 tokens, −0.5% at 40,002, −5.8% at 81,653 and −12.2% at 163,336; TPOT +2.4 .. +2.7%, +2.7 .. +2.9%, +2.1 .. +2.7% and +1.0 .. +1.6% (from +6.8% and +27.3% before the generated decode); TTFT −13.9 .. −13.2% at 163K. Peak device memory 77.8 GB on the folded pool against 82.7 GB on the split one and 97.1 GB for vLLM at its utilization budget.cargo fmt --check,clippy -D warningson the kernels and gemma4 crates including tests and examples, lib tests green; the one red in the kernels test targets islt_algo_store, which this range does not touch: the assertion that fails is that test's own precondition that a write was cut short, and theRLIMIT_FSIZEit uses to cut one does not truncate on this filesystem.