llama : fix segfault from unknown model arch name

This commit is contained in:
Francis Couture-Harpin 2024-03-01 10:32:38 -05:00
parent cb5e8f7fc4
commit 3b257f8867

View file

@ -809,6 +809,16 @@ static std::map<llm_arch, std::map<llm_tensor, std::string>> LLM_TENSOR_NAMES =
static llm_arch llm_arch_from_string(const std::string & name) { static llm_arch llm_arch_from_string(const std::string & name) {
for (const auto & kv : LLM_ARCH_NAMES) { // NOLINT for (const auto & kv : LLM_ARCH_NAMES) { // NOLINT
if (kv.second == nullptr) {
// LLM_ARCH_UNKNOWN does not have a name,
// but is somehow still in the LLM_ARCH_NAMES map.
if (kv.first == LLM_ARCH_UNKNOWN) {
// skip string comparison
continue;
}
// known architectures should always have a name
GGML_ASSERT(false && "missing architecture in LLM_ARCH_NAMES");
}
if (kv.second == name) { if (kv.second == name) {
return kv.first; return kv.first;
} }