Skip to content

Commit ed6dcaf

Browse files
glm-dsa : fix missing indexer tensors on sparse-indexer blocks
GLM-5.2 only has DSA lightning indexer tensors on a subset of blocks: the 3 dense-lead blocks (0-2) and every 4th MoE block (6, 10, 14, ..., 78). The remaining MoE blocks have no indexer tensors at all. glm-dsa.cpp required them on every block, so loading failed with: "missing tensor 'blk.3.indexer.k_norm.weight'" Two changes: - glm-dsa.cpp: mark all 5 indexer tensor creates as TENSOR_NOT_REQUIRED - deepseek32.cpp: guard the lightning indexer block with a null check on indexer_attn_q_b; when absent, top_k stays nullptr and build_attn_mla falls back to full attention for that layer Regressed in ggml-org#23346 (2026-05-29) which wired the DSA lightning indexer into the shared deepseek2 graph used by GLM_DSA. Before that PR the indexer tensors were loaded but never accessed in the graph. Assisted-by: Claude Sonnet
1 parent 22ea8d8 commit ed6dcaf

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/models/deepseek32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ llama_model_deepseek32::graph::graph(const llama_model & model, const llm_graph_
219219

220220
ggml_tensor * top_k = nullptr;
221221

222-
// lightning indexer
223-
{
222+
// lightning indexer - skipped when tensors are absent (e.g. GLM-5.2 only has them on certain blocks)
223+
if (model.layers[il].indexer_attn_q_b) {
224224
ggml_tensor * indexer_q = ggml_mul_mat(ctx0, model.layers[il].indexer_attn_q_b, qr);
225225
cb(indexer_q, "indexer_q", il);
226226

src/models/glm-dsa.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,13 @@ void llama_model_glm_dsa::load_arch_tensors(llama_model_loader &) {
100100

101101
layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), {n_embd}, flags);
102102

103-
// DSA indexer
104-
layer.indexer_k_norm = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "weight", i), {hparams.indexer_head_size}, flags);
105-
layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "bias", i), {hparams.indexer_head_size}, flags);
106-
layer.indexer_proj = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ, "weight", i), {n_embd, hparams.indexer_n_head}, flags);
107-
layer.indexer_attn_k = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K, "weight", i), {n_embd, hparams.indexer_head_size}, flags);
108-
layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, "weight", i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags);
103+
// DSA indexer - only present on a subset of blocks (dense-lead blocks + every 4th MoE block),
104+
// so mark all as TENSOR_NOT_REQUIRED; the graph skips the indexer path when these are null.
105+
layer.indexer_k_norm = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "weight", i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
106+
layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "bias", i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
107+
layer.indexer_proj = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ, "weight", i), {n_embd, hparams.indexer_n_head}, flags | TENSOR_NOT_REQUIRED);
108+
layer.indexer_attn_k = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K, "weight", i), {n_embd, hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
109+
layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, "weight", i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
109110
if (i < (int) hparams.n_layer_dense_lead) {
110111
layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd, n_ff}, flags);
111112
layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), { n_ff, n_embd}, flags);

0 commit comments

Comments
 (0)