Verba/Rapida

Experiments #167f

Row 167p's fix: the shortlist's top-64 pick without sorting the losers. Row 167's `r167_topk_part`...

done

What was tested

Row 167p's fix: the shortlist's top-64 pick without sorting the losers. Row 167's `r167_topk_part` (`src/topk_select.zig`) bitonic-sorts each 2,048-score chunk in full to keep 64 (106 us a step, plus a 33 us ); a threshold select (one pass counting scores above a candidate cut found from per-thread maxima, a gather of the at-most-few-hundred survivors, then the same stable order on those only) keeps argpartition's pick and tie order. Step 1 the r167 unit tests (ties, NaN, k = 64) plus a timing-free kernel microbench against row 167's part and merge; then the 150-reply identity count; then a pair stacked on row 167

Model and setup

row 167

Expected gain

about +0.7% to +1.0% (0.07 to 0.12 ms of 10.4 ms; **measured** cost, **estimate** of the new kernel's time)

Where the idea came from

rows 167, 167p

Outcome

done 2026-11-19: step 1a PASS (`2026-11-19-mac-r167f-select-chunks/README.md`: part plus merge 91.6 us at CH 256, TG 128 against 125.9 at CH 2048, saving 38.7 us [26.7, 51.3]; picks identical to argpartition at every size); closed into row stk2, which carries the constants (LESTO row/167f 9413eb26, stacked on row/stk2) to the identity count and the pair; no separate build

Lesson

smaller chunks cut row 167's select by a third with no new code: at CH 256 each threadgroup sorts 256 scores in shared memory instead of 2,048, and the merge's extra chunks (635 against 80) cost less than the sorts saved. The saving grows at every halving down to 256, so the sort dominated, not the merge.

Adopted

no (closed into row stk2, which measures it in the engine)

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