Skip to content

refactor(tokenizer): remove dead to_dict override - #12

Merged
AmitMY merged 1 commit into
mainfrom
simplify/drop-dead-to-dict
Jul 27, 2026
Merged

refactor(tokenizer): remove dead to_dict override#12
AmitMY merged 1 commit into
mainfrom
simplify/drop-dead-to-dict

Conversation

@AmitMY

@AmitMY AmitMY commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Audit item #6, now confirmed rather than suspected.

-    def to_dict(self):
-        return {}

Why it is dead

  • No caller. Nothing in the repo calls tokenizer.to_dict() — the one .to_dict() in the codebase is config.to_dict() on a PretrainedConfig, unrelated.
  • It overrides nothing. There is no to_dict anywhere in the PreTrainedTokenizer MRO, 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.
  • Nothing in transformers calls it on a tokenizer. Grepped the installed package across top-level modules, integrations/, trainer*.py and modelcard.py.

Verified on both CI transformers versions

With and without the method, on 4.57.6 and 5.14.1:

check with without
save_pretrained + AutoTokenizer.from_pretrained round trip OK OK
apply_chat_template OK OK
__call__ OK OK
repr OK OK

241 passed on both versions. ruff clean.

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, datasets fingerprinting, 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() on PretrainedConfig), did not override anything on the PreTrainedTokenizer MRO, 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 33c7f1a added 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.

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>
@AmitMY
AmitMY merged commit 8afe842 into main Jul 27, 2026
4 checks passed
@AmitMY
AmitMY deleted the simplify/drop-dead-to-dict branch July 27, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant