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

This commit is contained in:
Nidhi authored and GitHub committed 2026-11-03 11:11:05 +02:00
1 parent 259d91709d
commit 19e8a86fe8
1 file changed
+19
+19
View File
@@ -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);