[Bugfix] Avoid enlarging MiniMax H3 reference images and videos (#8253)

Signed-off-by: lishunyang12 <lishunyang12@users.noreply.github.com>
Co-authored-by: lishunyang12 <lishunyang12@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
This commit is contained in:
authored and GitHub committed 2026-09-28 20:12:53 +00:00
1 parent b656fcf45b
commit 7266fc6138
5 files changed
+105 -26

No files matched your search

@@ -138,7 +138,7 @@ def test_local_encoder_modes_preserve_validated_text_and_unified_handoff(task, t
(image.height // 32) * (image.width // 32), 96
)
pipeline.audio_vae = Mock()
prompt = {"prompt": "A person waves."}
prompt: dict[str, Any] = {"prompt": "A person waves."}
if task != "t2va":
prompt["multi_modal_data"] = {"image": Image.new("RGB", (256, 256))}
if text_key is not None:
@@ -1487,19 +1487,39 @@ def test_rainfusion_packed_padding_stays_mask_free_on_unaligned_lengths():
assert metadata.extra["valid_kv_length"] == 5
def test_reference_image_resize_contract():
@pytest.mark.parametrize(
("size", "expected"),
[
((1344, 768), (1344, 768)),
((640, 384), (640, 384)),
((2688, 1536), (2688, 1536)),
((1536, 2688), (1536, 2688)),
((3072, 3072), (3072, 3072)),
((1080, 1440), (1088, 1440)),
((648, 392), (640, 384)),
],
)
def test_reference_image_resize_contract(size, expected):
from PIL import Image
from vllm_omni.model_executor.models.minimax_h3.preprocessing import (
resolve_minimax_h3_reference_image_shape,
)
assert resolve_minimax_h3_reference_image_shape(Image.new("RGB", (1080, 1440))) == (
2048,
2720,
assert resolve_minimax_h3_reference_image_shape(Image.new("RGB", size)) == expected
def test_reference_image_resize_rejects_invalid_input():
from PIL import Image
from vllm_omni.model_executor.models.minimax_h3.preprocessing import (
resolve_minimax_h3_reference_image_shape,
)
with pytest.raises(ValueError, match="aspect ratio"):
resolve_minimax_h3_reference_image_shape(Image.new("RGB", (100, 501)))
with pytest.raises(ValueError, match="dimensions"):
resolve_minimax_h3_reference_image_shape(Image.new("RGB", (128, 128)))
def test_fl2va_supports_first_last_and_explicit_frame_index_contracts():
@@ -1678,13 +1698,26 @@ def test_encoder_forward_forwards_video_inputs():
)
def test_reference_video_shape_uses_h3_adapt_shape_policy():
@pytest.mark.parametrize(
("size", "expected"),
[
((640, 384), (640, 384)),
((384, 640), (384, 640)),
((1280, 720), (1280, 704)),
((1344, 768), (1344, 768)),
((1920, 1152), (1280, 768)),
((1152, 1920), (768, 1280)),
((3844, 2160), (1344, 768)),
((2160, 3844), (768, 1344)),
((2048, 2048), (768, 768)),
],
)
def test_reference_video_shape_caps_large_inputs_without_enlarging_small_inputs(size, expected):
from vllm_omni.model_executor.models.minimax_h3.reference_video import (
_reference_video_shape,
)
assert _reference_video_shape(1280, 720) == (1344, 768)
assert _reference_video_shape(3844, 2160) == (1344, 768)
assert _reference_video_shape(*size) == expected
def test_text_encoder_stub_constructs_without_group_or_weights():
@@ -2398,20 +2431,22 @@ def test_ref2va_reference_count_validation_preserves_client_error_metadata():
@pytest.mark.parametrize(
("case", "start_time", "expected_duration"),
("case", "start_time", "expected_duration", "input_size", "expected_size"),
[
("R7", None, 10.0),
("R8", 4.0, 6.0),
("R7", None, 10.0, (3844, 2160), (1344, 768)),
("R8", 4.0, 6.0, (640, 384), (640, 384)),
],
)
def test_r7_r8_ref2va_video_segment_matrix(monkeypatch, tmp_path, case, start_time, expected_duration):
def test_r7_r8_ref2va_video_segment_matrix(
monkeypatch, tmp_path, case, start_time, expected_duration, input_size, expected_size
):
from vllm_omni.diffusion.models.minimax_h3 import reference_video as reference_video_module
source = tmp_path / f"{case}.mp4"
source.touch()
metadata = {
"width": 1280,
"height": 720,
"width": input_size[0],
"height": input_size[1],
"fps": 24.0,
"frame_count": 240,
"duration": 10.0,
@@ -2440,6 +2475,8 @@ def test_r7_r8_ref2va_video_segment_matrix(monkeypatch, tmp_path, case, start_ti
assert prepared[0]["start_time_seconds"] == pytest.approx(start_time or 0.0)
assert transcode_calls[0][1]["duration_seconds"] == pytest.approx(expected_duration)
assert transcode_calls[0][1]["target_frame_count"] == 209
assert (prepared[0]["width"], prepared[0]["height"]) == expected_size
assert (transcode_calls[0][1]["target_width"], transcode_calls[0][1]["target_height"]) == expected_size
def test_ref2va_transcode_zero_frame_count_keeps_video_stream(monkeypatch, tmp_path):