Module qsa

Module qsa 

Source
Expand description

2026-09-25: The Qwen3.8-Flash-Next QSA indexer: sparse-attention token selection.

Owner: model-layers (QSA). Invariants:

  • Keys are ingested in position order: prefill_ingest and decode_select refuse a start position other than ingested.
  • At or below inert_bound() (budget + ratio - 1) visible tokens every visible token is selected, so the dense path is used unchanged.

Reference: Qwen4ExpTextQSAIndexer. The attention layer’s input is projected to n_heads query heads plus one raw key per token. The visible prefix is grouped into ratio-token blocks whose keys are mean-pooled, k_layernormed and roped at the block’s first position. Each query attends the top budget / ratio blocks by sum_h relu(q_h . k_b) / sqrt(hd), plus the incomplete tail.

Raw keys are ingested during prefill and decode. Decode selection gathers the selected K/V into a contiguous scratch that, through an identity block table, the paged decode attention reads as a cache. Prefill selection (prefill_select, in qsa_select.rs) overwrites the attention context of the rows past the bound. Selection takes a host top-k over scores read back from the device, so a layer with an indexer reports decode_graph_unsupported.

Structs§

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