From 9900b29c3abc5fa0b70dd5a3a68696912250d69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 26 Mar 2026 15:37:18 +0100 Subject: [PATCH] common : filter out imatrix when finding models (#21023) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- common/download.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/common/download.cpp b/common/download.cpp index fa2e6fb280..fce5cda88e 100644 --- a/common/download.cpp +++ b/common/download.cpp @@ -548,6 +548,20 @@ static hf_cache::hf_file find_best_mmproj(const hf_cache::hf_files & files, return best; } +static bool gguf_filename_is_model(const std::string & filepath) { + if (!string_ends_with(filepath, ".gguf")) { + return false; + } + + std::string filename = filepath; + if (auto pos = filename.rfind('/'); pos != std::string::npos) { + filename = filename.substr(pos + 1); + } + + return filename.find("mmproj") == std::string::npos && + filename.find("imatrix") == std::string::npos; +} + static hf_cache::hf_file find_best_model(const hf_cache::hf_files & files, const std::string & tag) { std::vector tags; @@ -561,8 +575,7 @@ static hf_cache::hf_file find_best_model(const hf_cache::hf_files & files, for (const auto & t : tags) { std::regex pattern(t + "[.-]", std::regex::icase); for (const auto & f : files) { - if (string_ends_with(f.path, ".gguf") && - f.path.find("mmproj") == std::string::npos && + if (gguf_filename_is_model(f.path) && std::regex_search(f.path, pattern)) { return f; } @@ -570,8 +583,7 @@ static hf_cache::hf_file find_best_model(const hf_cache::hf_files & files, } for (const auto & f : files) { - if (string_ends_with(f.path, ".gguf") && - f.path.find("mmproj") == std::string::npos) { + if (gguf_filename_is_model(f.path)) { return f; } }