Fix AttributeError in _patch_mistral_regex when fix_mistral_regex=True #45317
Open
mohdfaour03 wants to merge 2 commits intohuggingface:mainfrom
Open
Fix AttributeError in _patch_mistral_regex when fix_mistral_regex=True #45317mohdfaour03 wants to merge 2 commits intohuggingface:mainfrom
mohdfaour03 wants to merge 2 commits intohuggingface:mainfrom
Conversation
itazap
approved these changes
Apr 9, 2026
Collaborator
itazap
left a comment
There was a problem hiding this comment.
Thanks for fixing! let's just add a small test with passing fix_mistral_reegex=True so that we catch this next time 😊
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto |
The existing test only checks that passing fix_mistral_regex=True doesn't error, but the hub model's config version causes early return so the patching logic is never exercised. This new test creates a local config with an old transformers_version to force the patching code path, verifying that the pre_tokenizer is correctly patched to a Sequence without AttributeError.
4d50363 to
93b05c0
Compare
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45317&sha=93b05c |
Author
|
@itazap Added a test that calls |
itazap
reviewed
Apr 9, 2026
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| config_path = os.path.join(tmp_dir, "config.json") | ||
| with open(config_path, "w", encoding="utf-8") as f: | ||
| json.dump({"model_type": "mistral", "transformers_version": "4.50.0"}, f) |
Collaborator
There was a problem hiding this comment.
I dont think we need a v4 pin here, it still fails in v5 no?
2 tasks
This was referenced Apr 21, 2026
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 #45081
Problem
Loading a Mistral tokenizer with
fix_mistral_regex=Truecrashes because_patch_mistral_regexreceives a rawtokenizers.Tokenizerbut tries toaccess
.backend_tokenizer.pre_tokenizeron it — that attribute only existson
PreTrainedTokenizerFast.Fix
Removed the
.backend_tokenizerindirection (3 lines) since the tokenizerpassed in is already the backend tokenizer.
AI tools helped locate the bug. I reviewed and understood the fix.
Before submitting
Pull Request section?
to it if that's the case. Answer : Issue _patch_mistral_regex crashes with AttributeError: 'tokenizers.Tokenizer' object has no attribute 'backend_tokenizer' when loading Mistral tokenizer with fix_mistral_regex=True #45081
Who can review?
@ArthurZucker @itazap (tokenizers)