Commit 19e8a86fe for llama.cpp

commit 19e8a86fe87e5888f61b3aa975e8634b322bd776
Author: Nidhi <nidhisharma16635@gmail.com>
Date:   Tue Nov 3 14:41:05 2026 +0530

    tools : reject mismatched shards in GGUF split merge (#31579)

diff --git a/tools/gguf-split/gguf-split.cpp b/tools/gguf-split/gguf-split.cpp
index 73587b9fc..962a59ba0 100644
--- a/tools/gguf-split/gguf-split.cpp
+++ b/tools/gguf-split/gguf-split.cpp
@@ -454,6 +454,17 @@ static void gguf_merge(const split_params & split_params) {
         ctx_ggufs.push_back(ctx_gguf);
         ctx_metas.push_back(ctx_meta);

+        // Verify that this split belongs to the same set as the first one
+        if (i_split > 0) {
+            auto key_split_no    = gguf_find_key(ctx_gguf, LLM_KV_SPLIT_NO);
+            auto key_split_count = gguf_find_key(ctx_gguf, LLM_KV_SPLIT_COUNT);
+            if (key_split_no < 0 || gguf_get_val_u16(ctx_gguf, key_split_no) != i_split ||
+                key_split_count < 0 || gguf_get_val_u16(ctx_gguf, key_split_count) != n_split) {
+                fprintf(stderr, "\n%s: %s is not split %d of %d\n", __func__, split_path, i_split + 1, n_split);
+                exit(EXIT_FAILURE);
+            }
+        }
+
         if (i_split == 0) {
             auto key_n_split = gguf_find_key(ctx_gguf, LLM_KV_SPLIT_COUNT);
             if (key_n_split < 0) {
@@ -508,6 +519,14 @@ static void gguf_merge(const split_params & split_params) {

         fprintf(stderr, "\033[3Ddone\n");
     }
+
+    // Verify that no tensor is missing
+    auto key_n_tensors = gguf_find_key(ctx_ggufs[0], LLM_KV_SPLIT_TENSORS_COUNT);
+    if (key_n_tensors < 0 || gguf_get_val_i32(ctx_ggufs[0], key_n_tensors) != total_tensors) {
+        fprintf(stderr, "%s: splits contain %d tensors, which does not match %s\n", __func__, total_tensors, LLM_KV_SPLIT_TENSORS_COUNT);
+        exit(EXIT_FAILURE);
+    }
+
     std::ofstream fout;
     if (!split_params.dry_run) {
         fout.open(split_params.output.c_str(), std::ios::binary);