File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments