Modern Apps git

← Modern-Apps.git

ml: multi-query cached apply lanes walk channels, prefill attn apply -60%

Commit
62faa63ff186692c3f271913c21062d120a4da85
Author
vayun-mathur <[email protected]>
When
2026-10-26 00:26 UTC (1 month ago)
Parents
26d56b5

Diff

library/ml/src/main/rust/shaders/attn_apply_cached.comp
diff --git a/library/ml/src/main/rust/shaders/attn_apply_cached.comp b/library/ml/src/main/rust/shaders/attn_apply_cached.compindex 38e89986c4..e4af4158a6 100644--- a/library/ml/src/main/rust/shaders/attn_apply_cached.comp+++ b/library/ml/src/main/rust/shaders/attn_apply_cached.comp@@ -46,10 +46,12 @@ void main() {     if (index >= p.count) {         return;     }-    // The output is `[d_model, 1, queries]`: channel-major, query innermost.+    // The output is `[d_model, 1, queries]`. Adjacent lanes take adjacent channels of one query,+    // so the probability row is a broadcast and the V reads are contiguous; at one query this is+    // `channel = index`.     uint queries = max(p.dil_h, 1u);-    uint channel = index / queries;-    uint q = index % queries;+    uint channel = index % p.out_c;+    uint q = index / p.out_c;     uint stride = p.in_w;     uint head_dim = p.out_c / p.group;     uint head = channel / head_dim;@@ -65,5 +67,5 @@ void main() {     }     // A folded int8 round-trip: the attention mixture's `Quantize` (live's     // `Mm` round-trip at `MM_SCALE`) stores here instead of its own dispatch.-    arena[p.out_at + index] = float16_t(quant_store(total));+    arena[p.out_at + channel * queries + q] = float16_t(quant_store(total)); }