-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Bugfix] Fix num video tokens calculation for Qwen2-VL #13148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Isotr0py
merged 3 commits into
vllm-project:main
from
DarkLight1337:fix-qwen2vl-num-tokens
Feb 12, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DarkLight1337 This may cause a warning, please see: QwenLM/Qwen2.5-VL#738
Due to padding in the process of
dummy_data
, shorter sequences do not affect the calculation ofnum_gpu_blocks
andnum_gpu_blocks
in the KV cache. Therefore, using a rounding-down operation is more appropriate.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using round-down results in the error shown in #13099 because of the mismatch in token count. The warning is not affected by this PR (nor #13012) because the default
_MAX_FRAMES_PER_VIDEO
is 16 which is divisible by 2, so no padding is applied.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is intentional because it is indeed possible for the context length to be exceeded if you pass in too many video frames.
For example,
means that 16384 tokens are reserved for images while 114688 tokens are reserved for videos. If you pass max number of images and videos together, then there will be a total of 131072 tokens which indeed exceeds the context length of the model (128000).
Nevertheless, if you only intend to pass images to the model, you don't have to worry about the warning as only 16384 tokens (16384 image and 0 video tokens) can exist in practice. To silence the warning, you can set
--limit-mm-per-prompt video=0
to prevent videos from being passed to the model at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DarkLight1337 Yes, your fix is right, and padding num_frames in
_get_vision_info
is the same as applying a floor function to themax_total_frames
value obtained from_get_max_video_frames
in the original implementation. Crucially, this also guarantees that the result is divisible by temporal_patch_size(2).