@@ -12674,11 +12674,6 @@ static std::vector<llama_vocab::id> llama_tokenize_internal(const llama_vocab &
12674
12674
// tokenizer.encode('', add_special_tokens=True) returns [1]
12675
12675
// tokenizer.encode('', add_special_tokens=False) returns []
12676
12676
12677
- if (add_special && vocab.special_add_bos != 0) {
12678
- GGML_ASSERT(vocab.special_bos_id != -1);
12679
- output.push_back(vocab.special_bos_id);
12680
- }
12681
-
12682
12677
for (const auto & fragment : fragment_buffer) {
12683
12678
if (fragment.type == FRAGMENT_BUFFER_VARIANT_TYPE_RAW_TEXT) {
12684
12679
// without adding this leading whitespace, we do not get the same results as the original tokenizer
@@ -12705,18 +12700,18 @@ static std::vector<llama_vocab::id> llama_tokenize_internal(const llama_vocab &
12705
12700
}
12706
12701
}
12707
12702
12703
+ if (add_special && vocab.special_add_bos != 0 && output[0] != vocab.special_bos_id) {
12704
+ GGML_ASSERT(vocab.special_bos_id != -1);
12705
+ output.insert(output.begin(), vocab.special_bos_id);
12706
+ }
12707
+
12708
12708
if (add_special && vocab.special_add_eos == 1) {
12709
12709
GGML_ASSERT(vocab.special_eos_id != -1);
12710
12710
output.push_back(vocab.special_eos_id);
12711
12711
}
12712
12712
} break;
12713
12713
case LLAMA_VOCAB_TYPE_BPE:
12714
12714
{
12715
- if (add_special && vocab.special_add_bos != 0) {
12716
- GGML_ASSERT(vocab.special_bos_id != -1);
12717
- output.push_back(vocab.special_bos_id);
12718
- }
12719
-
12720
12715
for (const auto & fragment : fragment_buffer) {
12721
12716
if (fragment.type == FRAGMENT_BUFFER_VARIANT_TYPE_RAW_TEXT) {
12722
12717
auto raw_text = fragment.raw_text.substr(fragment.offset, fragment.length);
@@ -12731,6 +12726,11 @@ static std::vector<llama_vocab::id> llama_tokenize_internal(const llama_vocab &
12731
12726
}
12732
12727
}
12733
12728
12729
+ if (add_special && vocab.special_add_bos != 0 && output[0] != vocab.special_bos_id) {
12730
+ GGML_ASSERT(vocab.special_bos_id != -1);
12731
+ output.insert(output.begin(), vocab.special_bos_id);
12732
+ }
12733
+
12734
12734
GGML_ASSERT(vocab.special_add_eos != 1);
12735
12735
} break;
12736
12736
case LLAMA_VOCAB_TYPE_WPM:
0 commit comments