Verba/Rapida

Experiments #149k

The global layers' 2-pass attention re-reads K and V once per query head: MLX's generic...

done

What was tested

The global layers' 2-pass re-reads K and V once per query head: MLX's generic `sdpa_vector_2pass_1` runs one simdgroup per query head, so at G = 8 each K and V byte is read 8 times (1.34 GB through the caches a step at 8k for 168 MB of KV), and the duplication-free `_gqa` variant excludes head dim 512 (`scaled_dot_product_attention.cpp:550-555`, code read in `2026-11-12-mac-decode-profile-r147/README.md` ยง Row 149k). Stage 1: a timing microbenchmark of SDPA at head dim 512, 8k, 2 KV heads, 16 against 2 query heads. Stage 2: a head-dim-512 duplication-free pass-1 (HPT 2 or 4 heads a simdgroup, sub-chunk partials written as extra blocks, no threadgroup reduction); rounding-class, the Mac quality before a race

Model and setup

the best

Expected gain

the 0.35 to 0.43 ms a step at 8k by the bandwidth arithmetic (row 149v sizing), about +3% at the sessions' lengths

Where the idea came from

row 149g

Outcome

done 2026-11-12: inside Lesto the head-dim-512 2-pass kernel takes 214.7 us at G = 8 and 8k against 210.4 at G = 4 and 205.5 at G = 2, the same with K and V rotated past the cache (156 GB/s either way): the re-read is 4% of the kernel, so a duplication-free variant is worth at most +0.4% at 8k (+0.9% at 1k for the 1-pass kernel); no build; the shortfall moves to row 149m

Lesson

the head-dim-512 2-pass kernel runs the best's global layers at about 156 GB/s whether K and V come from DRAM or the cache and whether they are re-read 8, 4 or 2 times, so its shortfall is in the kernel's own loop or its second pass, not the GQA re-read; a duplication-free variant is worth at most 0.4% at 8k and 0.9% at 1k. The open question moves to row 149m (pass 1 against pass 2 at 8k).

Adopted

no (a diagnostic; the lever it sized is too small to build)

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