[Bugfix][Model] Honor Molmo2 dummy video num_frames >= 2 override (#53830)

Signed-off-by: hungh <hungh@nvidia.com>

Hung Hoang (黄兴) committed Aug 26, 2026 at 13:47 UTC a5f82882a6afa08e65260704011de3321a3aa4a4
2 files changed +36 -1
tests/models/multimodal/processing/test_molmo2.py
+35 -1
@@ -3,9 +3,14 @@
3
4 from types import SimpleNamespace
5
6 +import pytest
7 import torch
8
8 -from vllm.model_executor.models.molmo2 import build_flat_image_bool_length
9 +from vllm.config.multimodal import VideoDummyOptions
10 +from vllm.model_executor.models.molmo2 import (
11 + Molmo2DummyInputsBuilder,
12 + build_flat_image_bool_length,
13 +)
14
15
16 def test_build_flat_image_bool_length_matches_molmoweb_processor_tokens():
@@ -54,3 +59,32 @@ def test_build_flat_image_bool_length_respects_disabled_col_tokens():
59 assert len(image_tokens) == 45
60 assert image_tokens[0].item() == hf_config.low_res_image_start_token_id
61 assert (image_tokens == hf_config.image_col_id).sum().item() == 0
62 +
63 +
64 +@pytest.mark.parametrize(
65 + ("num_frames_override", "expected_frames"),
66 + [(1, 2), (2, 2), (3, 3)],
67 +)
68 +def test_dummy_video_num_frames_override_honors_min_of_two(
69 + num_frames_override, expected_frames
70 +):
71 + """A ``num_frames`` override below 2 must be ignored (the model needs at
72 + least 2 frames), matching the "cannot be less than 2, will be ignored"
73 + warning."""
74 + builder = object.__new__(Molmo2DummyInputsBuilder)
75 + builder.info = SimpleNamespace(
76 + get_hf_processor=lambda: SimpleNamespace(
77 + video_processor=SimpleNamespace(size={"width": 64, "height": 64})
78 + ),
79 + get_num_frames_with_most_features=lambda seq_len, mm_counts: 16,
80 + get_image_size_with_most_features=lambda: (64, 64),
81 + )
82 +
83 + data = builder.get_dummy_mm_data(
84 + seq_len=128,
85 + mm_counts={"image": 0, "video": 1},
86 + mm_options={"video": VideoDummyOptions(num_frames=num_frames_override)},
87 + )
88 +
89 + video, _metadata = data["video"][0]
90 + assert video.shape[0] == expected_frames
vllm/model_executor/models/molmo2.py
+1
@@ -1879,6 +1879,7 @@ class Molmo2DummyInputsBuilder(BaseDummyInputsBuilder[Molmo2ProcessingInfo]):
1879 num_frames_override,
1880 )
1881 target_num_frames = min(target_num_frames, num_frames_override)
1882 + target_num_frames = max(target_num_frames, 2)
1883
1884 dummy_videos = self._get_dummy_videos(
1885 width=video_size["width"],