Skip to content

Commit cc2b62f

Browse files
committed
src: remove duplicate function llama_should_add_bos_token
1 parent fc4ca27 commit cc2b62f

File tree

14 files changed

+26
-40
lines changed

14 files changed

+26
-40
lines changed

common/common.cpp

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

2705-
bool llama_should_add_bos_token(const llama_model * model) {
2706-
const int add_bos = llama_add_bos_token(model);
2707-
2708-
return add_bos != -1 ? bool(add_bos) : (llama_vocab_type(model) == LLAMA_VOCAB_TYPE_SPM);
2709-
}
2710-
27112705
//
27122706
// Chat template utils
27132707
//

common/common.h

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

383-
// Uses the value from the model metadata if possible, otherwise
384-
// defaults to true when model type is SPM, otherwise false.
385-
bool llama_should_add_bos_token(const llama_model * model);
386-
387383
//
388384
// Chat template utils
389385
//

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
@@ -203,8 +203,8 @@ int main(int argc, char ** argv) {
203203
LOG_TEE("\n");
204204
LOG_TEE("%s\n", gpt_params_get_system_info(params).c_str());
205205
}
206-
const bool add_bos = llama_should_add_bos_token(model);
207-
GGML_ASSERT(llama_add_eos_token(model) != 1);
206+
const bool add_bos = llama_add_bos_token(model);
207+
GGML_ASSERT(!llama_add_eos_token(model));
208208
LOG("add_bos: %d\n", add_bos);
209209

210210
std::vector<llama_token> embd_inp;

examples/main/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ int main(int argc, char ** argv) {
267267
}
268268
}
269269

270-
const bool add_bos = llama_should_add_bos_token(model);
270+
const bool add_bos = llama_add_bos_token(model);
271271
if (!llama_model_has_encoder(model)) {
272-
GGML_ASSERT(llama_add_eos_token(model) != 1);
272+
GGML_ASSERT(!llama_add_eos_token(model));
273273
}
274274
LOG("add_bos: %d\n", add_bos);
275275

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,8 @@ struct server_context {
693693

694694
n_ctx = llama_n_ctx(ctx);
695695

696-
add_bos_token = llama_should_add_bos_token(model);
697-
has_eos_token = llama_add_eos_token(model) != 1;
698-
696+
add_bos_token = llama_add_bos_token(model);
697+
has_eos_token = !llama_add_eos_token(model);
699698
return true;
700699
}
701700

@@ -2045,7 +2044,7 @@ struct server_context {
20452044
slot.t_start_generation = 0;
20462045

20472046
if (slot.infill) {
2048-
const bool add_bos = llama_should_add_bos_token(model);
2047+
const bool add_bos = llama_add_bos_token(model);
20492048
bool suff_rm_leading_spc = true;
20502049
if (params.input_suffix.find_first_of(' ') == 0 && params.input_suffix.size() > 1) {
20512050
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
@@ -915,11 +915,8 @@ extern "C" {
915915
LLAMA_API llama_token llama_token_nl (const struct llama_model * model); // next-line
916916
LLAMA_API llama_token llama_token_pad(const struct llama_model * model); // padding
917917

918-
// Returns -1 if unknown, 1 for true or 0 for false.
919-
LLAMA_API int32_t llama_add_bos_token(const struct llama_model * model);
920-
921-
// Returns -1 if unknown, 1 for true or 0 for false.
922-
LLAMA_API int32_t llama_add_eos_token(const struct llama_model * model);
918+
LLAMA_API bool llama_add_bos_token(const struct llama_model * model);
919+
LLAMA_API bool llama_add_eos_token(const struct llama_model * model);
923920

924921
// Codellama infill tokens
925922
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
@@ -1466,11 +1466,11 @@ llama_token llama_token_pad_impl(const struct llama_vocab & vocab) {
14661466
return vocab.special_pad_id;
14671467
}
14681468

1469-
int32_t llama_add_bos_token_impl(const struct llama_vocab & vocab) {
1469+
bool llama_add_bos_token_impl(const struct llama_vocab & vocab) {
14701470
return vocab.tokenizer_add_bos;
14711471
}
14721472

1473-
int32_t llama_add_eos_token_impl(const struct llama_vocab & vocab) {
1473+
bool llama_add_eos_token_impl(const struct llama_vocab & vocab) {
14741474
return vocab.tokenizer_add_eos;
14751475
}
14761476

src/llama-vocab.h

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

98-
int32_t llama_add_bos_token_impl(const struct llama_vocab & vocab);
99-
int32_t llama_add_eos_token_impl(const struct llama_vocab & vocab);
98+
bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
99+
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);
100100

101101
llama_token llama_token_prefix_impl(const struct llama_vocab & vocab);
102102
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
@@ -18699,11 +18699,11 @@ llama_token llama_token_pad(const struct llama_model * model) {
1869918699
return llama_token_pad_impl(model->vocab);
1870018700
}
1870118701

18702-
int32_t llama_add_bos_token(const struct llama_model * model) {
18702+
bool llama_add_bos_token(const struct llama_model * model) {
1870318703
return llama_add_bos_token_impl(model->vocab);
1870418704
}
1870518705

18706-
int32_t llama_add_eos_token(const struct llama_model * model) {
18706+
bool llama_add_eos_token(const struct llama_model * model) {
1870718707
return llama_add_eos_token_impl(model->vocab);
1870818708
}
1870918709

0 commit comments

Comments
 (0)