Skip to content

Commit a4a6d95

Browse files
committed
Merge branch 'hp/split/load-model' into hp/split/load-model-from-url
# Conflicts: # examples/gguf-split/gguf-split.cpp
2 parents d88d66b + e474e45 commit a4a6d95

File tree

5 files changed

+213
-217
lines changed

5 files changed

+213
-217
lines changed

common/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ struct llama_model * llama_load_model_from_url(const char * model_url, const cha
18881888
return NULL;
18891889
}
18901890

1891-
auto key_n_split = gguf_find_key(ctx_gguf, LLM_KV_GENERAL_SPLIT_N_SPLIT);
1891+
auto key_n_split = gguf_find_key(ctx_gguf, LLM_KV_SPLIT_COUNT);
18921892
if (key_n_split >= 0) {
18931893
n_split = gguf_get_val_u16(ctx_gguf, key_n_split);
18941894
}
@@ -1907,7 +1907,7 @@ struct llama_model * llama_load_model_from_url(const char * model_url, const cha
19071907
char split_path[PATH_MAX] = {0};
19081908
strncpy(split_path, path_model, sizeof(split_path) - 1);
19091909
char split_prefix[PATH_MAX] = {0};
1910-
if (!llama_split_prefix(split_prefix, split_path, strlen(split_path), 0, n_split)) {
1910+
if (!llama_split_prefix(split_prefix, sizeof(split_prefix), split_path, 0, n_split)) {
19111911
fprintf(stderr, "\n%s: unexpected input file name: %s"
19121912
" n_split=%d\n", __func__, split_path, n_split);
19131913
return NULL;

common/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,5 @@ llama_control_vector_data llama_control_vector_load(const std::vector<llama_cont
306306
//
307307
// Split utils
308308
//
309-
static const char * const LLM_KV_GENERAL_SPLIT_I_SPLIT = "split.no";
310-
static const char * const LLM_KV_GENERAL_SPLIT_N_SPLIT = "split.count";
309+
static const char * const LLM_KV_SPLIT_NO = "split.no";
310+
static const char * const LLM_KV_SPLIT_COUNT = "split.count";

examples/gguf-split/gguf-split.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum split_operation : uint8_t {
2626
SPLIT_OP_MERGE,
2727
};
2828

29-
static const char * const LLM_KV_GENERAL_SPLIT_N_TENSORS = "split.tensors.count";
29+
static const char * const LLM_KV_SPLIT_TENSORS_COUNT = "split.tensors.count";
3030

3131
struct split_params {
3232
split_operation operation = SPLIT_OP_SPLIT;
@@ -175,9 +175,9 @@ struct split_strategy {
175175
if (i_split == 0) {
176176
gguf_set_kv(ctx_out, ctx_gguf);
177177
}
178-
gguf_set_val_u16(ctx_out, LLM_KV_GENERAL_SPLIT_I_SPLIT, i_split);
179-
gguf_set_val_u16(ctx_out, LLM_KV_GENERAL_SPLIT_N_SPLIT, n_split);
180-
gguf_set_val_i32(ctx_out, LLM_KV_GENERAL_SPLIT_N_TENSORS,n_tensors);
178+
gguf_set_val_u16(ctx_out, LLM_KV_SPLIT_NO, i_split);
179+
gguf_set_val_u16(ctx_out, LLM_KV_SPLIT_COUNT, n_split);
180+
gguf_set_val_i32(ctx_out, LLM_KV_SPLIT_TENSORS_COUNT, n_tensors);
181181

182182
// populate the original tensors, so we get an initial metadata
183183
for (int i = i_split * params.n_split_tensors; i < n_tensors && i < (i_split + 1) * params.n_split_tensors; ++i) {
@@ -326,12 +326,12 @@ static void gguf_merge(const split_params & split_params) {
326326
ctx_metas.push_back(ctx_meta);
327327

328328
if (i_split == 0) {
329-
auto key_n_split = gguf_find_key(ctx_gguf, LLM_KV_GENERAL_SPLIT_N_SPLIT);
329+
auto key_n_split = gguf_find_key(ctx_gguf, LLM_KV_SPLIT_COUNT);
330330
if (key_n_split < 0) {
331331
fprintf(stderr,
332332
"\n%s: input file does not contain %s metadata\n",
333333
__func__,
334-
LLM_KV_GENERAL_SPLIT_N_SPLIT);
334+
LLM_KV_SPLIT_COUNT);
335335
gguf_free(ctx_gguf);
336336
ggml_free(ctx_meta);
337337
gguf_free(ctx_out);
@@ -353,7 +353,7 @@ static void gguf_merge(const split_params & split_params) {
353353
}
354354

355355
// Verify the file naming and extract split_prefix
356-
if (!llama_split_prefix(split_prefix, split_path, strlen(split_path), i_split, n_split)) {
356+
if (!llama_split_prefix(split_prefix, sizeof (split_prefix), split_path, i_split, n_split)) {
357357
fprintf(stderr, "\n%s: unexpected input file name: %s"
358358
" i_split=%d"
359359
" n_split=%d\n", __func__,
@@ -366,7 +366,7 @@ static void gguf_merge(const split_params & split_params) {
366366
}
367367

368368
// Do not trigger merge if we try to merge again the output
369-
gguf_set_val_u16(ctx_gguf, LLM_KV_GENERAL_SPLIT_N_SPLIT, 0);
369+
gguf_set_val_u16(ctx_gguf, LLM_KV_SPLIT_COUNT, 0);
370370

371371
// Set metadata from the first split
372372
gguf_set_kv(ctx_out, ctx_gguf);

0 commit comments

Comments
 (0)