Repository navigation
Conversation
Video frames are padded up to a multiple of temporal_patch_size, but smart_resize checked the budget with a round()-based t_bar (which can under-count odd frame counts) and computed beta with the unpadded num_frames, so the padded output could exceed max_pixels. Use ceil() for t_bar (restoring the semantics of huggingface#42083, unintentionally changed by the modularization in huggingface#47573) and compute both beta values from t_bar. Hand-edited the two glm4v sources and propagated via `python utils/checkers.py copies,modular_conversion --fix` to all affected qwen-like processors. Add regression tests for odd-frame budget enforcement and even-frame/image no-op behavior. Fixes huggingface#50871
Contributor
|
Thank you for your contribution 🤗! CI Security Gate — waiting for maintainer approvalCI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it. |
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: cohere_compass, cosmos3_edge, glm46v, glm4v, glmga, hy_v4_vl, qwen3_vl |
This branch has not been deployed
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.
What does this PR do?
Fixes #50871
Video processors pad the frame count up to a multiple of
temporal_patch_size(e.g. 57 → 58, 5 → 6), butsmart_resizesizes the spatial dimensions against the unpadded frame count. As a result, the final padded output can exceedmax_pixels(size.longest_edge), which breaks downstream consumers that pre-allocate buffers from that budget (e.g. vLLM's encoder cache:24882 > 24576embedding tokens for a 57-frame 720x1280 video with a 50331648-pixel budget).Two issues in
smart_resize:t_bar = round(num_frames / temporal_factor) * temporal_factorcan under-count odd frame counts (round(5 / 2) * 2 = 4, while padding always pads up to 6).ceilwas originally introduced in fix qwen2vl/qwen3vl video processor temporal padding when num_frames%temporal_patch_size!=1 #42083 together with the frame-padding fix; it appears to have been unintentionally changed back toroundduring the modularization in Modularize qwen-format vision processors #47573 (no review discussion mentions this change). This PR restores theceilsemantics.betacomputations use the unpaddednum_frames, so even with a correctt_barthe downscale factor is too small andt_bar * h_bar * w_bar > max_pixelsstill holds after resizing. Both branches now computebetafromt_bar.Both changes are needed together: with
ceilonly, the 5-frame repro below still returns 64x64 (beta ≈ 1); with thebetafix only,t_bar = 4under-counts and the over-budget branch never triggers.As suggested in #50871 (comment) ("prob affects more models ... Feel free to open a PR fixing all at once"), this fixes all affected qwen-like processors in one PR.
How the change is propagated
Only two hand-written sources are edited:
glm4v/image_processing_glm4v.py(source of thesmart_resizechain)glm4v/image_processing_pil_glm4v.py(hand-written twin with no sync mechanism, inherited by the glm46v/glmga/cosmos3_edge PIL processors)The remaining 13 files are regenerated with:
python utils/checkers.py copies,modular_conversion --fix
(
copiessyncsglm4v/video_processing_glm4v.pyvia the# Copied frommarker; the modular generator inlinessmart_resizetransitively into qwen3_vl, glmga, glm46v, cosmos3_edge, and — on a second run, since they import from the generated qwen3_vl file — cohere_compass and hy_v4_vl.) Read-onlycopiesandmodular_conversionchecks pass.Affected families: qwen3_vl, glm4v, glm46v, glmga, cosmos3_edge, cohere_compass, hy_v4_vl. The 2D per-frame-budget variants (qwen2_vl, video_llama_3, etc.) have no temporal padding and are unaffected. Image inputs are unaffected: there
num_frames == temporal_factor, sot_bar == num_framesand the change is a no-op (covered by a test).Verified behavior
max_pixels=20480max_pixels=50331648Tests
Added to
tests/models/qwen3_vl/test_video_processing_qwen3_vl.py:test_smart_resize_odd_frames_respects_max_pixels— the 5-frame and 57-frame repros abovetest_smart_resize_odd_frames_processor_output_fits_budget— end-to-end processor output shape for the 5-frame casetest_smart_resize_even_frames_and_images_unchanged— guards that even-frame and image behavior is untouchedqwen3_vlandglm4vvideo/image processing suites pass locally (64 passed). Other affected families' suites were also run; the only failures reproduce identically on unmodifiedmain(local environment issues, unrelated to this change).Out of scope / follow-up
The
cap_pixels_per_framepath computesmax_pixels = pixels_per_frame * num_frameswith the unpadded count before callingsmart_resize. With this fix the output is guaranteed to fit that (slightly under-counted) budget, but the budget itself arguably should also use the padded count. Happy to address it here or in a follow-up — would appreciate a maintainer's opinion (@zucchini-nlp).Before submitting checklist
smart_resizecomputesbetawith unpaddednum_frames, so padded output exceedsmax_pixels(size.longest_edge) #50871copies,modular_conversion) pass