Skip to content

Commit 08ef054

Browse files
committed
llama : expose n_head and allow setting rope_freq_base
This is useful for supporting dynamic NTK in code that uses llama.cpp.
1 parent f3b2698 commit 08ef054

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llama.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8718,6 +8718,10 @@ int llama_n_embd(const struct llama_model * model) {
87188718
return model->hparams.n_embd;
87198719
}
87208720

8721+
int llama_n_head(const struct llama_model * model) {
8722+
return model->hparams.n_head;
8723+
}
8724+
87218725
float llama_rope_freq_scale_train(const struct llama_model * model) {
87228726
return model->hparams.rope_freq_scale_train;
87238727
}
@@ -9621,6 +9625,10 @@ int llama_token_to_piece(const struct llama_model * model, llama_token token, ch
96219625
return 0;
96229626
}
96239627

9628+
void llama_set_rope_freq_base(struct llama_context * ctx, float freq) {
9629+
ctx->cparams.rope_freq_base = freq;
9630+
}
9631+
96249632
struct llama_timings llama_get_timings(struct llama_context * ctx) {
96259633
struct llama_timings result = {
96269634
/*.t_start_ms =*/ 1e-3 * ctx->t_start_us,

llama.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ extern "C" {
297297
LLAMA_API int llama_n_vocab (const struct llama_model * model);
298298
LLAMA_API int llama_n_ctx_train(const struct llama_model * model);
299299
LLAMA_API int llama_n_embd (const struct llama_model * model);
300+
LLAMA_API int llama_n_head (const struct llama_model * model);
300301

301302
// Get the model's RoPE frequency scaling factor
302303
LLAMA_API float llama_rope_freq_scale_train(const struct llama_model * model);
@@ -626,6 +627,9 @@ extern "C" {
626627
char * buf,
627628
int length);
628629

630+
// Sets rope_freq_base of llama context
631+
LLAMA_API void llama_set_rope_freq_base(struct llama_context * ctx, float freq);
632+
629633
//
630634
// Grammar
631635
//

0 commit comments

Comments
 (0)