fix: use _added_tokens_encoder cache instead of property in convert_tokens_to_string and get_vocab#46464
Closed
Achyuthan-S wants to merge 4 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds dtype propagation when loading sub-model configs from composite configs, and aligns several tokenizers to use the internal added-tokens encoder mapping.
Changes:
- Propagate
dtypefrom parent (composite) config into derived config duringAutoModel*loading. - Add a regression test to ensure dtype is preserved when loading a
CausalLMfrom a savedConditionalGenerationcheckpoint. - Update multiple tokenizers to reference
_added_tokens_encoderwhen building vocab / converting tokens.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/models/qwen3_5/test_modeling_qwen3_5.py | Adds a test intended to validate dtype propagation through save/load for AutoModel. |
| src/transformers/models/auto/auto_factory.py | Implements dtype propagation from composite config to sub-config in from_config and from_pretrained. |
| src/transformers/models/perceiver/tokenization_perceiver.py | Switches vocab + token-to-string logic to use _added_tokens_encoder. |
| src/transformers/models/myt5/tokenization_myt5.py | Switches vocab + token-to-string logic to use _added_tokens_encoder. |
| src/transformers/models/dia/tokenization_dia.py | Switches vocab + token-to-string logic to use _added_tokens_encoder. |
| src/transformers/models/byt5/tokenization_byt5.py | Switches vocab + token-to-string logic to use _added_tokens_encoder. |
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, byt5, dia, myt5, perceiver, qwen3_5 |
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.
Fixes #46396
Follow-up to #46323, which fixed
_convert_token_to_id_with_added_voc.The
added_tokens_encoderproperty rebuilds and re-sorts the full tokenmap on every access. This PR replaces remaining per-token calls to the
property with direct reads from the maintained
_added_tokens_encodercache in
convert_tokens_to_string()andget_vocab()across fourslow tokenizers: byt5, myt5, dia, and perceiver.
9 replacements across 4 files. The property itself and
tokenization_cpmant.pyare intentionally untouched (Option B fromthe issue).
Tests run:
tests/models/byt5/test_tokenization_byt5.pytests/models/myt5/test_tokenization_myt5.pytests/models/dia/test_tokenization_dia.pytests/models/perceiver/test_tokenization_perceiver.pytests/test_tokenization_common.pyAll passing (160 + 18 passed, 0 failures).
cc @itazap