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
import mimetypes
import os
from tempfile import NamedTemporaryFile, TemporaryDirectory
from typing import TYPE_CHECKING, NamedTuple
import numpy as np
import pytest
......@@ -15,9 +14,6 @@ from vllm.multimodal.image import convert_image_mode
from vllm.multimodal.inputs import PlaceholderRange
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_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"
......@@ -218,18 +214,13 @@ async def test_fetch_video_http_with_dynamic_loader(
assert metadata_sync["video_backend"] == "opencv_dynamic"
# Used for `test_argsort_mm_positions`.
class TestCase(NamedTuple):
mm_positions: "MultiModalPlaceholderDict"
expected_modality_idxs: list[tuple[str, int]]
def test_argsort_mm_positions():
test_cases = [
# yapf: disable
@pytest.mark.parametrize(
"case",
[
# Single modality
## Internally sorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=0, length=2),
......@@ -242,7 +233,7 @@ def test_argsort_mm_positions():
],
),
## Internally unsorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=3, length=2),
......@@ -257,7 +248,7 @@ def test_argsort_mm_positions():
# Two modalities
## Internally sorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=7, length=4),
......@@ -276,7 +267,7 @@ def test_argsort_mm_positions():
],
),
## Interleaved, internally sorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=0, length=4),
......@@ -295,7 +286,7 @@ def test_argsort_mm_positions():
],
),
## Interleaved, internally unsorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=8, length=2),
......@@ -316,7 +307,7 @@ def test_argsort_mm_positions():
# Three modalities
## Internally sorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=15, length=7),
......@@ -341,7 +332,7 @@ def test_argsort_mm_positions():
],
),
## Interleaved, internally sorted
TestCase(
dict(
mm_positions={
"image": [
PlaceholderRange(offset=0, length=2),
......@@ -363,8 +354,8 @@ def test_argsort_mm_positions():
("image", 2),
],
),
## Interleaved, internally sunorted
TestCase(
## Interleaved, internally unsorted
dict(
mm_positions={
"image": [
PlaceholderRange(offset=0, length=2),
......@@ -386,9 +377,13 @@ def test_argsort_mm_positions():
("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