Repository navigation
Sync the pad id to FastModel's fallback tokenizer - #16557
Merged
Merged
Conversation
When patch_tokenizer fails, FastModel reloads a fresh tokenizer and patches it again. An older unsloth_zoo raised after adding a pad and growing the embedding, so the model config kept the dropped pad's id while the returned tokenizer padded with another one. Point config and generation_config pad_token_id at the fallback tokenizer's pad when it has an embedding row.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
FastModelcan return a model whoseconfig.pad_token_idnames a token that the returned tokenizer does not have.What
When
patch_tokenizerraises insideFastBaseModel.from_pretrained,vision.pyreloads a fresh tokenizer and patches that instead. An older unsloth_zoofix_pad_tokencould raise after it had already added a pad token, grown the embedding and written the new pad id intomodel.config. The fallback then returned the fresh tokenizer, which has no such token, while the config still pointed at it. Generation and collators that read the pad from the config used an id the tokenizer never emits.The fallback now calls a small helper,
_sync_pad_token_id, after patching the fallback tokenizer. It setsconfig.pad_token_idandgeneration_config.pad_token_idto the returned tokenizer's pad id when that id is a valid embedding row. It does nothing when the tokenizer has no pad, the id is out of range, or the model has no input embeddings, and it only runs on the fallback path.The matching unsloth_zoo change stops
fix_pad_tokenfrom raising in this case; this side keeps FastModel consistent with zoo releases that still do.Tests
tests/test_fastmodel_pad_fallback_sync.py(new, CPU only, no unsloth import: the helper is read from source):vision.pyfallback calls the helper afterpatch_tokenizer.All 4 pass on this branch; on main the helper does not exist.
Not covered
No GPU load of a real FastModel checkpoint; the normal (non-fallback) tokenizer path is unchanged.