[data] fix: avoid duplicate BOS after chat template rendering - #170
Open
zhujian19891203 wants to merge 1 commit into
Open
[data] fix: avoid duplicate BOS after chat template rendering#170zhujian19891203 wants to merge 1 commit into
zhujian19891203 wants to merge 1 commit into
Conversation
HF chat templates may render BOS directly when tokenize=False. Passing the rendered prompt to the processor with default special-token handling can prepend another BOS, and separately tokenizing labels can also add BOS to trainable labels. Disable extra special tokens in these post-template encoding paths.
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.
Summary
Why
HF chat templates can render BOS directly when called with tokenize=False, for example through {{- bos_token -}} in the template. Passing that rendered prompt to the processor with default special-token handling can prepend another BOS and produce duplicated <|begin_of_text|> in model inputs.
The assistant answer is also tokenized separately to build labels. If that tokenize call adds special tokens, decoded trainable labels can start with BOS even though the answer is not a new document.
This keeps special-token layout owned by the rendered chat template and matches the existing ChatTemplate.encode_multiturn behavior, where text segments are tokenized with add_special_tokens=False.
Example