Module glm5next_kda

Module glm5next_kda 

Source
Expand description

2026-09-25: The GLM-5.3-Flash KDA attention block: one bound self_attn block per KDA layer.

Owner: model-arch (GLM-5.3-Flash KDA). Invariants:

q|k|v_proj -> pack -> conv1d + SiLU -> L2(q,k only) -> kda_gate / sigmoid(b_proj)
           -> kda_chunk (prefill) | kda_recurrent (decode)
           -> sigmoid-gated RMSNorm(o_norm, g_b(g_a(h))) -> o_proj
  • The binder accepts only BF16 and F32 tensors (binding::KDA_TENSORS), and every projection runs a BF16 kernel, so there is no dequantisation on this path.
  • The checkpoint stores q_conv1d/k_conv1d/v_conv1d separately; the binder concatenates them in q, k, v order, the order front_end packs the projections in.
  • o_norm gates with a sigmoid, not SiLU, so it runs kda_o_norm_gated_bf16 (kernels/gb10/common/kda_layer_ops.cu) rather than gated_rms_norm.
  • dense_mm_bf16 and cublas_bf16_proj_dense take no output row stride, so the three q/k/v projections go to separate [T, qkv] buffers and kda_pack_qkv_bf16 interleaves them.
  • The conv state keeps conv_kernel slots and the conv kernels shift left before convolving; see KdaSeqState.
  • Decode fuses conv, SiLU and L2 in one kernel; prefill runs a separate l2_norm_bf16 over the q|k channels. V is never normalised.

Modules§

binding
2026-09-25: Typed weight binding for the GLM-5.3-Flash KDA attention blocks.
tp
2026-09-25: GLM-5.3-Flash KDA tensor-parallel shard plan: head-parallel, one all-reduce after o_proj.
tp_bind
2026-09-25: Applies a super::tp::KdaTpPlan: slices each KDA tensor to this rank before the binder sees it.

Structs§

Glm5NextKdaConfig
2026-09-25: KDA geometry and the two numeric config values the block uses. The loader fills every field from ModelConfig except l2_eps and chunk; there is no Default.
Glm5NextKdaKernels
Glm5NextKdaLayer
2026-09-25: One bound KDA attention block.
Glm5NextKdaWeights
2026-09-25: One KDA block’s device weights. Torch Linear layout [out, in], BF16, except the two F32 gate parameters. There is no Z tensor; the output gate is low-rank g_a/g_b.
Glm5NextKdaWorkspace
2026-09-25: Scratch for the forward path, sized once for max_tokens (prefill buffers padded to a whole number of chunks). The loader shares one workspace across the KDA layers.
KdaSeqState
2026-09-25: The per-sequence state a KDA layer carries. The kernels update both buffers in place.

Constants§

SMEM_CEILING
2026-09-25: Largest shared memory a prefill chunk may need. Glm5NextKdaConfig::validate refuses a chunk whose smem_prepare or smem_scan exceeds it.