-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
VLMs: fix number of image tokens #34332
Changes from 2 commits
a413761
cdce455
48b294e
65cd04e
3a5b058
4b81d36
11762b5
8211a79
6477ea6
361182b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,8 +518,9 @@ def forward( | |
|
||
# TODO: @raushan retain only the new behavior after v4.47 | ||
else: | ||
n_image_tokens = (input_ids == self.config.image_token_index).sum(dim=-1)[0].item() | ||
n_image_features = image_features.shape[1] | ||
n_image_tokens = (input_ids == self.config.image_token_index).sum().item() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this slows down inference no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, if the image is padded it is usually unpadded before we come to this point, e.g in llava-next. Hm, I don't think the slowdown will be drastic especially since we need to check once per input in the pre-fill stage |
||
n_image_features = image_features.shape[0] * image_features.shape[1] | ||
|
||
if n_image_tokens != n_image_features: | ||
raise ValueError( | ||
f"Image features and image tokens do not match: tokens: {n_image_tokens}, features {n_image_features}" | ||
|
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.
rebasing should fix this!