[Security] Honor num_frames in Molmo2 default video sampling - #56207
Open
jperezdealgaba wants to merge 1 commit into
Open
jperezdealgaba wants to merge 1 commit into
jperezdealgaba wants to merge 1 commit into
Conversation
Co-authored-by: Cursor Agent Signed-off-by: Juan Pérez de Algaba <jperezde@redhat.com>
jperezdealgaba
requested review from
DarkLight1337,
Isotr0py,
NickLucche,
shen-shanshan,
tjtanaa and
ywang96
as code owners
September 10, 2026 07:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Molmo2 video loader's default sampling branch (
frame_sample_modeunset) returned every source frame and ignoredVideoTargetMetadata.num_frames. A client can select that CPU backend through requestmedia_io_kwargson an ordinary chat video request, so a small MP4 could expand into gigabytes of RGB even whennum_frameswas 1. This change uniformly samples at mostnum_frameswhen that cap is positive, and still returns all frames when the cap is unset (num_frames <= 0).Changes
vllm/multimodal/video.py: honor a positivenum_framesinMolmo2VideoBackend.compute_frames_index_to_samplewhenframe_sample_modeis omitted.tests/multimodal/test_video.py: unit and loader tests for capped, uniform, and unlimited default sampling.tests/multimodal/media/test_video.py:VideoMediaIOpath withvideo_backend=molmo2andnum_frames=1.Codepath coverage
MediaConnector.fetch_video/fetch_video_async→VideoMediaIO.load_bytes/load_file/ non-jpegload_base64→ Molmo2 loader: yes.Molmo2VideoBackend.load_bytes(samecompute_frames_index_to_sample): yes.loader_cls.compute_frames_index_to_sample(OpenCV/TorchCodec/etc.): yes.video/jpegcomma-split path: N/A (does not use the Molmo2 sampler).molmo2is a CPU backend).Duplicate-work check
Searched open and merged PRs for
Molmo2VideoBackend,compute_frames_index_to_sample,frame_sample_mode, andvideo_backend/num_frames. #51969 clamps request-levelnum_framesso clients cannot raise the engine ceiling; it does not make Molmo2's default branch read that ceiling. Other open video PRs cover GLM sampling, empty indices, or explicit frame-index selection. No open or merged PR closes this sink.Tests
test_molmo2_default_mode_honors_positive_num_framestest_molmo2_default_mode_uniformly_caps_to_num_framestest_molmo2_default_mode_keeps_all_frames_when_unlimitedtest_video_loader_frames_sampling[molmo2-default-honors-num_frames]test_molmo2_backend_honors_num_framesCommands:
.venv/bin/pre-commit run --files <changed files>(passed after ruff format);.venv/bin/python -m pyteston the tests above (7 passed).AI assistance
This PR was developed with AI assistance.
Made with Cursor