Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c3185b

Browse files
committed
Merge branch 'pr-45317' into merge-cluster-cluster-45081-3-20260423223633
2 parents 7e435be + 93b05c0 commit 0c3185b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎tests/models/auto/test_tokenization_auto.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,27 @@ def test_auto_tokenizer_from_mistral_patching(self):
337337
"mistralai/Ministral-3-3B-Instruct-2512", fix_mistral_regex=True
338338
) # should not error
339339

340+
@require_tokenizers
341+
def test_auto_tokenizer_mistral_patching_applies_pretokenizer(self):
342+
"""Verify fix_mistral_regex=True actually patches the pre_tokenizer without AttributeError."""
343+
import tokenizers
344+
345+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Ministral-3-3B-Instruct-2512")
346+
# Create a temp config with an old transformers_version so the patching code path is exercised
347+
with tempfile.TemporaryDirectory() as tmp_dir:
348+
config_path = os.path.join(tmp_dir, "config.json")
349+
with open(config_path, "w", encoding="utf-8") as f:
350+
json.dump({"model_type": "mistral", "transformers_version": "4.50.0"}, f)
351+
352+
patched = TokenizersBackend._patch_mistral_regex(
353+
tokenizer._tokenizer,
354+
tmp_dir,
355+
is_local=True,
356+
fix_mistral_regex=True,
357+
)
358+
self.assertTrue(getattr(patched, "fix_mistral_regex", False))
359+
self.assertIsInstance(patched.pre_tokenizer, tokenizers.pre_tokenizers.Sequence)
360+
340361
@require_tokenizers
341362
def test_auto_tokenizer_loads_bloom_repo_without_tokenizer_class(self):
342363
tokenizer = AutoTokenizer.from_pretrained("trl-internal-testing/tiny-BloomForCausalLM")

0 commit comments

Comments
 (0)