Commit ef708d40d for llama.cpp

commit ef708d40d279b64536dc80cbdcd039ae28bbafda
Author: Georgi Gerganov <ggerganov@gmail.com>
Date:   Fri Dec 4 15:41:23 2026 +0200

    common : recognize Q4_K in the -hf default quant preference (#33686)

    Repos shipping a bare Q4_K quant next to Q8_0 fell through to Q8_0
    by default, since only Q4_K_M and Q8_0 were in the preference list.
    Try Q4_K between the two; the tag still matches as a full token, so
    Q4_K never picks a Q4_K_M file and vice versa.

    Assisted-by: dsh:llama.cpp/ggml-org/Qwen3.8-Flash-Next-GGUF (RTX 5090 32GB, DDR5 128GB)

diff --git a/common/download.cpp b/common/download.cpp
index 4dabaedb5..c2841b264 100644
--- a/common/download.cpp
+++ b/common/download.cpp
@@ -774,7 +774,7 @@ static hf_cache::hf_file find_best_model(const hf_cache::hf_files & files,
     if (!tag.empty()) {
         tags.push_back(tag);
     } else {
-        tags = {"Q4_K_M", "Q8_0"};
+        tags = {"Q4_K_M", "Q4_K", "Q8_0"};
     }

     for (const auto & t : tags) {
diff --git a/tests/test-model-resolution.cpp b/tests/test-model-resolution.cpp
index e2576a1c9..b2d8a0135 100644
--- a/tests/test-model-resolution.cpp
+++ b/tests/test-model-resolution.cpp
@@ -161,6 +161,19 @@ static const std::vector<std::string> twins = {
     "model-Q4_XS.gguf",
 };

+// a repo shipping Q4_K next to Q8_0, in the style of ggml-org/GLM-4.7-Flash-GGUF
+static const std::vector<std::string> q4k = {
+    "model-BF16.gguf",
+    "model-Q4_K.gguf",
+    "model-Q8_0.gguf",
+};
+
+// Q4_K and Q4_K_M side by side, the tag must not cross the token
+static const std::vector<std::string> kq = {
+    "model-Q4_K.gguf",
+    "model-Q4_K_M.gguf",
+};
+
 // every speculative sidecar type at the same quant
 static const std::vector<std::string> quad = {
     "model-Q8_0.gguf",
@@ -295,6 +308,26 @@ static const plan_case plan_cases[] = {
      "model-IQ4_XS.gguf", {"model-IQ4_XS.gguf"},
      "", "", "", "", ""},

+    // the default preference falls to Q4_K when the repo ships no Q4_K_M
+    {"q4k default", q4k, "test/repo", "", false, false,
+     "model-Q4_K.gguf", {"model-Q4_K.gguf"},
+     "", "", "", "", ""},
+
+    // the Q4_K tag picks the Q4_K file
+    {"q4k tag", q4k, "test/repo:Q4_K", "", false, false,
+     "model-Q4_K.gguf", {"model-Q4_K.gguf"},
+     "", "", "", "", ""},
+
+    // Q4_K_M keeps the default over a Q4_K file of the same repo
+    {"kq default", kq, "test/repo", "", false, false,
+     "model-Q4_K_M.gguf", {"model-Q4_K_M.gguf"},
+     "", "", "", "", ""},
+
+    // the Q4_K tag matches the full token, never the Q4_K_M file
+    {"kq q4_k tag", kq, "test/repo:Q4_K", "", false, false,
+     "model-Q4_K.gguf", {"model-Q4_K.gguf"},
+     "", "", "", "", ""},
+
     // every sidecar type resolves at the tag
     {"quad exact tag", quad, "test/repo:Q8_0", "", true, false,
      "model-Q8_0.gguf", {"model-Q8_0.gguf"},
@@ -665,7 +698,7 @@ static const real_repo real_repos[] = {
       {"audio-flamingo-next-q4_k.gguf"},
       {"audio-flamingo-next-q8_0.gguf"}},
      {
-      {"", "audio-flamingo-3-q8_0.gguf", 1, "", "", "", "", ""},
+      {"", "audio-flamingo-3-q4_k.gguf", 1, "", "", "", "", ""},
       {"Q8_0", "audio-flamingo-3-q8_0.gguf", 1, "", "", "", "", ""},
       {"BF16", "audio-flamingo-3-bf16.gguf", 1, "", "", "", "", ""}},
      {"Q8_0", "Q4_K", "BF16"}},
@@ -1198,7 +1231,7 @@ static const real_repo real_repos[] = {
      {{"GLM-4.7-Flash-Q4_K.gguf"},
       {"GLM-4.7-Flash-Q8_0.gguf"}},
      {
-      {"", "GLM-4.7-Flash-Q8_0.gguf", 1, "", "", "", "", ""},
+      {"", "GLM-4.7-Flash-Q4_K.gguf", 1, "", "", "", "", ""},
       {"Q8_0", "GLM-4.7-Flash-Q8_0.gguf", 1, "", "", "", "", ""},
       {"Q4_K", "GLM-4.7-Flash-Q4_K.gguf", 1, "", "", "", "", ""}},
      {"Q8_0", "Q4_K"}},
@@ -1506,7 +1539,7 @@ static const real_repo real_repos[] = {
       {"Agents-A1-abliterated-bf16.gguf"},
       {"mmproj-model-bf16.gguf"}},
      {
-      {"", "Agents-A1-abliterated-Q8_0.gguf", 1, "mmproj-model-bf16.gguf", "", "", "", ""},
+      {"", "Agents-A1-abliterated-Q4_K.gguf", 1, "mmproj-model-bf16.gguf", "", "", "", ""},
       {"Q8_0", "Agents-A1-abliterated-Q8_0.gguf", 1, "mmproj-model-bf16.gguf", "", "", "", ""},
       {"Q4_K", "Agents-A1-abliterated-Q4_K.gguf", 1, "mmproj-model-bf16.gguf", "", "", "", ""},
       {"BF16", "Agents-A1-abliterated-bf16.gguf", 1, "mmproj-model-bf16.gguf", "", "", "", ""}},
@@ -2182,7 +2215,7 @@ static const real_repo real_repos[] = {
       {"Spark-X2.5-4B-abliterated-FIT-COMPACT-2.43GiB-Q4_K.gguf"},
       {"Spark-X2.5-4B-abliterated-FIT-QUALITY-3.15GiB-Q6_K.gguf"}},
      {
-      {"", "Spark-X2.5-4B-abliterated-BF16.gguf", 1, "", "", "", "", ""},
+      {"", "Spark-X2.5-4B-abliterated-FIT-COMPACT-2.43GiB-Q4_K.gguf", 1, "", "", "", "", ""},
       {"BF16", "Spark-X2.5-4B-abliterated-BF16.gguf", 1, "", "", "", "", ""},
       {"Q6_K", "Spark-X2.5-4B-abliterated-FIT-QUALITY-3.15GiB-Q6_K.gguf", 1, "", "", "", "", ""}},
      {"Q6_K", "Q4_K", "BF16"}},