Skip to content

Commit 839fc6d

Browse files
committed
handle freq_base_train
1 parent 6a4d9c2 commit 839fc6d

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

gpttype_adapter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
606606
rope_freq_base = (effectivenctx <= 2048 ? 10000.0f : (effectivenctx <= 3072 ? 26000.0f : (effectivenctx <= 4096 ? 32000.0f : (effectivenctx <= 6144 ? 54000.0f :
607607
(effectivenctx <= 8192 ? 82684.0f : (effectivenctx <= 12288 ? 140000.0f : (effectivenctx <= 16384 ? 200000.0f : (effectivenctx <= 24576 ? 320000.0f : 440000.0f))))))));
608608

609+
if(file_format_meta.freq_base_train > rope_freq_base)
610+
{
611+
rope_freq_base = file_format_meta.freq_base_train;
612+
}
609613
}
610614

611615
printf("Using automatic RoPE scaling (scale:%.3f, base:%.1f)\n",rope_freq_scale,rope_freq_base);

model_adapter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ void print_tok_vec(std::vector<float> &embd)
290290
}
291291
int filever = gguf_get_version(ctx);
292292
fileformatmeta->fileversion = filever;
293+
294+
//try to adapt if the rope_freq_base_train exceeds the auto one
295+
fkey = modelarch+".rope.freq_base";
296+
auto keyidx = gguf_find_key(ctx, fkey.c_str());
297+
if (keyidx != -1) {
298+
float fbt = gguf_get_val_f32(ctx, keyidx);
299+
fileformatmeta->freq_base_train = (fbt > 1.0f ? fbt : 0.0f);
300+
}
293301
}
294302
gguf_free(ctx);
295303
}

model_adapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct FileFormatExtraMeta
5555
{
5656
int n_ctx_train = 2048;
5757
int fileversion = 0;
58+
float freq_base_train = 0;
5859
};
5960

6061
enum ModelLoadResult

0 commit comments

Comments
 (0)