Module qsa

Module qsa 

Source
Expand description

The Qwen3.8-Flash-Next QSA indexer — decode-side sparse-attention selection (#753 phase G).

Reference: Qwen4ExpTextQSAIndexer. The attention layer’s INPUT (the hc_pre mixed output) is projected to 4 query heads + 1 raw key per token; the visible prefix is grouped into 4-token blocks whose keys are mean-pooled, k_layernormed and roped at the block’s first position; each query attends the top-512 blocks by sum_h relu(q_h . k_b)/sqrt(128), plus the incomplete tail. At or below budget + ratio - 1 (2051) visible tokens the selection is PROVABLY all-visible — the inert regime the port served in until now.

v1 SCOPE (decode-side): raw keys are ingested during prefill and decode; selection runs at DECODE steps once the visible prefix exceeds the inert bound, and feeds the EXISTING paged decode attention through a gathered contiguous scratch + identity block table. Prefill queries beyond the inert bound still run dense (a one-time WARN documents the divergence; per-query prefill selection is stage 2). Single sequence, BF16 KV only.

CUDA graphs: selection does a host top-k on the scores (D2H), which can never sit inside a captured graph — a layer carrying an indexer vetoes decode-graph capture entirely (graphs measured speed-NEUTRAL on GB10, so this costs nothing).

Structs§

QsaIndexer
QsaSelection
One decode step’s selection: contiguous NHD k/v scratch + identity table.
QsaSeqState