Skip to content

Commit 90b19bd

Browse files
authored
llama : let context be const when accessing const data (#1261)
1 parent 7ff0dcd commit 90b19bd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

llama.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ int llama_apply_lora_from_file(struct llama_context * ctx, const char * path_lor
23732373
}
23742374
}
23752375

2376-
int llama_get_kv_cache_token_count(struct llama_context * ctx) {
2376+
int llama_get_kv_cache_token_count(const struct llama_context * ctx) {
23772377
return ctx->model.kv_self.n;
23782378
}
23792379

@@ -2387,7 +2387,7 @@ void llama_set_rng_seed(struct llama_context * ctx, int seed) {
23872387
}
23882388

23892389
// Returns the size of the state
2390-
size_t llama_get_state_size(struct llama_context * ctx) {
2390+
size_t llama_get_state_size(const struct llama_context * ctx) {
23912391
// we don't know size of rng until we actually serialize it. so reserve more than enough memory for its serialized state.
23922392
// for reference, std::mt19937(1337) serializes to 6701 bytes.
23932393
const size_t s_rng_size = sizeof(size_t);
@@ -2605,15 +2605,15 @@ int llama_tokenize(
26052605
return res.size();
26062606
}
26072607

2608-
int llama_n_vocab(struct llama_context * ctx) {
2608+
int llama_n_vocab(const struct llama_context * ctx) {
26092609
return ctx->vocab.id_to_token.size();
26102610
}
26112611

2612-
int llama_n_ctx(struct llama_context * ctx) {
2612+
int llama_n_ctx(const struct llama_context * ctx) {
26132613
return ctx->model.hparams.n_ctx;
26142614
}
26152615

2616-
int llama_n_embd(struct llama_context * ctx) {
2616+
int llama_n_embd(const struct llama_context * ctx) {
26172617
return ctx->model.hparams.n_embd;
26182618
}
26192619

@@ -2625,7 +2625,7 @@ float * llama_get_embeddings(struct llama_context * ctx) {
26252625
return ctx->embedding.data();
26262626
}
26272627

2628-
const char * llama_token_to_str(struct llama_context * ctx, llama_token token) {
2628+
const char * llama_token_to_str(const struct llama_context * ctx, llama_token token) {
26292629
if (token >= llama_n_vocab(ctx)) {
26302630
return nullptr;
26312631
}

llama.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ extern "C" {
120120
int n_threads);
121121

122122
// Returns the number of tokens in the KV cache
123-
LLAMA_API int llama_get_kv_cache_token_count(struct llama_context * ctx);
123+
LLAMA_API int llama_get_kv_cache_token_count(const struct llama_context * ctx);
124124

125125
// Sets the current rng seed.
126126
LLAMA_API void llama_set_rng_seed(struct llama_context * ctx, int seed);
127127

128128
// Returns the size in bytes of the state (rng, logits, embedding and kv_cache)
129-
LLAMA_API size_t llama_get_state_size(struct llama_context * ctx);
129+
LLAMA_API size_t llama_get_state_size(const struct llama_context * ctx);
130130

131131
// Copies the state to the specified destination address.
132132
// Destination needs to have allocated enough memory.
@@ -164,9 +164,9 @@ extern "C" {
164164
int n_max_tokens,
165165
bool add_bos);
166166

167-
LLAMA_API int llama_n_vocab(struct llama_context * ctx);
168-
LLAMA_API int llama_n_ctx (struct llama_context * ctx);
169-
LLAMA_API int llama_n_embd (struct llama_context * ctx);
167+
LLAMA_API int llama_n_vocab(const struct llama_context * ctx);
168+
LLAMA_API int llama_n_ctx (const struct llama_context * ctx);
169+
LLAMA_API int llama_n_embd (const struct llama_context * ctx);
170170

171171
// Token logits obtained from the last call to llama_eval()
172172
// The logits for the last token are stored in the last row
@@ -180,7 +180,7 @@ extern "C" {
180180
LLAMA_API float * llama_get_embeddings(struct llama_context * ctx);
181181

182182
// Token Id -> String. Uses the vocabulary in the provided context
183-
LLAMA_API const char * llama_token_to_str(struct llama_context * ctx, llama_token token);
183+
LLAMA_API const char * llama_token_to_str(const struct llama_context * ctx, llama_token token);
184184

185185
// Special tokens
186186
LLAMA_API llama_token llama_token_bos();

0 commit comments

Comments
 (0)