Verba/Rapida

Experiments #167

A fused top-64 select for the 2-bit head shortlist: row 67c's `r67cScores` (`src/transformer.zig:4564`)...

done

What was tested

A fused top-64 select for the 2-bit head shortlist: row 67c's `r67cScores` (`src/transformer.zig:4564`) negates the 162,489 2-bit scores and calls `mlx_argpartition_axis`, which runs as MLX's multi-block sort (`merge_mbsort`, `partition_mbsort`, 131 us a step), then builds a 162,489-wide -1e30 row with `mlx_full` and `mlx_put_along_axis` that the head argmax reads whole (58 us); a Lesto kernel that keeps each threadgroup's 64 largest and merges them once, and an argmax over the 64 rescored values only, with the argpartition's own tie order (read from MLX's sort, then checked against it on captured rows), so the reply is unchanged; step 1 a kernel test against `mlx_argpartition` on captured 2-bit rows, then the 50-session identity count, then a pair

Model and setup

the best

Expected gain

about +1.0% to +1.8% (0.10 to 0.19 ms of 10.4 ms at 8k; **measured** cost, **estimate** of the kernel's own time)

Where the idea came from

rows 67c, 165

Outcome

done 2026-11-19: ; lossless (150 of 150), decode +0.59% [+0.57, +0.62] against the 0.7% line (`mac/167/1`), about 61 us a step of the 100 to 190 estimated; `row/167` kept for a stacked lossless pair; shortfall split in row 167p (`2026-11-19-mac-r167-topk-select/README.md` ยง Result, row 167)

Lesson

replacing the shortlist's full merge sort and full-row argmax with a fused top-64 select and a 64-wide argmax keeps every reply and shortens the decode step by about 61 us (+0.59% [+0.57, +0.62]), a third to two thirds of the estimate, because the fused select's first pass (80 threadgroups each bitonic-sorting 2,048 scores) runs 106 us by itself.

Adopted

no (no-gain under the pre-registered +0.7%; lossless and measured, so `row/167` stays for the next stacked lossless pair, beside rows 159z and 156g)

Want to see what these experiments produced? Lesto, the Gemma 4 inference engine for Apple silicon Macs, is on lestoengine.com

Made by Federico Andrioli, @fedeandri on X A research lab's own measurements, generated from its files. Data built