[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

@@ -1,4 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""Shared MiniMax H3 media normalization and Qwen presentation building.
Builds the positive presentation token stream:
@@ -34,7 +35,6 @@ _VIDEO_TAG = 0
MINIMAX_H3_OUTPUT_SHORT_EDGE = 768
MINIMAX_H3_OUTPUT_MAX_PIXELS = 768 * 1344
MINIMAX_H3_REFERENCE_IMAGE_SHORT_EDGE = 2048
MINIMAX_H3_REFERENCE_IMAGE_MULTIPLE = 32
MINIMAX_H3_SUPPORTED_ASPECT_RATIOS = {
"21:9": 21.0 / 9.0,
@@ -135,17 +135,16 @@ def resolve_minimax_h3_aspect_ratio(
def resolve_minimax_h3_reference_image_shape(image: Image.Image) -> tuple[int, int]:
"""Resize an H3 reference image to the official 2048-short-edge canvas."""
"""Preserve reference resolution, rounding each axis to the 32-pixel grid."""
width, height = image.size
ratio = width / height
if not 0.4 <= ratio <= 2.5:
raise OmniClientError(f"reference image aspect ratio must be in [0.4, 2.5], got {width}x{height}")
if min(width, height) < 256 or max(width, height) > 5760:
raise OmniClientError(f"reference image dimensions must be in [256, 5760] pixels, got {width}x{height}")
scale = MINIMAX_H3_REFERENCE_IMAGE_SHORT_EDGE / min(width, height)
return (
_align_multiple(width * scale, MINIMAX_H3_REFERENCE_IMAGE_MULTIPLE),
_align_multiple(height * scale, MINIMAX_H3_REFERENCE_IMAGE_MULTIPLE),
_align_multiple(width, MINIMAX_H3_REFERENCE_IMAGE_MULTIPLE),
_align_multiple(height, MINIMAX_H3_REFERENCE_IMAGE_MULTIPLE),
)
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""MiniMax H3 Ref2VA reference-video preparation."""
from __future__ import annotations
@@ -65,9 +66,9 @@ def deserialize_prepared_reference_videos(value: str) -> tuple[str, list[dict[st
MINIMAX_H3_FPS = 24.0
MINIMAX_H3_QWEN_VIDEO_SAMPLE_FPS = 2.0
MINIMAX_H3_QWEN_TEMPORAL_PATCH = 2
MINIMAX_H3_CANVAS_MULTIPLE = 32
MINIMAX_H3_BASE_SHORT_EDGE = 768
MINIMAX_H3_MAX_PIXELS = 768 * 1344
MINIMAX_H3_CANVAS_MULTIPLE = 32
MINIMAX_H3_MIN_REFERENCE_DIMENSION = 256
MINIMAX_H3_MAX_REFERENCE_DIMENSION = 5760
MINIMAX_H3_MIN_REFERENCE_FPS = 23.976
@@ -290,6 +291,7 @@ def validate_reference_audio_waveforms(values: list[tuple[torch.Tensor, int]]) -
def _reference_video_shape(width: int, height: int) -> tuple[int, int]:
"""Fit large references to the video canvas without enlarging small inputs."""
if (
min(width, height) < MINIMAX_H3_MIN_REFERENCE_DIMENSION
or max(width, height) > MINIMAX_H3_MAX_REFERENCE_DIMENSION
@@ -309,10 +311,14 @@ def _reference_video_shape(width: int, height: int) -> tuple[int, int]:
scale = math.sqrt(MINIMAX_H3_MAX_PIXELS / area)
target_width *= scale
target_height *= scale
return (
_nearest_multiple(target_width, MINIMAX_H3_CANVAS_MULTIPLE),
_nearest_multiple(target_height, MINIMAX_H3_CANVAS_MULTIPLE),
)
canvas_width = _nearest_multiple(target_width, MINIMAX_H3_CANVAS_MULTIPLE)
canvas_height = _nearest_multiple(target_height, MINIMAX_H3_CANVAS_MULTIPLE)
if width * height < canvas_width * canvas_height:
return (
_nearest_multiple(width, MINIMAX_H3_CANVAS_MULTIPLE),
_nearest_multiple(height, MINIMAX_H3_CANVAS_MULTIPLE),
)
return canvas_width, canvas_height
def _transcode_reference_video(