@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 8e9ffd37d6
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 15, 19:45 UTC

[Misc] Clean up processor tests (#14771)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>

Cyrus Leung committed Mar 14, 2025 at 02:25 UTC 8e9ffd37d6499c6855b04b2a4d8f5326b5e2f78f
8 files changed +30 -46
tests/models/multimodal/processing/test_h2ovl.py
+3 -5
@@ -96,14 +96,14 @@ def _run_check(
96 tokenizer = processor.info.get_tokenizer()
97 config = processor.info.get_hf_config()
98
99 + prompt = "<image>" * len(images)
100 mm_data = {"image": images}
101
102 total_expected_num_patches = sum(
103 _get_expected_num_patches(config, image, len(images), min_num, max_num)
104 for image in images)
105
105 - processed_inputs = processor.apply("<image>" * len(images), mm_data,
106 - mm_processor_kwargs)
106 + processed_inputs = processor.apply(prompt, mm_data, mm_processor_kwargs)
107
108 # Ensure we have the right number of placeholders per num_crops size
109 image_token_id = tokenizer.convert_tokens_to_ids("<IMG_CONTEXT>")
@@ -152,9 +152,7 @@ def test_processor_override(
152 }
153
154 ctx = build_model_context(
155 - model_name=model_id,
156 - tokenizer_name=model_id,
157 - trust_remote_code=True,
155 + model_id,
156 mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
157 limit_mm_per_prompt={"image": len(size_factors)},
158 )
tests/models/multimodal/processing/test_idefics3.py
+3 -7
@@ -9,10 +9,8 @@ from vllm.transformers_utils.tokenizer import cached_tokenizer_from_config
9 from ....conftest import _ImageAssets
10 from ...utils import build_model_context
11
12 -models = ["HuggingFaceM4/Idefics3-8B-Llama3"]
12
14 -
15 -@pytest.mark.parametrize("model", models)
13 +@pytest.mark.parametrize("model_id", ["HuggingFaceM4/Idefics3-8B-Llama3"])
14 # yapf: disable
15 @pytest.mark.parametrize(
16 ("mm_processor_kwargs", "expected_toks_per_img"),
@@ -25,7 +23,7 @@ models = ["HuggingFaceM4/Idefics3-8B-Llama3"]
23 @pytest.mark.parametrize("kwargs_on_init", [True, False])
24 def test_processor_override(
25 image_assets: _ImageAssets,
28 - model: str,
26 + model_id: str,
27 mm_processor_kwargs: dict[str, object],
28 expected_toks_per_img: int,
29 num_imgs: int,
@@ -36,9 +34,7 @@ def test_processor_override(
34 # in this test and assume that the kwargs will be correctly expanded by
35 # the partial when calling the custom input processor.
36 ctx = build_model_context(
39 - model_name=model,
40 - tokenizer_name=model,
41 - trust_remote_code=True,
37 + model_id,
38 mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
39 limit_mm_per_prompt={"image": num_imgs},
40 )
tests/models/multimodal/processing/test_internvl.py
+3 -5
@@ -56,14 +56,14 @@ def _run_check(
56 tokenizer = processor.info.get_tokenizer()
57 config = processor.info.get_hf_config()
58
59 + prompt = "<image>" * len(images)
60 mm_data = {"image": images}
61
62 total_expected_num_patches = sum(
63 _get_expected_num_patches(config, image, len(images), min_num, max_num)
64 for image in images)
65
65 - processed_inputs = processor.apply("<image>" * len(images), mm_data,
66 - mm_processor_kwargs)
66 + processed_inputs = processor.apply(prompt, mm_data, mm_processor_kwargs)
67
68 # Ensure we have the right number of placeholders per num_crops size
69 image_token_id = tokenizer.convert_tokens_to_ids("<IMG_CONTEXT>")
@@ -109,9 +109,7 @@ def test_processor_override(
109 }
110
111 ctx = build_model_context(
112 - model_name=model_id,
113 - tokenizer_name=model_id,
114 - trust_remote_code=True,
112 + model_id,
113 mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
114 limit_mm_per_prompt={"image": len(size_factors)},
115 )
tests/models/multimodal/processing/test_llava_next.py
+3 -6
@@ -36,8 +36,7 @@ def _validate_image_max_tokens_one(
36 @pytest.mark.parametrize("model_id", ["llava-hf/llava-v1.6-mistral-7b-hf"])
37 def test_processor_max_tokens(model_id):
38 ctx = build_model_context(
39 - model_name=model_id,
40 - tokenizer_name=model_id,
39 + model_id,
40 mm_processor_kwargs=None,
41 limit_mm_per_prompt={"image": 1},
42 )
@@ -136,8 +135,7 @@ def _test_image_prompt_replacements(
135 @pytest.mark.parametrize("num_imgs", [1, 2])
136 def test_processor_prompt_replacements_regression(model_id, num_imgs):
137 ctx = build_model_context(
139 - model_name=model_id,
140 - tokenizer_name=model_id,
138 + model_id,
139 mm_processor_kwargs=None,
140 limit_mm_per_prompt={"image": num_imgs},
141 )
@@ -166,8 +164,7 @@ def test_processor_prompt_replacements_regression(model_id, num_imgs):
164 @pytest.mark.parametrize("num_imgs", [1])
165 def test_processor_prompt_replacements_all(model_id, num_imgs):
166 ctx = build_model_context(
169 - model_name=model_id,
170 - tokenizer_name=model_id,
167 + model_id,
168 mm_processor_kwargs=None,
169 limit_mm_per_prompt={"image": num_imgs},
170 )
tests/models/multimodal/processing/test_llava_onevision.py
+3 -6
@@ -37,8 +37,7 @@ def _validate_image_max_tokens_one(
37 ["llava-hf/llava-onevision-qwen2-0.5b-ov-hf"])
38 def test_processor_max_tokens(model_id):
39 ctx = build_model_context(
40 - model_name=model_id,
41 - tokenizer_name=model_id,
40 + model_id,
41 mm_processor_kwargs=None,
42 limit_mm_per_prompt={"image": 1},
43 )
@@ -136,8 +135,7 @@ def _test_image_prompt_replacements(
135 @pytest.mark.parametrize("num_imgs", [1, 2])
136 def test_processor_prompt_replacements_regression(model_id, num_imgs):
137 ctx = build_model_context(
139 - model_name=model_id,
140 - tokenizer_name=model_id,
138 + model_id,
139 mm_processor_kwargs=None,
140 limit_mm_per_prompt={"image": num_imgs},
141 )
@@ -167,8 +165,7 @@ def test_processor_prompt_replacements_regression(model_id, num_imgs):
165 @pytest.mark.parametrize("num_imgs", [1])
166 def test_processor_prompt_replacements_all(model_id, num_imgs):
167 ctx = build_model_context(
170 - model_name=model_id,
171 - tokenizer_name=model_id,
168 + model_id,
169 mm_processor_kwargs=None,
170 limit_mm_per_prompt={"image": num_imgs},
171 )
tests/models/multimodal/processing/test_phi3v.py
+1 -3
@@ -35,9 +35,7 @@ def test_processor_override(
35 from vllm.model_executor.models.phi3v import _IMAGE_TOKEN_ID
36
37 ctx = build_model_context(
38 - model_name=model_id,
39 - tokenizer_name=model_id,
40 - trust_remote_code=True,
38 + model_id,
39 mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
40 limit_mm_per_prompt={"image": num_imgs},
41 )
tests/models/multimodal/processing/test_qwen2_vl.py
+1 -2
@@ -30,8 +30,7 @@ def test_processor_override(
30 ):
31 """Ensure Qwen2VLMultiModalProcessor handles min/max pixels properly."""
32 ctx = build_model_context(
33 - model_name=model_id,
34 - tokenizer_name=model_id,
33 + model_id,
34 mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
35 limit_mm_per_prompt={"image": num_imgs},
36 )
tests/models/utils.py
+13 -12
@@ -10,6 +10,8 @@ from vllm.config import ModelConfig, TaskOption
10 from vllm.inputs import InputContext
11 from vllm.sequence import Logprob, PromptLogprobs, SampleLogprobs
12
13 +from .registry import HF_EXAMPLE_MODELS
14 +
15 TokensText = tuple[list[int], str]
16
17
@@ -250,10 +252,8 @@ def check_logprobs_close(
252
253
254 def build_model_context(
253 - model_name: str,
255 + model_id: str,
256 task: TaskOption = "auto",
255 - tokenizer_name: Optional[str] = None,
256 - trust_remote_code: bool = False,
257 dtype: Optional[Union[str, torch.dtype]] = None,
258 mm_processor_kwargs: Optional[dict] = None,
259 limit_mm_per_prompt: Optional[dict] = None,
@@ -262,9 +262,7 @@ def build_model_context(
262 """Creates an InputContext for a given model.
263
264 Args:
265 - model_name: Name of the model being considered.
266 - tokenizer_name: Name of the tokenizer being considered.
267 - trust_remote_code: Whether or not to allow loading remote code.
265 + model_id: ID of the model being considered.
266 mm_processor_kwargs: optional processor kwargs for to be leveraged
267 in the input processor, mapper, dummy data creation, etc.
268 limit_mm_per_prompt: Multimodal limits.
@@ -272,21 +270,24 @@ def build_model_context(
270 Returns:
271 InputContext for the model being considered.
272 """
275 - if tokenizer_name is None:
276 - tokenizer_name = model_name
273 + model_info = HF_EXAMPLE_MODELS.find_hf_info(model_id)
274 + model_info.check_available_online(on_fail="skip")
275 + model_info.check_transformers_version(on_fail="skip")
276 +
277 if dtype is None:
278 dtype = "half"
279
280 model_config = ModelConfig(
281 - model_name,
281 + model_id,
282 task=task,
283 - tokenizer=tokenizer_name,
284 - tokenizer_mode="auto",
285 - trust_remote_code=trust_remote_code,
283 + tokenizer=model_info.tokenizer or model_id,
284 + tokenizer_mode=model_info.tokenizer_mode,
285 + trust_remote_code=model_info.trust_remote_code,
286 dtype=dtype,
287 seed=0,
288 mm_processor_kwargs=mm_processor_kwargs,
289 limit_mm_per_prompt=limit_mm_per_prompt,
290 disable_mm_preprocessor_cache=disable_mm_preprocessor_cache,
291 + hf_overrides=model_info.hf_overrides,
292 )
293 return InputContext(model_config)