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 14, 05:30 UTC
[Misc] Simplify `test_argsort_mm_positions` (#25690)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Cyrus Leung committed
Sep 26, 2025 at 02:23 UTC
6b0fcbbf4361cce7965c67ceede953e22062610c
1 file changed
+21
-26
tests/multimodal/test_utils.py
+21
-26
@@ -5,7 +5,6 @@ import base64
5
import mimetypes
6
import os
7
from tempfile import NamedTemporaryFile, TemporaryDirectory
8
-from typing import TYPE_CHECKING, NamedTuple
8
9
import numpy as np
10
import pytest
@@ -15,9 +14,6 @@ from vllm.multimodal.image import convert_image_mode
14
from vllm.multimodal.inputs import PlaceholderRange
15
from vllm.multimodal.utils import MediaConnector, argsort_mm_positions
16
18
-if TYPE_CHECKING:
19
- from vllm.multimodal.inputs import MultiModalPlaceholderDict
20
-
17
# Test different image extensions (JPG/PNG) and formats (gray/RGB/RGBA)
18
TEST_IMAGE_ASSETS = [
19
"2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", # "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
@@ -218,18 +214,13 @@ async def test_fetch_video_http_with_dynamic_loader(
214
assert metadata_sync["video_backend"] == "opencv_dynamic"
215
216
221
-# Used for `test_argsort_mm_positions`.
222
-class TestCase(NamedTuple):
223
- mm_positions: "MultiModalPlaceholderDict"
224
- expected_modality_idxs: list[tuple[str, int]]
225
-
226
-
227
-def test_argsort_mm_positions():
228
-
229
- test_cases = [
217
+# yapf: disable
218
+@pytest.mark.parametrize(
219
+ "case",
220
+ [
221
# Single modality
222
## Internally sorted
232
- TestCase(
223
+ dict(
224
mm_positions={
225
"image": [
226
PlaceholderRange(offset=0, length=2),
@@ -242,7 +233,7 @@ def test_argsort_mm_positions():
233
],
234
),
235
## Internally unsorted
245
- TestCase(
236
+ dict(
237
mm_positions={
238
"image": [
239
PlaceholderRange(offset=3, length=2),
@@ -257,7 +248,7 @@ def test_argsort_mm_positions():
248
249
# Two modalities
250
## Internally sorted
260
- TestCase(
251
+ dict(
252
mm_positions={
253
"image": [
254
PlaceholderRange(offset=7, length=4),
@@ -276,7 +267,7 @@ def test_argsort_mm_positions():
267
],
268
),
269
## Interleaved, internally sorted
279
- TestCase(
270
+ dict(
271
mm_positions={
272
"image": [
273
PlaceholderRange(offset=0, length=4),
@@ -295,7 +286,7 @@ def test_argsort_mm_positions():
286
],
287
),
288
## Interleaved, internally unsorted
298
- TestCase(
289
+ dict(
290
mm_positions={
291
"image": [
292
PlaceholderRange(offset=8, length=2),
@@ -316,7 +307,7 @@ def test_argsort_mm_positions():
307
308
# Three modalities
309
## Internally sorted
319
- TestCase(
310
+ dict(
311
mm_positions={
312
"image": [
313
PlaceholderRange(offset=15, length=7),
@@ -341,7 +332,7 @@ def test_argsort_mm_positions():
332
],
333
),
334
## Interleaved, internally sorted
344
- TestCase(
335
+ dict(
336
mm_positions={
337
"image": [
338
PlaceholderRange(offset=0, length=2),
@@ -363,8 +354,8 @@ def test_argsort_mm_positions():
354
("image", 2),
355
],
356
),
366
- ## Interleaved, internally sunorted
367
- TestCase(
357
+ ## Interleaved, internally unsorted
358
+ dict(
359
mm_positions={
360
"image": [
361
PlaceholderRange(offset=0, length=2),
@@ -386,9 +377,13 @@ def test_argsort_mm_positions():
377
("image", 1),
378
],
379
),
389
- ]
380
+ ],
381
+)
382
+# yapf: enable
383
+def test_argsort_mm_positions(case):
384
+ mm_positions = case["mm_positions"]
385
+ expected_modality_idxs = case["expected_modality_idxs"]
386
391
- for mm_positions, expected_modality_idxs in test_cases:
392
- modality_idxs = argsort_mm_positions(mm_positions)
387
+ modality_idxs = argsort_mm_positions(mm_positions)
388
394
- assert modality_idxs == expected_modality_idxs
389
+ assert modality_idxs == expected_modality_idxs