33
44import time
55from contextlib import nullcontext
6- from typing import cast
76
87import numpy as np
98import pytest
2423 replace_token_matches ,
2524)
2625from vllm .multimodal .profiling import MultiModalProfiler
27- from vllm .tokenizers import TokenizerLike
2826
2927from .utils import random_image
3028
@@ -238,15 +236,12 @@ def test_find_token_matches(
238236 expected_by_key ,
239237 update_type ,
240238):
241- # Should not be used since there is nothing to convert to token IDs
242- mock_tokenizer = cast (TokenizerLike , object ())
243-
244239 prompt_updates = {
245240 key : update_type (key , target , []).resolve (0 )
246241 for key , target in target_by_key .items ()
247242 }
248243 result = {
249- key : list (update .iter_token_matches (prompt , mock_tokenizer ))
244+ key : list (update .iter_token_matches (prompt , tokenizer = None ))
250245 for key , update in prompt_updates .items ()
251246 }
252247
@@ -385,15 +380,12 @@ def test_find_text_matches(
385380 expected_by_key ,
386381 update_type ,
387382):
388- # Should not be used since there is nothing to convert to text
389- mock_tokenizer = cast (TokenizerLike , object ())
390-
391383 prompt_updates = {
392384 key : update_type (key , target , []).resolve (0 )
393385 for key , target in target_by_key .items ()
394386 }
395387 result = {
396- key : list (update .iter_text_matches (prompt , mock_tokenizer ))
388+ key : list (update .iter_text_matches (prompt , tokenizer = None ))
397389 for key , update in prompt_updates .items ()
398390 }
399391
@@ -545,9 +537,6 @@ def test_find_update_text(
545537 repl_by_key ,
546538 expected_by_update_type_mm_count ,
547539):
548- # Should not be used since there is nothing to convert to text
549- mock_tokenizer = cast (TokenizerLike , object ())
550-
551540 for (
552541 update_type ,
553542 expected_by_mm_count ,
@@ -564,7 +553,7 @@ def test_find_update_text(
564553 new_prompt , result = apply_text_matches (
565554 prompt ,
566555 mm_prompt_updates ,
567- mock_tokenizer ,
556+ tokenizer = None ,
568557 )
569558
570559 # Only displayed on error
@@ -750,9 +739,6 @@ def test_find_update_tokens(
750739 repl_by_key ,
751740 expected_by_update_type_mm_count ,
752741):
753- # Should not be used since there is nothing to convert to tokens
754- mock_tokenizer = cast (TokenizerLike , object ())
755-
756742 for (
757743 update_type ,
758744 expected_by_mm_count ,
@@ -769,7 +755,7 @@ def test_find_update_tokens(
769755 new_prompt , result = apply_token_matches (
770756 prompt ,
771757 mm_prompt_updates ,
772- mock_tokenizer ,
758+ tokenizer = None ,
773759 )
774760
775761 # Only displayed on error
@@ -900,15 +886,12 @@ def test_find_mm_placeholders(
900886 expected ,
901887 update_type ,
902888):
903- # Should not be used since there is nothing to convert to tokens
904- mock_tokenizer = cast (TokenizerLike , object ())
905-
906889 mm_prompt_updates = {
907890 key : [[update_type (key , [], repl ).resolve (i )] for i in range (3 )]
908891 for key , repl in repl_by_key .items ()
909892 }
910893
911- result = find_mm_placeholders (prompt , mm_prompt_updates , mock_tokenizer )
894+ result = find_mm_placeholders (prompt , mm_prompt_updates , tokenizer = None )
912895
913896 # Only displayed on error
914897 print ("result:" , result )
@@ -1029,12 +1012,9 @@ def test_hf_processor_init_kwargs(
10291012 inference_kwargs ,
10301013 expected_kwargs ,
10311014):
1032- # Should not be used since there is nothing to convert to tokens
1033- mock_tokenizer = cast (TokenizerLike , object ())
1034-
10351015 ctx = InputProcessingContext (
10361016 model_config = ModelConfig (model_id , mm_processor_kwargs = config_kwargs ),
1037- tokenizer = mock_tokenizer ,
1017+ tokenizer = None ,
10381018 )
10391019
10401020 processor = ctx .get_hf_processor (
@@ -1065,12 +1045,9 @@ def test_hf_processor_call_kwargs(
10651045 inference_kwargs ,
10661046 expected_kwargs ,
10671047):
1068- # Should not be used since there is nothing to convert to tokens
1069- mock_tokenizer = cast (TokenizerLike , object ())
1070-
10711048 ctx = InputProcessingContext (
10721049 model_config = ModelConfig (model_id , mm_processor_kwargs = config_kwargs ),
1073- tokenizer = mock_tokenizer ,
1050+ tokenizer = None ,
10741051 )
10751052
10761053 processor = ctx .get_hf_processor (DummyProcessor ) # type: ignore[arg-type]
@@ -1089,8 +1066,6 @@ def test_apply_matches_no_match_exits_quickly():
10891066
10901067 With the fix, it should exit immediately when no match is found.
10911068 """
1092- mock_tokenizer = cast (TokenizerLike , object ())
1093-
10941069 # Create a long prompt with no placeholder
10951070 long_prompt = "x" * 10000
10961071
@@ -1103,7 +1078,7 @@ def test_apply_matches_no_match_exits_quickly():
11031078 result , _ = _apply_matches (
11041079 long_prompt ,
11051080 mm_prompt_updates ,
1106- mock_tokenizer ,
1081+ tokenizer = None ,
11071082 )
11081083 elapsed = time .perf_counter () - start
11091084
0 commit comments