Fix ESM2 tokenizer export: use PreTrainedTokenizerFast instead of TokenizersBackend#1555
Open
svc-bionemo wants to merge 1 commit intoNVIDIA:mainfrom
Open
Fix ESM2 tokenizer export: use PreTrainedTokenizerFast instead of TokenizersBackend#1555svc-bionemo wants to merge 1 commit intoNVIDIA:mainfrom
svc-bionemo wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
…nedTokenizerFast In transformers 5.x, AutoTokenizer serializes the class name as "TokenizersBackend" which is not resolvable by AutoTokenizer.from_pretrained(). Patch the saved tokenizer_config.json after save_pretrained() to force tokenizer_class="PreTrainedTokenizerFast" and remove non-standard fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: svc-bionemo <267129667+svc-bionemo@users.noreply.github.com>
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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
The ESM2 export script produces a
tokenizer_config.jsonwith"tokenizer_class": "TokenizersBackend"when run with transformers 5.x (26.03 container). This class name is not in theAutoTokenizerregistry, so loading exported models fails:This affects both the repo exports and the models already on the HF Hub (e.g.
nvidia/esm2_t6_8M_UR50D).Root Cause
Transformers 5.x renamed the internal fast tokenizer backend class to
TokenizersBackend, but this name is not registered inTOKENIZER_MAPPING_NAMES. Whensave_pretrained()is called, it serializes this unresolvable class name.Fix
After
tokenizer.save_pretrained(), patch the savedtokenizer_config.jsonto:tokenizer_classto"PreTrainedTokenizerFast"(universally resolvable)backend,is_local) that transformers 5.x addsApplied to both
bionemo-recipes/models/esm2/export.pyand its copy atbionemo-recipes/recipes/vllm_inference/esm2/export.py.Note
The existing Hub models (
nvidia/esm2_*) also need theirtokenizer_config.jsonpatched — this PR fixes the export script so future exports are correct.