|
@@ -497,7 +497,7 @@ struct llm_tokenizer_bpe_session {
|
|
|
|
|
|
|
|
bool append_bos(std::vector<llama_vocab::id> & output) const {
|
|
bool append_bos(std::vector<llama_vocab::id> & output) const {
|
|
|
if (vocab.tokenizer_add_bos) {
|
|
if (vocab.tokenizer_add_bos) {
|
|
|
- GGML_ASSERT(vocab.special_bos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_bos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_bos_id);
|
|
output.push_back(vocab.special_bos_id);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -506,7 +506,7 @@ struct llm_tokenizer_bpe_session {
|
|
|
|
|
|
|
|
bool append_eos(std::vector<llama_vocab::id> & output) const {
|
|
bool append_eos(std::vector<llama_vocab::id> & output) const {
|
|
|
if (vocab.tokenizer_add_eos) {
|
|
if (vocab.tokenizer_add_eos) {
|
|
|
- GGML_ASSERT(vocab.special_eos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_eos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_eos_id);
|
|
output.push_back(vocab.special_eos_id);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -1403,7 +1403,7 @@ static void tokenizer_st_partition(const llama_vocab & vocab, std::forward_list<
|
|
|
if (source == 0) {
|
|
if (source == 0) {
|
|
|
buffer.erase_after(buffer.before_begin());
|
|
buffer.erase_after(buffer.before_begin());
|
|
|
} else {
|
|
} else {
|
|
|
- buffer.erase_after(std::next(buffer.begin(), (source-1)));
|
|
|
|
|
|
|
+ buffer.erase_after(std::next(buffer.begin(), (source - 1)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// repeat for the right side
|
|
// repeat for the right side
|
|
@@ -1417,7 +1417,7 @@ static void tokenizer_st_partition(const llama_vocab & vocab, std::forward_list<
|
|
|
if (source == 0) {
|
|
if (source == 0) {
|
|
|
buffer.erase_after(buffer.before_begin());
|
|
buffer.erase_after(buffer.before_begin());
|
|
|
} else {
|
|
} else {
|
|
|
- buffer.erase_after(std::next(buffer.begin(), (source-1)));
|
|
|
|
|
|
|
+ buffer.erase_after(std::next(buffer.begin(), (source - 1)));
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -1454,7 +1454,7 @@ std::vector<llama_vocab::id> llama_tokenize_internal(
|
|
|
bool is_prev_special = true; // prefix with space if first token
|
|
bool is_prev_special = true; // prefix with space if first token
|
|
|
|
|
|
|
|
if (add_special && vocab.tokenizer_add_bos) {
|
|
if (add_special && vocab.tokenizer_add_bos) {
|
|
|
- GGML_ASSERT(vocab.special_bos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_bos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_bos_id);
|
|
output.push_back(vocab.special_bos_id);
|
|
|
is_prev_special = true;
|
|
is_prev_special = true;
|
|
|
}
|
|
}
|
|
@@ -1489,7 +1489,7 @@ std::vector<llama_vocab::id> llama_tokenize_internal(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (add_special && vocab.tokenizer_add_eos) {
|
|
if (add_special && vocab.tokenizer_add_eos) {
|
|
|
- GGML_ASSERT(vocab.special_eos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_eos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_eos_id);
|
|
output.push_back(vocab.special_eos_id);
|
|
|
}
|
|
}
|
|
|
} break;
|
|
} break;
|
|
@@ -1522,7 +1522,7 @@ std::vector<llama_vocab::id> llama_tokenize_internal(
|
|
|
case LLAMA_VOCAB_TYPE_WPM:
|
|
case LLAMA_VOCAB_TYPE_WPM:
|
|
|
{
|
|
{
|
|
|
if (add_special) {
|
|
if (add_special) {
|
|
|
- GGML_ASSERT(vocab.special_cls_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_cls_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_cls_id);
|
|
output.push_back(vocab.special_cls_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1542,14 +1542,14 @@ std::vector<llama_vocab::id> llama_tokenize_internal(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (add_special) {
|
|
if (add_special) {
|
|
|
- GGML_ASSERT(vocab.special_sep_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_sep_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_sep_id);
|
|
output.push_back(vocab.special_sep_id);
|
|
|
}
|
|
}
|
|
|
} break;
|
|
} break;
|
|
|
case LLAMA_VOCAB_TYPE_UGM:
|
|
case LLAMA_VOCAB_TYPE_UGM:
|
|
|
{
|
|
{
|
|
|
if (add_special && vocab.tokenizer_add_bos) {
|
|
if (add_special && vocab.tokenizer_add_bos) {
|
|
|
- GGML_ASSERT(vocab.special_bos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_bos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_bos_id);
|
|
output.push_back(vocab.special_bos_id);
|
|
|
}
|
|
}
|
|
|
llm_tokenizer_ugm_session session(vocab);
|
|
llm_tokenizer_ugm_session session(vocab);
|
|
@@ -1574,7 +1574,7 @@ std::vector<llama_vocab::id> llama_tokenize_internal(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (add_special && vocab.tokenizer_add_eos) {
|
|
if (add_special && vocab.tokenizer_add_eos) {
|
|
|
- GGML_ASSERT(vocab.special_eos_id != -1);
|
|
|
|
|
|
|
+ GGML_ASSERT(vocab.special_eos_id != LLAMA_TOKEN_NULL);
|
|
|
output.push_back(vocab.special_eos_id);
|
|
output.push_back(vocab.special_eos_id);
|
|
|
}
|
|
}
|
|
|
} break;
|
|
} break;
|
|
@@ -1642,7 +1642,7 @@ llama_token_attr llama_token_get_attr_impl(const struct llama_vocab & vocab, lla
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool llama_token_is_eog_impl(const struct llama_vocab & vocab, llama_token token) {
|
|
bool llama_token_is_eog_impl(const struct llama_vocab & vocab, llama_token token) {
|
|
|
- return token != -1 && vocab.special_eog_ids.count(token) > 0;
|
|
|
|
|
|
|
+ return token != LLAMA_TOKEN_NULL && vocab.special_eog_ids.count(token) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool llama_token_is_control_impl(const struct llama_vocab & vocab, llama_token token) {
|
|
bool llama_token_is_control_impl(const struct llama_vocab & vocab, llama_token token) {
|
|
@@ -1881,7 +1881,7 @@ int32_t llama_detokenize_impl(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (remove_special && vocab.tokenizer_add_eos) {
|
|
if (remove_special && vocab.tokenizer_add_eos) {
|
|
|
- if (n_tokens > 0 && tokens[n_tokens-1] == vocab.special_eos_id) {
|
|
|
|
|
|
|
+ if (n_tokens > 0 && tokens[n_tokens - 1] == vocab.special_eos_id) {
|
|
|
n_tokens--;
|
|
n_tokens--;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|