Verba/Rapida

Esperimenti #149k

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

done

Il testo degli esperimenti resta in inglese, come l'ha scritto il laboratorio.

Cosa è stato provato

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

Modello e configurazione

the best

Guadagno atteso

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

Da dove viene l'idea

row 149g

Esito

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

Lezione

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).

Adottato

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

Vuoi vedere cosa hanno prodotto questi esperimenti? Lesto, il motore di inferenza per Gemma 4 sui Mac con Apple silicon, è su lestoengine.com

Creato da Federico Andrioli, @fedeandri su X Le misure di un laboratorio di ricerca, ricavate direttamente dai suoi file. Dati aggiornati al