[Bugfix][Multimodal] Fix video temporal padding estimates#49030
[Bugfix][Multimodal] Fix video temporal padding estimates#49030labAxiaoming wants to merge 1 commit into
Conversation
|
Hello~ Could you please help review this bug fix when you have a moment? Thankyou~ @DarkLight1337, @Isotr0py, @ywang96 |
| # https://github.com/huggingface/transformers/blob/v5.13.0/src/transformers/models/qwen2_vl/video_processing_qwen2_vl.py#L249-L252 | ||
| padded_num_frames = num_frames + (-num_frames % temporal_patch_size) |
There was a problem hiding this comment.
QQ: I think we have padded frames in video loader?
Lines 1636 to 1663 in 854c33f
There was a problem hiding this comment.
Thank for your review
_get_vision_info is used for vLLM-side token/budget estimation, dummy input sizing, and warmup. It is not the actual image/video preprocessing path; real inputs are still processed by the HF/model image or video processor.
if frames.shape[0] & 1:
frames = np.concatenate([frames, frames[-1:]], axis=0)
This code may be process real video and ensures the video has an even number of frames. If the frame count is odd, it duplicates the last frame and appends it, making the total frame count even. but if temporal_patch_size was not 2, such as 4, the origin frames was 17, paded frame was 18 after pad, 20 was expected.
the real video preprocess also on transformers huggingface/transformers#47141
Round video frame counts up to the next multiple of temporal_patch_size. The previous formula could underestimate vision tokens when the temporal patch size was greater than two. Update the six affected model estimators and add GLM4V regression coverage for temporal patch sizes 2, 4, and 8. Fixes vllm-project#47866 Signed-off-by: xiaoming <1259730330@qq.com>
Head branch was pushed to by a user without write access
184dc88 to
063d7ef
Compare
|
ci/pr fail seems OOM for Zyphra/Zamba2-1.2B-instruct model , but i have not modify about this model |
Fix Video Temporal Padding Token Estimates
Summary
Fix incorrect video token estimation when
temporal_patch_size > 2.Fix #47866
Root Cause
Several multimodal models used:
This only works reliably for
temporal_patch_size1 or 2. For example:The incorrect padding can make
grid_tand the estimated video token count toosmall. This affects vLLM-side budget estimation, dummy input sizing, and
warmup.
Changes
Replace the formula with:
Updated model paths:
MiMo additionally converts the padded frame count to
int, because itseffective_framesis calculated fromnum_frames * tokens_per_second.No shared helper or
math_utilschanges are introduced.Tests
test video and image in
GLM-OCRandQwen2-VL-7B-InstructmodelAdded a CPU-only regression test covering:
python -m pytest tests/models/multimodal/processing/test_glm4_1v.py -k test_vision_info_rounds_up_temporal_frames -vThe change only affects vLLM token estimation. Hugging Face preprocessing,
vision encoder computation, model weights, and generated outputs are unchanged.
Related Issues and PRs
vllm-project/vllm#47876:
it changes only the six call sites and adds focused regression coverage,
without introducing a shared helper or modifying common math utilities.
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.