nx_f32_gqa_attention.nx
buildroot/runtime/nx_f32_gqa_attention.nx
about
nx_f32_gqa_attention.nx -- software-f32 Grouped-Query multi-head attention (Ainslie 2023 GQA).
sd-server -> Nishi migration: Qwen3-4B (the Z-Image text encoder + companion chat model) uses GQA with
32 query heads sharing 8 kv heads (4:1, confirmed from the real GGUF: q_out 4096, kv_out 1024). This wraps
the gated single-head `nx_f32_attention`: for each query head h it gathers Q_h and the SHARED K/V of kv
head (h / group), runs scaled-dot-product attention, and scatters the head output back. This is the
attention core of a real Qwen (and DiT) transformer layer.
Q,out: flat *i64 f32 bits [n_tokens, n_q_heads*head_dim]. K,V: [n_tokens, n_kv_heads*head_dim].
license_tier: ORIGINAL
dependencies 5 imports · 2 importers
imports: nx_syscalls.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f32_attention.nx
imported by: nx_f32_qwen_layer.nxnx_qwen_hybrid_attn.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 17 | const NX_F32GQA_OK: i64 = 0 |
| 18 | const NX_F32GQA_ERR: i64 = 1 |
functions
| 20 | func nx_f32_gqa_attention(Q: *i64, K: *i64, V: *i64, n_tokens: i64, |
| 66 | func main() -> i64 |