refactor(tokenizer): remove dead to_dict override - #12
Merged
Conversation
to_dict returned {} and had no caller. It also overrode nothing: there is
no to_dict anywhere in the PreTrainedTokenizer MRO, so it was not shadowing
a base method whose behaviour needed neutralising.
Checked on both CI transformers versions (4.57.6 and 5.14.1) that removing
it leaves save_pretrained + AutoTokenizer.from_pretrained round-trip,
apply_chat_template, __call__ and repr all working. Also grepped the
installed transformers for tokenizer to_dict callers across the top-level
modules, integrations/, trainer*.py and modelcard.py -- none.
Caveat for the reviewer: 33c7f1a "fix(tokenizer): dict should be empty"
added this deliberately and the message does not say what broke. If it was
working around a downstream library (wandb config logging, datasets
fingerprinting) rather than transformers itself, my checks would not have
caught it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Audit item #6, now confirmed rather than suspected.
Why it is dead
tokenizer.to_dict()— the one.to_dict()in the codebase isconfig.to_dict()on aPretrainedConfig, unrelated.to_dictanywhere in thePreTrainedTokenizerMRO, so it was not shadowing a base method whose behaviour needed neutralising. Deleting it leaves the attribute genuinely absent, not falling back to something else.integrations/,trainer*.pyandmodelcard.py.Verified on both CI transformers versions
With and without the method, on 4.57.6 and 5.14.1:
save_pretrained+AutoTokenizer.from_pretrainedround tripapply_chat_template__call__repr241 passed on both versions.
ruffclean.Caveat worth a reviewer's judgement
Commit
33c7f1a "fix(tokenizer): dict should be empty"added this deliberately, and the message does not say what it fixed. My checks cover transformers itself; if it was working around a downstream consumer — wandb config logging,datasetsfingerprinting, something in the training script — those paths are not exercised here. If you remember what prompted that commit and it was outside transformers, say so and I will close this.🤖 Generated with Claude Code
Note
Low Risk
Deletes dead code with no references in-repo; only residual risk is an undocumented downstream consumer of the old empty
to_dict.Overview
Removes the
UTFTokenizer.to_dict()override that only returned{}, as audit item #6.The method had no callers in this repo (unlike
config.to_dict()onPretrainedConfig), did not override anything on thePreTrainedTokenizerMRO, and tokenizer round-trips (save_pretrained/AutoTokenizer,apply_chat_template,__call__) were checked on transformers 4.57.6 and 5.14.1 with the method removed.Reviewer note: commit
33c7f1aadded this deliberately; if something outside transformers (e.g. wandb, datasets fingerprinting) relied on it, that path is not covered by the checks above.Reviewed by Cursor Bugbot for commit 33cee24. Bugbot is set up for automated code reviews on this repo. Configure here.