Correctly identify LF token for GPT-2 style BPE tokenizer #11496
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fix makes the reported linefeed token for models such as Llama-3 and Qwen consistent with what other sources say (verified with https://huggingface.co/spaces/Xenova/the-tokenizer-playground).
This bug is unlikely to have any impact on current llama.cpp functionality, because the
llama_vocab_nl()
API function is never called. However, the incorrect token IDs appear to have caused some confusion, e.g. here: https://www.reddit.com/r/LocalLLaMA/comments/1cpv7np/why_does_llama3_use_lf_token_128_%C3%A4.The change is necessary because the
llama_vocab::impl::tokenize()
method takes the original orthography in UTF-8 as input, rather than the modified internal representation of the BPE vocabulary (U+010A for "\n"), which is only created inunicode_byte_to_utf8_map()
.This leads to the correct tokens IDs being shown in the trace:
Before
Llama-3:
print_info: LF token = 128 'Ä'
Qwen:
print_info: LF token = 148848 'ÄĬ'
After
Llama-3:
print_info: LF token = 198 'Ċ'
Qwen2:
print_info: LF token = 198 'Ċ