Skip to content

Commit 6540935

Browse files
committed
vocab : llama_vocab_add_[be]os -> llama_vocab_get_add_[be]os (#11174)
ggml-ci
1 parent 6df37bc commit 6540935

File tree

15 files changed

+123
-124
lines changed

15 files changed

+123
-124
lines changed

common/speculative.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ bool common_speculative_are_compatible(
9494
return false;
9595
}
9696

97-
if (llama_vocab_add_bos(vocab_tgt) != llama_vocab_add_bos(vocab_dft) ||
98-
llama_vocab_add_eos(vocab_tgt) != llama_vocab_add_eos(vocab_dft) ||
97+
if (llama_vocab_get_add_bos(vocab_tgt) != llama_vocab_get_add_bos(vocab_dft) ||
98+
llama_vocab_get_add_eos(vocab_tgt) != llama_vocab_get_add_eos(vocab_dft) ||
9999
llama_vocab_bos(vocab_tgt) != llama_vocab_bos(vocab_dft) ||
100100
llama_vocab_eos(vocab_tgt) != llama_vocab_eos(vocab_dft)) {
101101
LOG_ERR("%s: draft vocab special tokens must match target vocab to use speculation\n", __func__);
102-
LOG_ERR("%s: tgt: bos = %d (%d), eos = %d (%d)\n", __func__, llama_vocab_bos(vocab_tgt), llama_vocab_add_bos(vocab_tgt), llama_vocab_eos(vocab_tgt), llama_vocab_add_eos(vocab_tgt));
103-
LOG_ERR("%s: dft: bos = %d (%d), eos = %d (%d)\n", __func__, llama_vocab_bos(vocab_dft), llama_vocab_add_bos(vocab_dft), llama_vocab_eos(vocab_dft), llama_vocab_add_eos(vocab_dft));
102+
LOG_ERR("%s: tgt: bos = %d (%d), eos = %d (%d)\n", __func__, llama_vocab_bos(vocab_tgt), llama_vocab_get_add_bos(vocab_tgt), llama_vocab_eos(vocab_tgt), llama_vocab_get_add_eos(vocab_tgt));
103+
LOG_ERR("%s: dft: bos = %d (%d), eos = %d (%d)\n", __func__, llama_vocab_bos(vocab_dft), llama_vocab_get_add_bos(vocab_dft), llama_vocab_eos(vocab_dft), llama_vocab_get_add_eos(vocab_dft));
104104
return false;
105105
}
106106

examples/cvector-generator/cvector-generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct tokenized_prompt {
275275
tokenized_prompt(llama_context * ctx, std::string pos, std::string neg) {
276276
const llama_model * model = llama_get_model(ctx);
277277
const llama_vocab * vocab = llama_model_get_vocab(model);
278-
const bool add_bos = llama_vocab_add_bos(vocab);
278+
const bool add_bos = llama_vocab_get_add_bos(vocab);
279279
tokens_pos = common_tokenize(ctx, pos, add_bos, true);
280280
tokens_neg = common_tokenize(ctx, neg, add_bos, true);
281281
max_seq_len = std::max(tokens_pos.size(), tokens_neg.size());

examples/eval-callback/eval-callback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static bool run(llama_context * ctx, const common_params & params) {
130130
const llama_model * model = llama_get_model(ctx);
131131
const llama_vocab * vocab = llama_model_get_vocab(model);
132132

133-
const bool add_bos = llama_vocab_add_bos(vocab);
133+
const bool add_bos = llama_vocab_get_add_bos(vocab);
134134

135135
std::vector<llama_token> tokens = common_tokenize(ctx, params.prompt, add_bos);
136136

examples/imatrix/imatrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,10 @@ static bool compute_imatrix(llama_context * ctx, const common_params & params) {
431431
const llama_model * model = llama_get_model(ctx);
432432
const llama_vocab * vocab = llama_model_get_vocab(model);
433433

434-
const bool add_bos = llama_vocab_add_bos(vocab);
434+
const bool add_bos = llama_vocab_get_add_bos(vocab);
435435
const int n_ctx = llama_n_ctx(ctx);
436436

437-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
437+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
438438

439439
auto tim1 = std::chrono::high_resolution_clock::now();
440440
LOG_INF("%s: tokenizing the input ..\n", __func__);

examples/infill/infill.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ int main(int argc, char ** argv) {
154154
LOG_INF("\n");
155155
LOG_INF("%s\n", common_params_get_system_info(params).c_str());
156156
}
157-
const bool add_bos = llama_vocab_add_bos(vocab);
158-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
157+
const bool add_bos = llama_vocab_get_add_bos(vocab);
158+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
159159

160160
std::vector<llama_token> embd_inp;
161161
std::vector<llama_token> embd_end;

examples/llama-bench/llama-bench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ static void test_prompt(llama_context * ctx, int n_prompt, int n_batch, int n_th
14101410

14111411
while (n_processed < n_prompt) {
14121412
int n_tokens = std::min(n_prompt - n_processed, n_batch);
1413-
tokens[0] = n_processed == 0 && llama_vocab_add_bos(vocab) ? llama_vocab_bos(vocab) : std::rand() % n_vocab;
1413+
tokens[0] = n_processed == 0 && llama_vocab_get_add_bos(vocab) ? llama_vocab_bos(vocab) : std::rand() % n_vocab;
14141414
for (int i = 1; i < n_tokens; i++) {
14151415
tokens[i] = std::rand() % n_vocab;
14161416
}
@@ -1428,7 +1428,7 @@ static void test_gen(llama_context * ctx, int n_gen, int n_threads) {
14281428
const llama_vocab * vocab = llama_model_get_vocab(model);
14291429
const int32_t n_vocab = llama_vocab_n_vocab(vocab);
14301430

1431-
llama_token token = llama_vocab_add_bos(vocab) ? llama_vocab_bos(vocab) : std::rand() % n_vocab;
1431+
llama_token token = llama_vocab_get_add_bos(vocab) ? llama_vocab_bos(vocab) : std::rand() % n_vocab;
14321432

14331433
for (int i = 0; i < n_gen; i++) {
14341434
llama_decode(ctx, llama_batch_get_one(&token, 1));

examples/main/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ int main(int argc, char ** argv) {
242242
}
243243
}
244244

245-
const bool add_bos = llama_vocab_add_bos(vocab);
245+
const bool add_bos = llama_vocab_get_add_bos(vocab);
246246
if (!llama_model_has_encoder(model)) {
247-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
247+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
248248
}
249249

250250
LOG_DBG("n_ctx: %d, add_bos: %d\n", n_ctx, add_bos);

examples/perplexity/perplexity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ static results_perplexity perplexity_v2(llama_context * ctx, const common_params
299299
const llama_model * model = llama_get_model(ctx);
300300
const llama_vocab * vocab = llama_model_get_vocab(model);
301301

302-
const bool add_bos = llama_vocab_add_bos(vocab);
303-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
302+
const bool add_bos = llama_vocab_get_add_bos(vocab);
303+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
304304

305305
LOG_INF("%s: tokenizing the input ..\n", __func__);
306306

@@ -450,8 +450,8 @@ static results_perplexity perplexity(llama_context * ctx, const common_params &
450450
const llama_model * model = llama_get_model(ctx);
451451
const llama_vocab * vocab = llama_model_get_vocab(model);
452452

453-
const bool add_bos = llama_vocab_add_bos(vocab);
454-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
453+
const bool add_bos = llama_vocab_get_add_bos(vocab);
454+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
455455

456456
std::ofstream logits_stream;
457457
if (!params.logits_file.empty()) {
@@ -1717,8 +1717,8 @@ static void kl_divergence(llama_context * ctx, const common_params & params) {
17171717
const int n_batch = params.n_batch;
17181718
const int num_batches = (n_ctx + n_batch - 1)/n_batch;
17191719
const int nv = 2*((n_vocab + 1)/2) + 4;
1720-
const bool add_bos = llama_vocab_add_bos(vocab);
1721-
GGML_ASSERT(!llama_vocab_add_eos(vocab));
1720+
const bool add_bos = llama_vocab_get_add_bos(vocab);
1721+
GGML_ASSERT(!llama_vocab_get_add_eos(vocab));
17221722

17231723
std::vector<uint16_t> log_probs_uint16(size_t(n_ctx - 1 - n_ctx/2) * nv);
17241724
std::vector<float> kld_values(size_t(n_ctx - 1 - n_ctx/2)*n_chunk);

examples/server/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ struct server_context {
16981698

16991699
n_ctx = llama_n_ctx(ctx);
17001700

1701-
add_bos_token = llama_vocab_add_bos(vocab);
1701+
add_bos_token = llama_vocab_get_add_bos(vocab);
17021702
has_eos_token = llama_vocab_eos(vocab) != LLAMA_TOKEN_NULL;
17031703

17041704
if (!params_base.speculative.model.empty()) {

examples/server/utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static llama_tokens format_infill(
333333
auto embd_inp = spm_infill ? tokens_suffix : tokens_prefix;
334334
auto embd_end = spm_infill ? tokens_prefix : tokens_suffix;
335335

336-
if (llama_vocab_add_bos(vocab)) {
336+
if (llama_vocab_get_add_bos(vocab)) {
337337
embd_inp.insert(embd_inp.begin(), llama_vocab_bos(vocab));
338338
}
339339

examples/speculative/speculative.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ int main(int argc, char ** argv) {
106106
}
107107

108108
if (
109-
llama_vocab_add_bos(vocab_tgt) != llama_vocab_add_bos(vocab_dft) ||
110-
llama_vocab_add_eos(vocab_tgt) != llama_vocab_add_eos(vocab_dft) ||
109+
llama_vocab_get_add_bos(vocab_tgt) != llama_vocab_get_add_bos(vocab_dft) ||
110+
llama_vocab_get_add_eos(vocab_tgt) != llama_vocab_get_add_eos(vocab_dft) ||
111111
llama_vocab_bos(vocab_tgt) != llama_vocab_bos(vocab_dft) ||
112112
llama_vocab_eos(vocab_tgt) != llama_vocab_eos(vocab_dft)
113113
) {

examples/tokenize/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ int main(int raw_argc, char ** raw_argv) {
367367
prompt = stdin_buffer.str();
368368
}
369369

370-
const bool model_wants_add_bos = llama_vocab_add_bos(vocab);
370+
const bool model_wants_add_bos = llama_vocab_get_add_bos(vocab);
371371
const bool add_bos = model_wants_add_bos && !no_bos;
372372
const bool parse_special = !no_parse_special;
373373
const bool escape = !no_escape;

include/llama.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,8 @@ extern "C" {
942942
LLAMA_API llama_token llama_vocab_nl (const struct llama_vocab * vocab); // next-line
943943
LLAMA_API llama_token llama_vocab_pad(const struct llama_vocab * vocab); // padding
944944

945-
LLAMA_API bool llama_vocab_add_bos(const struct llama_vocab * vocab);
946-
LLAMA_API bool llama_vocab_add_eos(const struct llama_vocab * vocab);
945+
LLAMA_API bool llama_vocab_get_add_bos(const struct llama_vocab * vocab);
946+
LLAMA_API bool llama_vocab_get_add_eos(const struct llama_vocab * vocab);
947947

948948
LLAMA_API llama_token llama_vocab_fim_pre(const struct llama_vocab * vocab);
949949
LLAMA_API llama_token llama_vocab_fim_suf(const struct llama_vocab * vocab);
@@ -964,8 +964,8 @@ extern "C" {
964964
DEPRECATED(LLAMA_API llama_token llama_token_sep(const struct llama_vocab * vocab), "use llama_vocab_sep instead");
965965
DEPRECATED(LLAMA_API llama_token llama_token_nl (const struct llama_vocab * vocab), "use llama_vocab_nl instead");
966966
DEPRECATED(LLAMA_API llama_token llama_token_pad(const struct llama_vocab * vocab), "use llama_vocab_pad instead");
967-
DEPRECATED(LLAMA_API bool llama_add_bos_token(const struct llama_vocab * vocab), "use llama_vocab_add_bos instead");
968-
DEPRECATED(LLAMA_API bool llama_add_eos_token(const struct llama_vocab * vocab), "use llama_vocab_add_eos instead");
967+
DEPRECATED(LLAMA_API bool llama_add_bos_token(const struct llama_vocab * vocab), "use llama_vocab_get_add_bos instead");
968+
DEPRECATED(LLAMA_API bool llama_add_eos_token(const struct llama_vocab * vocab), "use llama_vocab_get_add_eos instead");
969969
DEPRECATED(LLAMA_API llama_token llama_token_fim_pre(const struct llama_vocab * vocab), "use llama_vocab_fim_pre instead");
970970
DEPRECATED(LLAMA_API llama_token llama_token_fim_suf(const struct llama_vocab * vocab), "use llama_vocab_fim_suf instead");
971971
DEPRECATED(LLAMA_API llama_token llama_token_fim_mid(const struct llama_vocab * vocab), "use llama_vocab_fim_mid instead");

0 commit comments

Comments
 (0)