Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion requirements/requirements-convert_legacy_llama.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
numpy~=1.26.4
sentencepiece>=0.1.98,<0.3.0

transformers==4.57.6
# GLM-5.2 and other recent models require transformers 5.x; the TokenizersBackend class
# referenced in their tokenizer_config.json does not exist in 4.x
transformers>=5.0.0

gguf>=0.1.0
protobuf>=4.21.0,<5.0.0
6 changes: 5 additions & 1 deletion src/llama-quant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ static void init_quantize_state_counters(quantize_state_impl & qs, std::vector<t
qs.has_tied_embeddings = false;
}
}
qs.n_ffn_down = qs.n_ffn_gate = qs.n_ffn_up = (int)qs.model.hparams.n_layer();
// Use n_layer_all, not n_layer(), because models with nextn/MTP blocks (e.g. GLM-5.2,
// BailingMoE2) store ffn_down/gate/up_exps tensors for those extra blocks in the GGUF
// file. The MoE path in layer_info() parses the block index from the tensor name, so
// those tensors would exceed the bounds set by n_layer() = n_layer_all - n_layer_nextn.
qs.n_ffn_down = qs.n_ffn_gate = qs.n_ffn_up = (int)qs.model.hparams.n_layer_all;
}

//
Expand Down
4 changes: 2 additions & 2 deletions src/models/deepseek32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ llama_model_deepseek32::graph::graph(const llama_model & model, const llm_graph_

ggml_tensor * top_k = nullptr;

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

Expand Down
13 changes: 7 additions & 6 deletions src/models/glm-dsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ void llama_model_glm_dsa::load_arch_tensors(llama_model_loader &) {

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

// DSA indexer
layer.indexer_k_norm = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "weight", i), {hparams.indexer_head_size}, flags);
layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "bias", i), {hparams.indexer_head_size}, flags);
layer.indexer_proj = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ, "weight", i), {n_embd, hparams.indexer_n_head}, flags);
layer.indexer_attn_k = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K, "weight", i), {n_embd, hparams.indexer_head_size}, flags);
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);
// DSA indexer - only present on a subset of blocks (dense-lead blocks + every 4th MoE block),
// so mark all as TENSOR_NOT_REQUIRED; the graph skips the indexer path when these are null.
layer.indexer_k_norm = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "weight", i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM, "bias", i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
layer.indexer_proj = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ, "weight", i), {n_embd, hparams.indexer_n_head}, flags | TENSOR_NOT_REQUIRED);
layer.indexer_attn_k = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K, "weight", i), {n_embd, hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
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);
if (i < (int) hparams.n_layer_dense_lead) {
layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd, n_ff}, flags);
layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), { n_ff, n_embd}, flags);
Expand Down
Loading