Unverified Commit 6b0fcbbf authored by Cyrus Leung's avatar Cyrus Leung Committed by GitHub
Browse files

[Misc] Simplify `test_argsort_mm_positions` (#25690)


Signed-off-by: default avatarDarkLight1337 <tlleungac@connect.ust.hk>
parent 0fa673af
...@@ -5,7 +5,6 @@ import base64 ...@@ -5,7 +5,6 @@ import base64
import mimetypes import mimetypes
import os import os
from tempfile import NamedTemporaryFile, TemporaryDirectory from tempfile import NamedTemporaryFile, TemporaryDirectory
from typing import TYPE_CHECKING, NamedTuple
import numpy as np import numpy as np
import pytest import pytest
...@@ -15,9 +14,6 @@ from vllm.multimodal.image import convert_image_mode ...@@ -15,9 +14,6 @@ from vllm.multimodal.image import convert_image_mode
from vllm.multimodal.inputs import PlaceholderRange from vllm.multimodal.inputs import PlaceholderRange
from vllm.multimodal.utils import MediaConnector, argsort_mm_positions from vllm.multimodal.utils import MediaConnector, argsort_mm_positions
if TYPE_CHECKING:
from vllm.multimodal.inputs import MultiModalPlaceholderDict
# Test different image extensions (JPG/PNG) and formats (gray/RGB/RGBA) # Test different image extensions (JPG/PNG) and formats (gray/RGB/RGBA)
TEST_IMAGE_ASSETS = [ TEST_IMAGE_ASSETS = [
"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" "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( ...@@ -218,18 +214,13 @@ async def test_fetch_video_http_with_dynamic_loader(
assert metadata_sync["video_backend"] == "opencv_dynamic" assert metadata_sync["video_backend"] == "opencv_dynamic"
# Used for `test_argsort_mm_positions`. # yapf: disable
class TestCase(NamedTuple): @pytest.mark.parametrize(
mm_positions: "MultiModalPlaceholderDict" "case",
expected_modality_idxs: list[tuple[str, int]] [
def test_argsort_mm_positions():
test_cases = [
# Single modality # Single modality
## Internally sorted ## Internally sorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=0, length=2), PlaceholderRange(offset=0, length=2),
...@@ -242,7 +233,7 @@ def test_argsort_mm_positions(): ...@@ -242,7 +233,7 @@ def test_argsort_mm_positions():
], ],
), ),
## Internally unsorted ## Internally unsorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=3, length=2), PlaceholderRange(offset=3, length=2),
...@@ -257,7 +248,7 @@ def test_argsort_mm_positions(): ...@@ -257,7 +248,7 @@ def test_argsort_mm_positions():
# Two modalities # Two modalities
## Internally sorted ## Internally sorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=7, length=4), PlaceholderRange(offset=7, length=4),
...@@ -276,7 +267,7 @@ def test_argsort_mm_positions(): ...@@ -276,7 +267,7 @@ def test_argsort_mm_positions():
], ],
), ),
## Interleaved, internally sorted ## Interleaved, internally sorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=0, length=4), PlaceholderRange(offset=0, length=4),
...@@ -295,7 +286,7 @@ def test_argsort_mm_positions(): ...@@ -295,7 +286,7 @@ def test_argsort_mm_positions():
], ],
), ),
## Interleaved, internally unsorted ## Interleaved, internally unsorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=8, length=2), PlaceholderRange(offset=8, length=2),
...@@ -316,7 +307,7 @@ def test_argsort_mm_positions(): ...@@ -316,7 +307,7 @@ def test_argsort_mm_positions():
# Three modalities # Three modalities
## Internally sorted ## Internally sorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=15, length=7), PlaceholderRange(offset=15, length=7),
...@@ -341,7 +332,7 @@ def test_argsort_mm_positions(): ...@@ -341,7 +332,7 @@ def test_argsort_mm_positions():
], ],
), ),
## Interleaved, internally sorted ## Interleaved, internally sorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=0, length=2), PlaceholderRange(offset=0, length=2),
...@@ -363,8 +354,8 @@ def test_argsort_mm_positions(): ...@@ -363,8 +354,8 @@ def test_argsort_mm_positions():
("image", 2), ("image", 2),
], ],
), ),
## Interleaved, internally sunorted ## Interleaved, internally unsorted
TestCase( dict(
mm_positions={ mm_positions={
"image": [ "image": [
PlaceholderRange(offset=0, length=2), PlaceholderRange(offset=0, length=2),
...@@ -386,9 +377,13 @@ def test_argsort_mm_positions(): ...@@ -386,9 +377,13 @@ def test_argsort_mm_positions():
("image", 1), ("image", 1),
], ],
), ),
] ],
)
# yapf: enable
def test_argsort_mm_positions(case):
mm_positions = case["mm_positions"]
expected_modality_idxs = case["expected_modality_idxs"]
for mm_positions, expected_modality_idxs in test_cases:
modality_idxs = argsort_mm_positions(mm_positions) modality_idxs = argsort_mm_positions(mm_positions)
assert modality_idxs == expected_modality_idxs assert modality_idxs == expected_modality_idxs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment