Load added tokens from GGUF metadata (fixes missing <think>/</think> on Qwen)#3641
Open
jaweed3 wants to merge 1 commit into
Open
Load added tokens from GGUF metadata (fixes missing <think>/</think> on Qwen)#3641jaweed3 wants to merge 1 commit into
jaweed3 wants to merge 1 commit into
Conversation
GGUF files may include a tokenizer.ggml.added_tokens field containing tokens that were added after training (e.g. <think> and </think> for Qwen models). The from_gguf implementation was ignoring this field, so these tokens were invisible to the tokenizer. Read tokenizer.ggml.added_tokens from the GGUF metadata and register them as special tokens on the tokenizer. This ensures they are treated as single tokens during encoding. Fixes huggingface#3473
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
tokenizer.ggml.added_tokensfield in GGUF metadata was being ignored. Tokens like<think>and</think>used by Qwen models were not registered with the tokenizer, so they could not be encoded as single tokens.This reads the field (when present) and registers each token as a special token via
Tokenizer::add_special_tokens, matching the behavior of the Hugging Face tokenizers that generated the GGUF file.Fixes #3473
Tests
added_tokens_are_loaded_as_special— verifies added tokens get vocab entriesadded_tokens_encode_as_single_token— verifies"<think>"encodes as 1 tokenno_added_tokens_does_not_fail— verifies absence of the field is harmless