Skip to content
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

llama : disambiguate API #9270

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Inference of Meta's [LLaMA](https://arxiv.org/abs/2302.13971) model (and others)

## Recent API changes

- [2024 Sep 02] Rename `llama_xxx_type` to `llama_get_xxx_type` https://github.com/ggerganov/llama.cpp/pull/9270
- [2024 Jun 26] The source code and CMake build scripts have been restructured https://github.com/ggerganov/llama.cpp/pull/8006
- [2024 Apr 21] `llama_token_to_piece` can now optionally render special tokens https://github.com/ggerganov/llama.cpp/pull/6807
- [2024 Apr 4] State and session file functions reorganized under `llama_state_*` https://github.com/ggerganov/llama.cpp/pull/6341
Expand Down
4 changes: 2 additions & 2 deletions examples/embedding/embedding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void batch_add_seq(llama_batch & batch, const std::vector<int32_t> & toke
}

static void batch_decode(llama_context * ctx, llama_batch & batch, float * output, int n_seq, int n_embd, int embd_norm) {
const enum llama_pooling_type pooling_type = llama_pooling_type(ctx);
const enum llama_pooling_type pooling_type = llama_get_pooling_type(ctx);
const struct llama_model * model = llama_get_model(ctx);

// clear previous kv_cache values (irrelevant for embeddings)
Expand Down Expand Up @@ -114,7 +114,7 @@ int main(int argc, char ** argv) {
const int n_ctx_train = llama_n_ctx_train(model);
const int n_ctx = llama_n_ctx(ctx);

const enum llama_pooling_type pooling_type = llama_pooling_type(ctx);
const enum llama_pooling_type pooling_type = llama_get_pooling_type(ctx);

if (llama_model_has_encoder(model) && llama_model_has_decoder(model)) {
fprintf(stderr, "%s: error: computing embeddings in encoder-decoder models is not supported\n", __func__);
Expand Down
2 changes: 1 addition & 1 deletion examples/perplexity/perplexity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ static void hellaswag_score(llama_context * ctx, const gpt_params & params) {
size_t hs_task_count = prompt_lines.size()/6;
fprintf(stderr, "%s : loaded %zu tasks from prompt.\n", __func__, hs_task_count);

const bool is_spm = llama_vocab_type(llama_get_model(ctx)) == LLAMA_VOCAB_TYPE_SPM;
const bool is_spm = llama_get_vocab_type(llama_get_model(ctx)) == LLAMA_VOCAB_TYPE_SPM;
fprintf(stderr, "================================= is_spm = %d\n", is_spm);

// The tasks should be randomized so the score stabilizes quickly.
Expand Down
2 changes: 1 addition & 1 deletion examples/retrieval/retrieval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int main(int argc, char ** argv) {
const int n_ctx_train = llama_n_ctx_train(model);
const int n_ctx = llama_n_ctx(ctx);

const enum llama_pooling_type pooling_type = llama_pooling_type(ctx);
const enum llama_pooling_type pooling_type = llama_get_pooling_type(ctx);
if (pooling_type == LLAMA_POOLING_TYPE_NONE) {
fprintf(stderr, "%s: error: pooling type NONE not supported\n", __func__);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ struct server_context {

json model_meta() const {
return json {
{"vocab_type", llama_vocab_type (model)},
{"vocab_type", llama_get_vocab_type(model)},
{"n_vocab", llama_n_vocab (model)},
{"n_ctx_train", llama_n_ctx_train (model)},
{"n_embd", llama_n_embd (model)},
Expand Down
4 changes: 2 additions & 2 deletions examples/speculative/speculative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ int main(int argc, char ** argv) {
model_dft = llama_init_dft.model;
ctx_dft = llama_init_dft.context;

const bool vocab_type_tgt = llama_vocab_type(model_tgt);
const bool vocab_type_tgt = llama_get_vocab_type(model_tgt);
LOG("vocab_type tgt: %d\n", vocab_type_tgt);

const bool vocab_type_dft = llama_vocab_type(model_dft);
const bool vocab_type_dft = llama_get_vocab_type(model_dft);
LOG("vocab_type dft: %d\n", vocab_type_dft);

if (vocab_type_tgt != vocab_type_dft) {
Expand Down
12 changes: 8 additions & 4 deletions include/llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,14 @@ extern "C" {
LLAMA_API uint32_t llama_n_ubatch (const struct llama_context * ctx);
LLAMA_API uint32_t llama_n_seq_max (const struct llama_context * ctx);

LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx);

LLAMA_API enum llama_vocab_type llama_vocab_type (const struct llama_model * model);
LLAMA_API enum llama_rope_type llama_rope_type (const struct llama_model * model);
LLAMA_API enum llama_pooling_type llama_get_pooling_type(const struct llama_context * ctx);
LLAMA_API enum llama_vocab_type llama_get_vocab_type (const struct llama_model * model);
LLAMA_API enum llama_rope_type llama_get_rope_type (const struct llama_model * model);

// OLD API (use the new API above: https://github.com/ggerganov/llama.cpp/pull/9270)
//LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx);
//LLAMA_API enum llama_vocab_type llama_vocab_type (const struct llama_model * model);
//LLAMA_API enum llama_rope_type llama_rope_type (const struct llama_model * model);

LLAMA_API int32_t llama_n_vocab (const struct llama_model * model);
LLAMA_API int32_t llama_n_ctx_train(const struct llama_model * model);
Expand Down
8 changes: 4 additions & 4 deletions src/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5945,7 +5945,7 @@ static void llm_load_hparams(
hparams.use_alibi = true;
}

hparams.rope_type = llama_rope_type(&model);
hparams.rope_type = llama_get_rope_type(&model);
}

static void llm_load_vocab(
Expand Down Expand Up @@ -18469,11 +18469,11 @@ uint32_t llama_n_seq_max(const struct llama_context * ctx) {
return ctx->kv_self.size;
}

enum llama_vocab_type llama_vocab_type(const struct llama_model * model) {
enum llama_vocab_type llama_get_vocab_type(const struct llama_model * model) {
return model->vocab.type;
}

enum llama_rope_type llama_rope_type(const struct llama_model * model) {
enum llama_rope_type llama_get_rope_type(const struct llama_model * model) {
switch (model->arch) {
// these models do not use RoPE
case LLM_ARCH_GPT2:
Expand Down Expand Up @@ -18536,7 +18536,7 @@ enum llama_rope_type llama_rope_type(const struct llama_model * model) {
return LLAMA_ROPE_TYPE_NONE;
}

enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx) {
enum llama_pooling_type llama_get_pooling_type(const struct llama_context * ctx) {
return ctx->cparams.pooling_type;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test-tokenizer-1-bpe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int main(int argc, char **argv) {
}
}

//GGML_ASSERT(llama_vocab_type(model) == LLAMA_VOCAB_TYPE_BPE);
if (llama_vocab_type(model) != LLAMA_VOCAB_TYPE_BPE) {
//GGML_ASSERT(llama_get_vocab_type(model) == LLAMA_VOCAB_TYPE_BPE);
if (llama_get_vocab_type(model) != LLAMA_VOCAB_TYPE_BPE) {
return 99;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test-tokenizer-1-spm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ int main(int argc, char ** argv) {
}
}

//GGML_ASSERT(llama_vocab_type(model) == LLAMA_VOCAB_TYPE_SPM);
if (llama_vocab_type(model) != LLAMA_VOCAB_TYPE_SPM) {
//GGML_ASSERT(llama_get_vocab_type(model) == LLAMA_VOCAB_TYPE_SPM);
if (llama_get_vocab_type(model) != LLAMA_VOCAB_TYPE_SPM) {
return 99;
}

Expand Down
Loading