Expand description
GLM-5.3-Flash KDA CPU reference (Slice 2 design artifact – not a production forward path). GLM-5.3-Flash KDA (Kimi Delta Attention) CPU reference — Slice 2B.
Design artifact, not a production path. Nothing here runs on GPU, nothing here is wired into a forward pass, and no checkpoint tensor is bound. Its only job is to prove the GLM KDA equations in Atlas-shaped code against golden vectors produced by HuggingFace itself, before a single CUDA kernel is written.
§Why this exists
GLM KDA is not a thin parameterization of Atlas’s Qwen GDN (layers::qwen3_ssm). Four
structural items are genuinely new:
- Decay is per (head, key-channel), not scalar-per-head. Atlas’s
compute_gdn_gateswritesgate_out[num_tokens, num_v_heads]; KDA needs[T, H, head_dim]. - The decay source is a low-rank projection
f_a: hidden -> head_dim,f_b: head_dim -> H*head_dim. Atlas derives its scalar from the fusedBAprojection. - The gate law is bounded:
lower_bound * sigmoid(exp(A_log) * (g + dt_bias)), versus Atlas’s unboundedexp(-exp(A_log) * softplus(a + dt_bias)). - The output gate is low-rank
g_a/g_b. Atlas takes a full-rankZout of its fusedQKVZprojection; the KDA checkpoint has noZtensor at all.
See docs/glm5next/KDA-VS-QWEN-GDN.md for the full REUSE/ADAPT/NEW table.
§Provenance of the goldens
kda_golden.json is generated by gen_kda_golden.py (kept beside it), which calls the real
transformers 5.16.1 glm5_next module — Glm5NextTextForgetGate,
Glm5NextTextRMSNormGated, l2norm, recurrent_kimi_delta_attention,
chunk_kimi_delta_attention. No equation is re-derived on the Python side either.
transformers 5.16.0 contains no glm5_next at all even though the checkpoint declares
that version; 5.16.1 is the first source-bearing release.
§Config values are read, never defaulted
gate_lower_bound, rms_norm_eps and hidden_act must all come from the checkpoint config.
vLLM happens to agree with HF on this checkpoint only by coincidence: it looks up the legacy
key lower_bound while the checkpoint stores gate_lower_bound, and falls back to a default
of -5.0 that happens to match. Atlas must not inherit that.
§Layout conventions
q/k/v/gate:[T, H, D], row-major, index((t * H) + h) * D + d.beta:[T, H], indext * H + h.dt_bias:[H * D]— per channel.a_log:[H]— per head.state:[H, D_k, D_v], index(h * D_k + kd) * D_v + vd.- Weights follow the torch
Linearconvention[out, in], row-major.
Structs§
- KdaDims
- KDA geometry. Production is
hidden 4096 / heads 64 / head_dim 128; the low-rank width for bothf_a/f_bandg_a/g_bequalshead_dim. - KdaWeights
- Weights for one KDA layer, reference-only. Torch
Linearlayout[out, in]throughout.
Functions§
- bounded_
gate - The bounded GLM forget gate, item 3 of the four NEW structural items.
- kda_
chunked - Prefill formulation: chunked (WY-style) delta rule, mirroring HF’s
chunk_kimi_delta_attention. Included at reference level because the per-channel decay mask is exactly the part that a scalar-decay GDN kernel cannot express — proving it here is cheaper than proving it in CUDA. - kda_
chunked_ prenorm - Same chunked formulation, but
q/kare already L2-normalised — Atlas’s contract, where the conv path (fused on decode,l2_norm_bf16on prefill) has already normalised them. - kda_
recurrent - Decode formulation: one token at a time, carrying
state. - kda_
recurrent_ prenorm - Same recurrence, but
q/kare already L2-normalised. - kda_
reference_ layer - End-to-end reference for one KDA layer, from post-conv q/k/v to
o_projoutput. - l2norm_
rows x / sqrt(sum(x^2) + eps)over the trailing dimension.- linear
y = x @ w^Tforx: [m, k],w: [n, k](torchLinearweight layout), no bias.- rms_
norm_ gated - Gated RMSNorm over the trailing
d, strict FP32, sigmoid gate. - unbounded_
gdn_ gate - Unbounded Qwen-GDN gate, kept only so the microtest can show the two laws diverge.