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
8 changes: 6 additions & 2 deletions src/llama-arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,10 @@ static const std::map<llm_tensor, llm_tensor_info> LLM_TENSOR_INFOS = {
{LLM_TENSOR_DFLASH_SELECTOR_HIDDEN, {LLM_TENSOR_LAYER_OUTPUT, GGML_OP_MUL_MAT}},
};

LLM_KV::LLM_KV(llm_arch arch, const char * suffix) : arch(arch), suffix(suffix) {}
LLM_KV::LLM_KV(llm_arch arch, const char * suffix, const char * prefix) : arch(arch), suffix(suffix), prefix(prefix) {}

std::string LLM_KV::operator()(llm_kv kv) const {
std::string name = ::format(LLM_KV_NAMES.at(kv), LLM_ARCH_NAMES.at(arch));
std::string name = ::format(LLM_KV_NAMES.at(kv), prefix ? prefix : LLM_ARCH_NAMES.at(arch));

if (suffix != nullptr) {
name += ".";
Expand Down Expand Up @@ -1069,6 +1069,10 @@ llm_arch llm_arch_from_string(const std::string & name) {
}
}

if (name == "glm5next") { // pre-upstream converter
return LLM_ARCH_GLM5_NEXT;
Comment on lines +1072 to +1073

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add regression tests for the legacy metadata aliases

This compatibility fix has no automated regression coverage for either affected path: loading a model whose architecture and hyperparameter prefix are glm5next, or loading an mmproj that uses projector type glm5next, swiglu_limit, and no pixel-budget keys. Existing architecture and mtmd tests can still pass if either alias path stops working, so add synthetic legacy-metadata cases that fail on the parent commit and verify both loaders.

Useful? React with 👍 / 👎.

Comment on lines +1072 to +1073

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Canonicalize the alias before creating architecture filters

When test-llama-archs is invoked with --arch glm5next, this new branch makes llm_arch_from_string() report a known architecture, so the argument parser builds the exact filter ^glm5next$. The test cases are matched against llm_arch_name(LLM_ARCH_GLM5_NEXT), which is glm5-next, so both normal and --save modes select zero cases and exit successfully. Return or expose the canonical name to exact-filter callers instead of making the alias appear canonical.

Useful? React with 👍 / 👎.

}

return LLM_ARCH_UNKNOWN;
}

Expand Down
3 changes: 2 additions & 1 deletion src/llama-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,11 @@ enum llm_tensor_layer {
};

struct LLM_KV {
LLM_KV(llm_arch arch, const char * suffix = nullptr);
LLM_KV(llm_arch arch, const char * suffix = nullptr, const char * prefix = nullptr);

llm_arch arch;
const char * suffix;
const char * prefix; // KV prefix as written in the file (differs from the arch name for legacy names)

std::string operator()(llm_kv kv) const;
};
Expand Down
6 changes: 3 additions & 3 deletions src/llama-model-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ llama_model_loader::llama_model_loader(
}

get_key(llm_kv(LLM_KV_GENERAL_ARCHITECTURE), arch_name, false);
llm_kv = LLM_KV(llm_arch_from_string(arch_name));
llm_kv = LLM_KV(llm_arch_from_string(arch_name), nullptr, arch_name.c_str());

files.emplace_back(new llama_file(fname.c_str(), "rb", use_direct_io));
contexts.emplace_back(ctx);
Expand Down Expand Up @@ -693,7 +693,7 @@ llama_model_loader::llama_model_loader(
}

get_key(llm_kv(LLM_KV_GENERAL_ARCHITECTURE), arch_name, false);
llm_kv = LLM_KV(llm_arch_from_string(arch_name));
llm_kv = LLM_KV(llm_arch_from_string(arch_name), nullptr, arch_name.c_str());

files.emplace_back(new llama_file(file));
contexts.emplace_back(ctx);
Expand All @@ -711,7 +711,7 @@ llama_model_loader::llama_model_loader(
}
} else {
get_key(llm_kv(LLM_KV_GENERAL_ARCHITECTURE), arch_name, false);
llm_kv = LLM_KV(llm_arch_from_string(arch_name));
llm_kv = LLM_KV(llm_arch_from_string(arch_name), nullptr, arch_name.c_str());
}

n_kv = gguf_get_n_kv(metadata);
Expand Down
3 changes: 3 additions & 0 deletions tools/mtmd/clip-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ static projector_type clip_projector_type_from_string(const std::string & str) {
return pair.first;
}
}
if (str == "glm5next") { // pre-upstream converter
return PROJECTOR_TYPE_GLM5V;
}
return PROJECTOR_TYPE_UNKNOWN;
}

Expand Down
10 changes: 7 additions & 3 deletions tools/mtmd/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,9 +1779,13 @@ struct clip_model_loader {
hparams.n_merge = 2;
hparams.image_resize_algo = RESIZE_ALGO_BICUBIC;
get_u32(KEY_SPATIAL_MERGE_SIZE, hparams.n_merge, false);
get_f32(KEY_SWIGLU_CLAMP, hparams.swiglu_clamp, true);
get_u32(KEY_IMAGE_MIN_PIXELS, hparams.image_min_pixels);
get_u32(KEY_IMAGE_MAX_PIXELS, hparams.image_max_pixels);
// pre-upstream files: swiglu_limit, no pixel budget keys
const bool legacy = gguf_find_key(ctx_gguf.get(), KEY_SWIGLU_CLAMP) < 0;
get_f32(legacy ? "clip.vision.swiglu_limit" : KEY_SWIGLU_CLAMP, hparams.swiglu_clamp, true);
hparams.image_min_pixels = 12544;
hparams.image_max_pixels = 6272000;
get_u32(KEY_IMAGE_MIN_PIXELS, hparams.image_min_pixels, !legacy);
get_u32(KEY_IMAGE_MAX_PIXELS, hparams.image_max_pixels, !legacy);
hparams.set_limit_image_tokens();
hparams.set_warmup_n_tokens(46*46); // avoid OOM on warmup
} break;
Expand Down