Skip to content

llama : let context be const when accessing const data #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ int llama_apply_lora_from_file(struct llama_context * ctx, const char * path_lor
}
}

int llama_get_kv_cache_token_count(struct llama_context * ctx) {
int llama_get_kv_cache_token_count(const struct llama_context * ctx) {
return ctx->model.kv_self.n;
}

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

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

int llama_n_vocab(struct llama_context * ctx) {
int llama_n_vocab(const struct llama_context * ctx) {
return ctx->vocab.id_to_token.size();
}

int llama_n_ctx(struct llama_context * ctx) {
int llama_n_ctx(const struct llama_context * ctx) {
return ctx->model.hparams.n_ctx;
}

int llama_n_embd(struct llama_context * ctx) {
int llama_n_embd(const struct llama_context * ctx) {
return ctx->model.hparams.n_embd;
}

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

const char * llama_token_to_str(struct llama_context * ctx, llama_token token) {
const char * llama_token_to_str(const struct llama_context * ctx, llama_token token) {
if (token >= llama_n_vocab(ctx)) {
return nullptr;
}
Expand Down
12 changes: 6 additions & 6 deletions llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ extern "C" {
int n_threads);

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

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

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

// Copies the state to the specified destination address.
// Destination needs to have allocated enough memory.
Expand Down Expand Up @@ -164,9 +164,9 @@ extern "C" {
int n_max_tokens,
bool add_bos);

LLAMA_API int llama_n_vocab(struct llama_context * ctx);
LLAMA_API int llama_n_ctx (struct llama_context * ctx);
LLAMA_API int llama_n_embd (struct llama_context * ctx);
LLAMA_API int llama_n_vocab(const struct llama_context * ctx);
LLAMA_API int llama_n_ctx (const struct llama_context * ctx);
LLAMA_API int llama_n_embd (const struct llama_context * ctx);

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

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

// Special tokens
LLAMA_API llama_token llama_token_bos();
Expand Down