Skip to content

remove token functions with context args in favor of model #3720

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 10 commits into from
Oct 23, 2023
28 changes: 28 additions & 0 deletions llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9669,29 +9669,57 @@ llama_token llama_token_bos(const struct llama_context * ctx) {
return ctx->model.vocab.special_bos_id;
}

llama_token llama_model_token_bos(const struct llama_model * model) {
return model->vocab.special_bos_id;
}

llama_token llama_token_eos(const struct llama_context * ctx) {
return ctx->model.vocab.special_eos_id;
}

llama_token llama_model_token_eos(const struct llama_model * model) {
return model->vocab.special_eos_id;
}

llama_token llama_token_nl(const struct llama_context * ctx) {
return ctx->model.vocab.linefeed_id;
}

llama_token llama_model_token_nl(const struct llama_model * model) {
return model->vocab.linefeed_id;
}
llama_token llama_token_prefix(const struct llama_context * ctx) {
return ctx->model.vocab.special_prefix_id;
}

llama_token llama_model_token_prefix(const struct llama_model * model) {
return model->vocab.special_prefix_id;
}

llama_token llama_token_middle(const struct llama_context * ctx) {
return ctx->model.vocab.special_middle_id;
}

llama_token llama_model_token_middle(const struct llama_model * model) {
return model->vocab.special_middle_id;
}

llama_token llama_token_suffix(const struct llama_context * ctx) {
return ctx->model.vocab.special_suffix_id;
}

llama_token llama_model_token_suffix(const struct llama_model * model) {
return model->vocab.special_suffix_id;
}

llama_token llama_token_eot(const struct llama_context * ctx) {
return ctx->model.vocab.special_eot_id;
}

llama_token llama_model_token_eot(const struct llama_model * model) {
return model->vocab.special_eot_id;
}

int llama_tokenize(
const struct llama_model * model,
const char * text,
Expand Down
10 changes: 10 additions & 0 deletions llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,22 @@ extern "C" {
LLAMA_API llama_token llama_token_bos(const struct llama_context * ctx); // beginning-of-sentence
LLAMA_API llama_token llama_token_eos(const struct llama_context * ctx); // end-of-sentence
LLAMA_API llama_token llama_token_nl (const struct llama_context * ctx); // next-line

LLAMA_API llama_token llama_model_token_bos(const struct llama_model *model);
LLAMA_API llama_token llama_model_token_eos(const struct llama_model *model);
LLAMA_API llama_token llama_model_token_nl(const struct llama_model *model);

// codellama infill tokens
LLAMA_API llama_token llama_token_prefix(const struct llama_context * ctx); // Beginning of infill prefix
LLAMA_API llama_token llama_token_middle(const struct llama_context * ctx); // Beginning of infill middle
LLAMA_API llama_token llama_token_suffix(const struct llama_context * ctx); // Beginning of infill suffix
LLAMA_API llama_token llama_token_eot (const struct llama_context * ctx); // End of infill middle

LLAMA_API llama_token llama_model_token_prefix(const struct llama_model * model);
LLAMA_API llama_token llama_model_token_middle(const struct llama_model * model);
LLAMA_API llama_token llama_model_token_suffix(const struct llama_model * model);
LLAMA_API llama_token llama_model_token_eot (const struct llama_model * model);

//
// Tokenization
//
Expand Down