Migrate VLM tests and remove unit-test-backend-1-gpu job (#16679)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
from dataclasses import asdict, dataclass
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.test_utils import run_doctests
|
||||
|
||||
register_cuda_ci(est_time=20, suite="stage-b-test-small-1-gpu")
|
||||
|
||||
|
||||
def test_resolve_evs_config():
|
||||
from sglang.srt.multimodal.evs import EVS, EVSConfig, EVSProcessor
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class EVSModelConfig:
|
||||
video_pruning_rate: float = 0.1
|
||||
spatial_merge_size: int = 2
|
||||
|
||||
class EVSModel(EVS):
|
||||
@staticmethod
|
||||
def create_evs_config(hf_config: EVSModelConfig) -> EVSConfig:
|
||||
return EVSConfig(
|
||||
video_pruning_rate=hf_config.video_pruning_rate,
|
||||
spatial_merge_size=hf_config.spatial_merge_size,
|
||||
)
|
||||
|
||||
processor = EVSProcessor(
|
||||
hf_config=EVSModelConfig(spatial_merge_size=3),
|
||||
config_to_evs_model={EVSModelConfig: EVSModel},
|
||||
)
|
||||
expected = EVSConfig(video_pruning_rate=0.1, spatial_merge_size=3)
|
||||
assert asdict(processor.evs_config) == asdict(expected)
|
||||
|
||||
# No EVS for pruning rate 0.0
|
||||
processor = EVSProcessor(
|
||||
hf_config=EVSModelConfig(video_pruning_rate=0.0),
|
||||
config_to_evs_model={EVSModelConfig: EVSModel},
|
||||
)
|
||||
assert processor.evs_config is None
|
||||
|
||||
# No EVS for non-EVS config
|
||||
processor = EVSProcessor(
|
||||
hf_config=SimpleNamespace(),
|
||||
config_to_evs_model={EVSModelConfig: EVSModel},
|
||||
)
|
||||
assert processor.evs_config is None
|
||||
|
||||
|
||||
def test_replace_offsets_with_tokens_per_frame():
|
||||
from sglang.srt.multimodal.evs.evs_core import replace_offsets_with_tokens_per_frame
|
||||
|
||||
run_doctests(replace_offsets_with_tokens_per_frame)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.exit(pytest.main([__file__]))
|
||||
@@ -0,0 +1,64 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
import pytest
|
||||
|
||||
from sglang.srt.utils import sample_video_frames
|
||||
from sglang.test.ci.ci_register import register_cpu_ci
|
||||
|
||||
register_cpu_ci(est_time=5, suite="stage-a-cpu-only")
|
||||
|
||||
|
||||
class DummyVideo:
|
||||
def __init__(self, total_frames: int, avg_fps: float):
|
||||
self._frames = total_frames
|
||||
self._fps = avg_fps
|
||||
|
||||
def __len__(self):
|
||||
return self._frames
|
||||
|
||||
def get_avg_fps(self):
|
||||
return self._fps
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Case:
|
||||
frames: int
|
||||
avg_fps: float
|
||||
desired_fps: int
|
||||
max_frames: int
|
||||
expected_frames: list[int]
|
||||
description: str
|
||||
|
||||
|
||||
# fmt: off
|
||||
@pytest.mark.parametrize("case", [
|
||||
Case(
|
||||
frames=100, avg_fps=25.0, desired_fps=5, max_frames=200,
|
||||
expected_frames=[0, 5, 10, 15, 20, 26, 31, 36, 41, 46, 52, 57, 62, 67, 72, 78, 83, 88, 93, 99],
|
||||
description="capped by desired_fps"
|
||||
),
|
||||
Case(
|
||||
frames=10, avg_fps=10.0, desired_fps=100, max_frames=5,
|
||||
expected_frames=[0, 2, 4, 6, 9],
|
||||
description="capped by max_frames"
|
||||
),
|
||||
Case(
|
||||
frames=50, avg_fps=25.0, desired_fps=50, max_frames=200,
|
||||
expected_frames=list(range(50)),
|
||||
description="capped by total_frames"
|
||||
),
|
||||
Case(
|
||||
frames=1, avg_fps=30.0, desired_fps=0, max_frames=0,
|
||||
expected_frames=[0],
|
||||
description="always sample at least 1 frame"
|
||||
)
|
||||
], ids=lambda c: c.description)
|
||||
def test_sample_video_frames_lengths(case: Case):
|
||||
video = DummyVideo(case.frames, case.avg_fps)
|
||||
result = sample_video_frames(video, desired_fps=case.desired_fps, max_frames=case.max_frames)
|
||||
assert result == case.expected_frames
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.exit(pytest.main([__file__]))
|
||||
Reference in New Issue
Block a user