qsa: skip score/select where no attention reads them; select once per pass below the exact bound

Architecture-only (no kernel, op schema or graph change). The attention block tells the indexer
whether it reads the selection (AttnGatedFP8::qsa_use): dense steps (<= 1024 tokens of context)
issue no query norm, qsa_score or qsa_select; single-row-per-sequence steps under the exact bound
read the block table; multi-row steps under the bound select once per pass (the selection is
layer-invariant there, every complete block in block order) and the other QSA layers reuse it.
Block keys and tail run every step. The exact host bound (RadBatch::kv_used_max_h) decides which
side of the bound a step is on and keys the pass. RADIANCE_DEBUG_QSA_EAGER=1 restores the old
issue pattern.

arch_test: the pinned step hashes of qwen4exp_fp8 move (graphs unchanged) and two tests pin the
new issue pattern; ref_test pins the equalities it rests on (qsa_select below the bound).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 authored and StillDeadcode committed 2026-11-17 18:41:16 +01:00
1 parent 315aea7db9
commit cfec01ec8d
8 files changed
+515 -30

No files matched your search

+23
View File
@@ -1466,6 +1466,29 @@ inline void batch_split(const RadBatch* b, int64_t* n_seq_dec, int64_t* n_tok_de
}
}
/* What a step's attention reads of the QSA selection (AttnGatedFP8::qsa_use), which decides what
* the indexer issues for the layer (QsaIndexer::step, docs/QSA.md "Below the bound"):
*
* kQsaSelect score and select, per layer: a step past the exactness bound, a streamed group,
* and every step of a block that did not ask for the forms below;
* kQsaUnread nothing reads the selection: the step is entirely at or below the bound and its
* attention is the dense one, or the sparse row over the sequence's own block table
* (one row a sequence), which is what the selection would be. The indexer stores its
* keys and tail and issues no query, score or select;
* kQsaOnce the attention reads a selection (the sparse row a query) on a step entirely at or
* below the bound: every complete block is taken whatever it scores, so the
* selection depends on the positions and the block table alone and is the same
* bytes at every layer. The first full-attention layer of the pass issues it as
* always; no later layer issues a query, a score or a select. */
enum QsaUse : int { kQsaSelect = 0, kQsaUnread = 1, kQsaOnce = 2 };
/* RADIANCE_DEBUG_QSA_EAGER: every step is kQsaSelect, the issue sequence before the forms above
* existed. An instrument for comparing the two (the text must not move); read once. */
inline bool qsa_eager() {
static const bool on = std::getenv("RADIANCE_DEBUG_QSA_EAGER") != nullptr;
return on;
}
/* The step batch's entry for one declared KV group (built once per step by the core, spec §8). */
inline const RadKVGroupBatch* kv_batch(const RadBatch* b, rad_kvgroup group) {
for (int i = 0; i < b->n_kv_groups; ++i)