Expand description
2026-09-25: CPU reference for the GLM-5.3-Flash DSA kpool indexer and NoPE MLA.
Owner: model-arch (GLM-5.3-Flash DSA reference). Invariants:
- Nothing here runs on a GPU or reads a checkpoint; production code does not call it.
- Every index row
expand_selectionreturns is written for its fullout_width, withINVALIDin every slot that holds no token.
examples/dsa_indexer_microtest.rs checks it against goldens from gen_dsa_indexer_golden.py
and gen_dsa_mla_golden.py, which run the transformers glm5_next indexer and attention.
k_normis a LayerNorm: it subtracts the mean and adds a bias (indexer.k_norm.bias). The DSA block’s other norms (q_a_layernorm,kv_a_layernorm) have no bias.- The pool softmax runs over the slot axis, separately for each
head_dimchannel. - Pooling starts at the first valid token, not at slot 0: with left padding
[P, P, A, B, C, D], pool 0 is[A, B, C, D]. - A pool is valid only if all
kpoolslots are valid. A trailing partial pool is not a pool; the tail append covers it, so a 7-token sequence has one pool. - NoPE:
qk_rope_head_dim = 0, sokv_a_proj_with_mqaemitskv_lora_rankvalues and there is no rope section.
Structs§
- DsaDims
- 2026-09-25: Indexer and MLA geometry. No field has a default.
- Pools
- 2026-09-25: The compressed k-pool candidates.
Constants§
- INVALID
- 2026-09-25: The invalid-index sentinel, the
-1the golden generator writes.
Functions§
- expand_
kv - 2026-09-25: Expand the compressed latent into per-head K and V. NoPE only: it asserts
qk_rope_head_dim == 0, so K is exactlyqk_nope_head_dimwide. - expand_
selection - 2026-09-25: Expand selected pools into raw token indices, append the visible tail, and pad with
INVALID. Every row is written for allout_widthentries: the output starts filled withINVALID, and a padded query row stays that way. - index_
scores - 2026-09-25: Per-(query, pool) index score:
sum_h weights[h] * relu(scale * q_h . key). - kept_
pools - 2026-09-25: The original ids of the pools
pool_stateskeeps. Computed from padding and sequence length alone. - layer_
norm - 2026-09-25: LayerNorm over the trailing
d: subtract the mean, divide by the standard deviation, thenw * x + b. - linear
- 2026-09-25:
y = x @ w^Tforx: [m, k],w: [n, k](torchLinearlayout), no bias. - mla_
masked_ attention - 2026-09-25: NoPE MLA over a per-query selected key set.
- pool_
states - 2026-09-25: Build the pools.
k/gateare[seq, index_head_dim],validis[seq]. The indexer golden records the output oftransformers’get_pooled_statesfor comparison. - rms_
norm - 2026-09-25: RMSNorm without bias, the contrast to
layer_normin the tests. - sigmoid_
f32 - 2026-09-25: Public sigmoid; nothing in the DSA reference calls it.
- topk_
pools - 2026-09-25: Select up to
select_kpools per query, ordered by higher score, then smaller pool index, so ties resolve the same way on every run. Invalid candidates scoref32::MIN. - topk_
to_ mask - 2026-09-25: Turn an index row into the boolean visibility mask the attention reads. Duplicate
indices collapse, so a repeated token is attended once; out-of-range and
INVALIDentries are dropped. - visible
- 2026-09-25: Which keys a query at
q_posmay see: causal and not padding.