Skip to content

[Bugfix][MM] Fix OpenPangu video backend crash on num_frames=-1 - #56390

Open
hungnnvidia wants to merge 1 commit into
vllm-project:mainfrom
hungnnvidia:fix/openpangu-video-num-frames-sentinel
Open

hungnnvidia wants to merge 1 commit into
vllm-project:mainfrom
hungnnvidia:fix/openpangu-video-num-frames-sentinel

Conversation

@hungnnvidia

Copy link
Copy Markdown
Contributor

Purpose

OpenCVDynamicOpenPanguVideoBackend.compute_frames_index_to_sample never normalizes the num_frames = -1 ("no cap / all frames") sentinel that every other video backend honors via if num_frames > 0. The backend's own load_bytes default is num_frames=-1, so with the default the fps > 0 cap branch condition num_frames >= int(total_duration * fps) + 1 evaluates to -1 >= (>=1)False, leaving num_frames == -1, which then hits:

np.linspace(0, total_duration, num_frames, dtype=float)  # num_frames == -1

ValueError: Number of samples, -1, must be non-negative. The fps == -1 ("no fps limit") path crashes the same way.

Fix

Treat num_frames < 0 as "no cap":

  • fps > 0: use the fps-derived count (int(total_duration * fps) + 1).
  • fps == -1: sample every frame (total_frames_num).

Positive num_frames (within or above the fps cap) and the invalid-fps ValueError are unchanged.

Reproduction (from the real code)

Before (origin/main):

>>> OpenCVDynamicOpenPanguVideoBackend.compute_frames_index_to_sample(
...     VideoSourceMetadata(total_frames_num=100, original_fps=30, duration=100/30),
...     VideoTargetMetadata(num_frames=-1, fps=2, max_duration=300))
ValueError: Number of samples, -1, must be non-negative.

After:

num_frames=-1, fps=2   -> 7 indices,  range=[0,90], sorted, in-range   (was CRASH)
num_frames=-1, fps=-1  -> 100 indices, range=[0,99], sorted, in-range  (was CRASH)
num_frames=8,  fps=2   -> capped to fps count (unchanged)
num_frames=10000, fps=2-> capped to fps count (unchanged)
fps=0                  -> ValueError: requires dataset fps is -1 or greater than 0 (unchanged)

Test Plan / Result

  • Added test_openpangu_num_frames_sentinel (parametrized fps=2 and fps=-1) to tests/multimodal/test_video.py.
  • pytest tests/multimodal/test_video.py -k openpangu_num_frames_sentinel2 passed.
  • pre-commit run ruff-check --files vllm/multimodal/video.py tests/multimodal/test_video.py → Passed.

Not a duplicate

Searched open PRs on vllm-project/vllm (openpangu num_frames, OpenPangu video sampling); none address this. This is distinct from the recent zero-fps guard PRs (#54390 Qwen3-VL, #54396 GLM-GA), which fix a different ZeroDivisionError, not the num_frames=-1 sentinel.

Notes

The openpangu backend is opt-in (registered without a video_processor auto-mapping), but its own default parameter value crashes it, so any explicit selection without also overriding num_frames hits this. AI assistance was used to locate, reproduce, fix, and test this bug; a human has reviewed the change.

`OpenCVDynamicOpenPanguVideoBackend.compute_frames_index_to_sample` never
normalized the "-1 = no cap / all frames" sentinel that every other video
backend honors (`if num_frames > 0`). With the backend's own default
`num_frames=-1`, the `fps > 0` cap branch condition
`num_frames >= int(total_duration * fps) + 1` is `-1 >= (>=1)` -> False, so
`num_frames` stayed `-1` and reached `np.linspace(0, total_duration, -1)`,
raising `ValueError: Number of samples, -1, must be non-negative`. The
`fps == -1` path crashed the same way.

Treat `num_frames < 0` as "no cap": use the fps-derived count when `fps > 0`,
and sample every frame when `fps == -1`. Positive num_frames (within or above
the cap) and the invalid-fps error are unchanged.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Signed-off-by: hungh <hungh@nvidia.com>
@mergify mergify Bot added multi-modality Related to multi-modality (#4194) bug Something isn't working labels Sep 11, 2026
@hungnnvidia
hungnnvidia marked this pull request as ready for review September 11, 2026 04:29

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working multi-modality Related to multi-modality (#4194)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant