[Bugfix][Multimodal] Fix PyNvVideoCodec video backend returning NCHW instead of NHWC (#51076)

Signed-off-by: Junpu Yu <davidyu@nvidia.com>
This commit is contained in:
Junpu Yu
2026-08-08 04:49:06 +00:00
committed by GitHub
parent 22a175921c
commit d3621c1eb3
2 changed files with 39 additions and 1 deletions
+20
View File
@@ -20,6 +20,7 @@ from vllm.multimodal.video import (
PYNVVIDEOCODEC_VIDEO_BACKEND,
VIDEO_LOADER_REGISTRY,
VideoLoader,
_pynvvc_frames_to_nhwc,
)
from ..utils import cosine_similarity, create_video_from_image, normalize_image
@@ -498,3 +499,22 @@ class TestMergeKwargsGpuBackendPolicy:
def test_unknown_backend_not_treated_as_gpu(self):
assert not VIDEO_LOADER_REGISTRY.backend_requires_gpu("totally_unknown")
@pytest.mark.parametrize("layout", ["nhwc", "nchw"])
def test_pynvvc_frames_normalized_to_nhwc(layout: str):
"""PyNvVideoCodec frame batches are normalized to NHWC regardless of the
per-frame layout the decoder emits (it has varied across versions), so the
HF video processors (which materialize a PIL image per frame) receive the
same NHWC shape as every other video backend."""
torch = pytest.importorskip("torch")
n, h, w, c = 4, 5, 6, 3
nhwc = torch.arange(n * h * w * c, dtype=torch.uint8).reshape(n, h, w, c)
frames = nhwc if layout == "nhwc" else nhwc.permute(0, 3, 1, 2).contiguous()
out = _pynvvc_frames_to_nhwc(frames)
assert out.shape == (n, h, w, c)
assert out.is_contiguous()
assert torch.equal(out, nhwc) # content preserved / correctly transposed