Repository navigation
Conversation
Qwen3VL's processor wraps each video frame individually in <|vision_start|>...<|vision_end|> tags (with a timestamp prefix), so mm_token_type_ids contains T separate type-2 groups for a video that has T temporal frames. get_rope_index iterates video_grid_thw once per type-2 group, but video_grid_thw only has one entry per *video* with shape [T, H, W]. After the first frame the iterator is exhausted and subsequent calls to next() raise StopIteration. Fix: expand video_grid_thw from per-video entries [T, H, W] into per-frame entries [1, H, W] before building grid_iters, so the number of iterator elements matches the number of type-2 groups the processor produces. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen3_vl |
Author
|
This was pretty much all Claude, for the record. I just woke up to my stuff not working when running Cosmos-Reason-2B on a fresh install. |
Member
Member
|
Fixed by #44474, by qwen team. I'll close this PR as duplicate and since it's code agent generated mostly |
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 fix?
Running video inference with any
Qwen3VLmodel raisesStopIterationduringmodel.generate():Root cause
Qwen3VL's processor (
processing_qwen3_vl.py) formats each video frame individually, prefixing it with a timestamp and wrapping it in its own<|vision_start|>…<|vision_end|>pair:This produces T separate type-2 groups in
mm_token_type_ids(one per frame, interleaved with type-0 text groups for the timestamps).get_rope_indexbuilds an iterator overvideo_grid_thwand callsnext()once per type-2 group it encounters. However,video_grid_thwhas one entry per video with shape[T, H, W]— not one entry per frame. For a 14-frame video, the iterator is exhausted after the very first frame and every subsequent call raisesStopIteration.This is a mismatch introduced when the per-frame timestamp feature was added to Qwen3VL's processor: the processor now emits T groups per video, but
get_rope_index(inherited from the Qwen2VL pattern) still expects a single contiguous block per video.Fix
Before building
grid_iters, expandvideo_grid_thwfrom per-video entries[T, H, W]into per-frame entries[1, H, W], giving the iterator exactly as many elements as there are type-2 groups inmm_token_type_ids:For a video with
video_grid_thw = [[14, 80, 44]], the expansion produces 14 rows of[1, 80, 44], matching the 14 type-2 groups the processor emits. Multiple videos in a batch are handled correctly: each[T_i, H, W]entry expands independently.Testing
Verified by running end-to-end video inference with
Qwen3VL-based models (e.g.Cosmos-Reason2-8B) on a real video file — inference now completes successfully and produces coherent output.A regression test should check that
get_rope_indexdoes not raise whenvideo_grid_thwhasT > 1andmm_token_type_idshas T separate type-2 groups (one per frame).Fix diagnosed and developed with assistance from Claude Code (Anthropic).