Implement a single decode step of FlashDecoding with grouped-query attention (GQA).
At decode time the query is one token while the key/value cache has length . FlashDecoding splits that cache along the sequence axis, computes attention on each split, and merges the split results so the output equals full attention.
Inputs
q: array of shape (batch, n_q_heads, head_dim) — query for the new tokenk, v: arrays of shape (batch, seq, n_kv_heads, head_dim) — the KV cachen_splits: positive int, number of contiguous splits of the sequence axisn_q_heads is divisible by n_kv_heads. Each KV head is shared by n_q_heads / n_kv_heads query heads (GQA; MHA is the special case n_kv_heads == n_q_heads).
Contract
seq with the same lengths as numpy.array_split(range(seq), n_splits) (leading splits get the remainder).n_splits > seq) contribute nothing.(batch, n_q_heads, head_dim) and must match full GQA scaled-dot-product attention
with KV heads repeated to the query-head axis.
Use 64-bit floats internally.