Skip to content

Commit 4e440f2

Browse files
committed
src: remove duplicate function llama_should_add_bos_token
1 parent 7e72aa7 commit 4e440f2

File tree

14 files changed

+26
-39
lines changed

14 files changed

+26
-39
lines changed

common/common.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,12 +2662,6 @@ std::string llama_detokenize(llama_context * ctx, const std::vector<llama_token>
26622662
return text;
26632663
}
26642664

2665-
bool llama_should_add_bos_token(const llama_model * model) {
2666-
const int add_bos = llama_add_bos_token(model);
2667-
2668-
return add_bos != -1 ? bool(add_bos) : (llama_vocab_type(model) == LLAMA_VOCAB_TYPE_SPM);
2669-
}
2670-
26712665
//
26722666
// Chat template utils
26732667
//

common/common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ std::string llama_detokenize(
361361
const std::vector<llama_token> & tokens,
362362
bool special = true);
363363

364-
// Uses the value from the model metadata if possible, otherwise
365-
// defaults to true when model type is SPM, otherwise false.
366-
bool llama_should_add_bos_token(const llama_model * model);
367-
368364
//
369365
// Chat template utils
370366
//

examples/cvector-generator/cvector-generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ struct tokenized_prompt {
271271
size_t max_seq_len;
272272

273273
tokenized_prompt(llama_context * ctx, std::string pos, std::string neg) {
274-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
274+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
275275
tokens_pos = ::llama_tokenize(ctx, pos, add_bos, true);
276276
tokens_neg = ::llama_tokenize(ctx, neg, add_bos, true);
277277
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
@@ -127,7 +127,7 @@ static bool ggml_debug(struct ggml_tensor * t, bool ask, void * user_data) {
127127
}
128128

129129
static bool run(llama_context * ctx, const gpt_params & params) {
130-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
130+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
131131

132132
std::vector<llama_token> tokens = ::llama_tokenize(ctx, params.prompt, add_bos);
133133

examples/imatrix/imatrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ static void process_logits(
433433
}
434434

435435
static bool compute_imatrix(llama_context * ctx, const gpt_params & params) {
436-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
437-
GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
436+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
437+
GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
438438
const int n_ctx = llama_n_ctx(ctx);
439439

440440
auto tim1 = std::chrono::high_resolution_clock::now();

examples/infill/infill.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ int main(int argc, char ** argv) {
200200
LOG_TEE("\n");
201201
LOG_TEE("%s\n", gpt_params_get_system_info(params).c_str());
202202
}
203-
const bool add_bos = llama_should_add_bos_token(model);
204-
GGML_ASSERT(llama_add_eos_token(model) != 1);
203+
const bool add_bos = llama_add_bos_token(model);
204+
GGML_ASSERT(!llama_add_eos_token(model));
205205
LOG("add_bos: %d\n", add_bos);
206206

207207
std::vector<llama_token> embd_inp;

examples/main/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ int main(int argc, char ** argv) {
264264
}
265265
}
266266

267-
const bool add_bos = llama_should_add_bos_token(model);
267+
const bool add_bos = llama_add_bos_token(model);
268268
if (!llama_model_has_encoder(model)) {
269-
GGML_ASSERT(llama_add_eos_token(model) != 1);
269+
GGML_ASSERT(!llama_add_eos_token(model));
270270
}
271271
LOG("add_bos: %d\n", add_bos);
272272

examples/perplexity/perplexity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ static results_perplexity perplexity_v2(llama_context * ctx, const gpt_params &
340340
// Output: `perplexity: 13.5106 [114/114]`
341341
// BOS tokens will be added for each chunk before eval
342342

343-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
344-
GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
343+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
344+
GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
345345

346346
fprintf(stderr, "%s: tokenizing the input ..\n", __func__);
347347

@@ -480,8 +480,8 @@ static results_perplexity perplexity(llama_context * ctx, const gpt_params & par
480480
// Output: `perplexity: 13.5106 [114/114]`
481481
// BOS tokens will be added for each chunk before eval
482482

483-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
484-
GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
483+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
484+
GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
485485

486486
std::ofstream logits_stream;
487487
if (!params.logits_file.empty()) {
@@ -1733,8 +1733,8 @@ static void kl_divergence(llama_context * ctx, const gpt_params & params) {
17331733
const int n_batch = params.n_batch;
17341734
const int num_batches = (n_ctx + n_batch - 1)/n_batch;
17351735
const int nv = 2*((n_vocab + 1)/2) + 4;
1736-
const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
1737-
GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
1736+
const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
1737+
GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
17381738

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

examples/server/server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ struct server_context {
686686

687687
n_ctx = llama_n_ctx(ctx);
688688

689-
add_bos_token = llama_should_add_bos_token(model);
690-
GGML_ASSERT(llama_add_eos_token(model) != 1);
689+
add_bos_token = llama_add_bos_token(model);
690+
GGML_ASSERT(!llama_add_eos_token(model));
691691

692692
return true;
693693
}
@@ -2028,7 +2028,7 @@ struct server_context {
20282028
slot.t_start_generation = 0;
20292029

20302030
if (slot.infill) {
2031-
const bool add_bos = llama_should_add_bos_token(model);
2031+
const bool add_bos = llama_add_bos_token(model);
20322032
bool suff_rm_leading_spc = true;
20332033
if (params.input_suffix.find_first_of(' ') == 0 && params.input_suffix.size() > 1) {
20342034
params.input_suffix.erase(0, 1);

examples/tokenize/tokenize.cpp

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

365-
const bool model_wants_add_bos = llama_should_add_bos_token(model);
365+
const bool model_wants_add_bos = llama_add_bos_token(model);
366366
const bool add_bos = model_wants_add_bos && !no_bos;
367367
const bool parse_special = !no_parse_special;
368368

include/llama.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,8 @@ extern "C" {
912912
LLAMA_API llama_token llama_token_nl (const struct llama_model * model); // next-line
913913
LLAMA_API llama_token llama_token_pad(const struct llama_model * model); // padding
914914

915-
// Returns -1 if unknown, 1 for true or 0 for false.
916-
LLAMA_API int32_t llama_add_bos_token(const struct llama_model * model);
917-
918-
// Returns -1 if unknown, 1 for true or 0 for false.
919-
LLAMA_API int32_t llama_add_eos_token(const struct llama_model * model);
915+
LLAMA_API bool llama_add_bos_token(const struct llama_model * model);
916+
LLAMA_API bool llama_add_eos_token(const struct llama_model * model);
920917

921918
// Codellama infill tokens
922919
LLAMA_API llama_token llama_token_prefix(const struct llama_model * model); // Beginning of infill prefix

src/llama-vocab.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,11 +1476,11 @@ llama_token llama_token_pad_impl(const struct llama_vocab & vocab) {
14761476
return vocab.special_pad_id;
14771477
}
14781478

1479-
int32_t llama_add_bos_token_impl(const struct llama_vocab & vocab) {
1479+
bool llama_add_bos_token_impl(const struct llama_vocab & vocab) {
14801480
return vocab.tokenizer_add_bos;
14811481
}
14821482

1483-
int32_t llama_add_eos_token_impl(const struct llama_vocab & vocab) {
1483+
bool llama_add_eos_token_impl(const struct llama_vocab & vocab) {
14841484
return vocab.tokenizer_add_eos;
14851485
}
14861486

src/llama-vocab.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ llama_token llama_token_sep_impl(const struct llama_vocab & vocab);
9494
llama_token llama_token_nl_impl (const struct llama_vocab & vocab);
9595
llama_token llama_token_pad_impl(const struct llama_vocab & vocab);
9696

97-
int32_t llama_add_bos_token_impl(const struct llama_vocab & vocab);
98-
int32_t llama_add_eos_token_impl(const struct llama_vocab & vocab);
97+
bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
98+
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);
9999

100100
llama_token llama_token_prefix_impl(const struct llama_vocab & vocab);
101101
llama_token llama_token_middle_impl(const struct llama_vocab & vocab);

src/llama.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18517,11 +18517,11 @@ llama_token llama_token_pad(const struct llama_model * model) {
1851718517
return llama_token_pad_impl(model->vocab);
1851818518
}
1851918519

18520-
int32_t llama_add_bos_token(const struct llama_model * model) {
18520+
bool llama_add_bos_token(const struct llama_model * model) {
1852118521
return llama_add_bos_token_impl(model->vocab);
1852218522
}
1852318523

18524-
int32_t llama_add_eos_token(const struct llama_model * model) {
18524+
bool llama_add_eos_token(const struct llama_model * model) {
1852518525
return llama_add_eos_token_impl(model->vocab);
1852618526
}
1852718527

0 commit comments

Comments
 (0)