Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project

import numpy as np
import pytest
import torch
from PIL import Image

from vllm_omni.model_executor.models.minimax_h3.encoder_processing import _frames_to_tensor

pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]


@pytest.mark.parametrize("reverse_rows", [False, True])
def test_rgb_video_array_matches_framewise_conversion_and_owns_data(reverse_rows):
frames = np.arange(3 * 5 * 7 * 3, dtype=np.uint8).reshape(3, 5, 7, 3)
if reverse_rows:
frames = frames[:, ::-1]

expected = _frames_to_tensor([Image.fromarray(frame) for frame in frames])
actual = _frames_to_tensor(frames)

torch.testing.assert_close(actual, expected, rtol=0, atol=0)
assert actual.is_contiguous()
original_value = actual[0, 0, 0, 0].item()
frames[0, 0, 0, 0] = (original_value + 1) % 256
assert actual[0, 0, 0, 0].item() == original_value
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def _image_to_tensor(image: Image.Image) -> torch.Tensor:
def _frames_to_tensor(frames: Sequence[Any]) -> torch.Tensor:
if len(frames) == 0:
raise ValueError("MiniMax H3 reference video must contain frames")
if isinstance(frames, np.ndarray) and frames.dtype == np.uint8 and frames.ndim == 4 and frames.shape[-1] == 3:
# Keep the existing owned, contiguous output without converting each RGB frame through PIL.
return torch.from_numpy(np.array(frames, copy=True, order="C"))
return torch.stack(
[
_image_to_tensor(frame if isinstance(frame, Image.Image) else Image.fromarray(np.asarray(frame)))
Expand Down
Loading