feat: respect prepend_bos and add return_input_tokens flag#1439
Open
MdSadiqMd wants to merge 1 commit into
Open
feat: respect prepend_bos and add return_input_tokens flag#1439MdSadiqMd wants to merge 1 commit into
MdSadiqMd wants to merge 1 commit into
Conversation
Author
|
@jlarson4 PR is up, please review it |
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.
Description
The Bridge tokenizer is loaded with
add_bos_token=True, diverging from the default HF tokenizer behavior. This causes two silent footguns:generate(prepend_bos=...)was ignored — the parameter existed but emitted a warning and fell back tocfg.default_prepend_bos, preventing users from passingprepend_bos=Falseto avoid double-BOS when using chat templates that embed<|begin_of_text|>.generate()return value.This PR fixes both issues and documents the BOS contract so users know when and why to set
prepend_bos=False.Changes:
generate()now respectsprepend_bos— the parameter is forwarded toto_tokens()instead of being discarded with a warning.generate(text, prepend_bos=False)correctly strips tokenizer-auto-prepended BOS, which is the required pattern when the input is pre-formatted chat-template text that already contains a BOS token.return_input_tokensflag added — whenTrue,generate()returns(output, input_tokens)whereinput_tokensis the token tensor that was actually fed to the model (after BOS handling). Compatible withreturn_cache=True(returns 3-tuple(output, cache, input_tokens)).model.tokenizerhasadd_bos_token=Trueand differs from the stock HF tokenizer, that direct.encode()prepends BOS, and shows the recommendedprepend_bos=Falsepattern for chat-template text.Fixes #1418
Type of change
Screenshots
N/A — code changes only. Verified manually with gpt2:
prepend_bosTrue(default)FalseChecklist: