Skip to content

Commit 9e897d4

Browse files
committed
common : sanity check for non-NULL tokens
ggml-ci
1 parent 1ba3df3 commit 9e897d4

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

common/common.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,31 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
838838
return iparams;
839839
}
840840

841+
if (params.reranking) {
842+
bool ok = true;
843+
844+
if (llama_token_bos(model) == LLAMA_TOKEN_NULL) {
845+
LOG_WRN("%s: warning: model does not have a BOS token, reranking will not work\n", __func__);
846+
ok = false;
847+
}
848+
849+
if (llama_token_eos(model) == LLAMA_TOKEN_NULL) {
850+
LOG_WRN("%s: warning: model does not have an EOS token, reranking will not work\n", __func__);
851+
ok = false;
852+
}
853+
854+
if (llama_token_sep(model) == LLAMA_TOKEN_NULL) {
855+
LOG_WRN("%s: warning: model does not have a SEP token, reranking will not work\n", __func__);
856+
ok = false;
857+
}
858+
859+
if (!ok) {
860+
llama_free_model(model);
861+
862+
return iparams;
863+
}
864+
}
865+
841866
auto cparams = llama_context_params_from_gpt_params(params);
842867

843868
llama_context * lctx = llama_new_context_with_model(model, cparams);
@@ -855,6 +880,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
855880
if (cvec.n_embd == -1) {
856881
llama_free(lctx);
857882
llama_free_model(model);
883+
858884
return iparams;
859885
}
860886

@@ -867,6 +893,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
867893
if (err) {
868894
llama_free(lctx);
869895
llama_free_model(model);
896+
870897
return iparams;
871898
}
872899
}
@@ -889,7 +916,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
889916
llama_lora_adapters_apply(lctx, iparams.lora_adapters);
890917
}
891918

892-
if (params.sparams.ignore_eos && llama_token_eos(model) == -1) {
919+
if (params.sparams.ignore_eos && llama_token_eos(model) == LLAMA_TOKEN_NULL) {
893920
LOG_WRN("%s: warning: model does not have an EOS token, ignoring --ignore-eos\n", __func__);
894921
params.sparams.ignore_eos = false;
895922
}
@@ -930,6 +957,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
930957

931958
iparams.model = model;
932959
iparams.context = lctx;
960+
933961
return iparams;
934962
}
935963

src/llama-vocab.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ struct llama_vocab {
4040
id special_bos_id = 1;
4141
id special_eos_id = 2;
4242
id special_unk_id = 0;
43-
id special_sep_id = -1;
44-
id special_pad_id = -1;
45-
id special_cls_id = -1;
46-
id special_mask_id = -1;
43+
id special_sep_id = LLAMA_TOKEN_NULL;
44+
id special_pad_id = LLAMA_TOKEN_NULL;
45+
id special_cls_id = LLAMA_TOKEN_NULL;
46+
id special_mask_id = LLAMA_TOKEN_NULL;
4747

4848
id linefeed_id = 13;
49-
id special_prefix_id = -1;
50-
id special_suffix_id = -1;
51-
id special_middle_id = -1;
52-
id special_eot_id = -1; // TODO: move above after "eos_id", and here add "file separator" token
53-
id special_eom_id = -1;
49+
id special_prefix_id = LLAMA_TOKEN_NULL;
50+
id special_suffix_id = LLAMA_TOKEN_NULL;
51+
id special_middle_id = LLAMA_TOKEN_NULL;
52+
id special_eot_id = LLAMA_TOKEN_NULL; // TODO: move above after "eos_id", and here add "file separator" token
53+
id special_eom_id = LLAMA_TOKEN_NULL;
5454

5555
// set of all tokens that cause "end of generation"
5656
std::set<id> special_eog_ids;

src/llama.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ struct llama_hparams {
24122412

24132413
// needed by encoder-decoder models (e.g. T5, FLAN-T5)
24142414
// ref: https://github.com/ggerganov/llama.cpp/pull/8141
2415-
llama_token dec_start_token_id = -1;
2415+
llama_token dec_start_token_id = LLAMA_TOKEN_NULL;
24162416

24172417
enum llama_pooling_type pooling_type = LLAMA_POOLING_TYPE_NONE;
24182418
enum llama_rope_type rope_type = LLAMA_ROPE_TYPE_NONE;

0 commit comments

Comments
 (0)