Repository navigation
Let vendored copies of Transformers tokenizers opt into library-class repairs - #68
Merged
Merged
Conversation
… repairs Tokenicer applies the SentencePiece pipeline restoration only to type(tokenizer) is transformers.LlamaTokenizer, and the serialized tokenizer.json preference only to classes whose module starts with transformers. A library that vendors exact copies of Transformers tokenizer classes (GPT-QModel pins the Transformers 5.23 ABI this way) therefore loses both repairs and gets different token IDs for the same checkpoint. Add register_transformers_equivalent(cls, name): an explicit, per-class-object opt-in declaring cls an exact copy of transformers.<name>. Both checks now ask transformers_class_name(cls), which returns the class name for Transformers' own classes, the registered name for registered copies, and None otherwise. A class name alone never grants equivalence, so remote/custom tokenizer code is still left alone, and subclasses are still not normalized as Llama. Bump to 0.0.21. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
Tokenicer applies two class-specific repairs only to Transformers' own tokenizer classes:
normalize_sentencepiece(tokenicer/sentencepiece.py) runs only whentype(tokenizer) is transformers.LlamaTokenizer._resolve_serialized_tokenizer(tokenicer/tokenicer.py) skips any class whose__module__does not start withtransformers..GPT-QModel now pins the Transformers 5.23 ABI by vendoring exact copies of Transformers' model, config and tokenizer classes (ModelCloud/GPTQModel#4620). A vendored
LlamaTokenizeris a different class object in a different module, so both repairs are skipped. For the same checkpoint, it then produces different token IDs than Transformers' own class. InternVL-Chat (Llama/Phi-3 text models) showed this in GPT-QModel's tests.Change
tokenicer.register_transformers_equivalent(cls, name=None). It is an explicit opt-in, keyed by the class object, that declaresclsan exact copy oftransformers.<name>(defaultcls.__name__). It is exported fromtokenicer.tokenicer.equivalence.transformers_class_name(cls). It returns the class name for Transformers' own classes, the registered name for registered copies, andNoneotherwise.transformers_class_name.LlamaTokenizerare still not normalized as Llama.pyproject.tomlandsetup.cfg.Tests
tests/test_equivalence.pyruns offline and covers:ruff check tokenicer tests(0.9.6) passes.tokenicer/__init__.pyalready had an E402 on main for the import placed after HF cache setup; both late imports are now marked as intentional.🤖 Generated with Claude Code