-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Add: num_additional_image_tokens to models #35052
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
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f7b66a9
Add: num_additional_image_tokens to models
jp1924 17ca285
docs: update docstring for num_additional_image_tokens in configurati…
jp1924 5093d49
Add num_additional_image_tokens to LlavaNextVideo model and update fe…
jp1924 264f848
revert
jp1924 b666b29
Fix: adjust num_image_tokens calculation in LlavaProcessor
jp1924 e17d95e
Remove num_additional_image_tokens initialization from configuration …
jp1924 925eaef
Fix test error
jp1924 0eb8415
revert
jp1924 301a669
Fix: adjust num_image_tokens calculation in LlavaNextVideoProcessor
jp1924 8ee4024
fix conflict
jp1924 139e6af
Merge branch 'main' into img_mismatch_error
jp1924 114283b
Fix: adjust num_image_tokens calculation in VideoLlavaProcessor
jp1924 bd3765d
Merge branch 'main' into img_mismatch_error
zucchini-nlp bb73040
make style
zucchini-nlp 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
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
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
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
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.
L163: we add
self.num_additional_image_tokensL165: we subtract
1Might that lead to a discrepancy?
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.
@qubvel
In the existing model code,
selected_image_feature[:, 1:]is also hardcoded with1, so there won't be any discrepancy.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.
If I got it right the idea is that "default" behaviour always slice one feature, while "full" does not slice anything. Why do we need
self.num_additional_image_tokensthen? Would it be more correct to fix the modeling code instead to make it consistent? @zucchini-nlp wdyt?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.
We add
num_additional_image_tokensto account for the ViTs with/without CLS, so currently it is either 0 or 1. Then the modeling code has two options to select the features, either crop 1 token or take the full embeddings. So, the main reason why we addednum_additional_image_tokensin the first place was to make processor flexible for different types of ViT and calculate image patch length frompatch_size.@qubvel hmm, not sure I got what you mean by modifying the model code?
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.
I just trying to unedrstand why do we need both
num_additional_image_tokensandvision_feature_select_strategyin processor. As far as I understandnum_additional_image_tokensis enough to computenum_image_tokens, or am I missing something?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.
Not sure I got the whole picture 🥲 but yeah, introducing two dependent parameters might be confusing, am I right that we should only use it as follows?
num_additional_image_tokens = 1ANDvision_feature_select_strategy = "default"num_additional_image_tokens = 0ANDvision_feature_select_strategy = "full"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.
I see, confusing picture here. Yes, currently I think those two are the combinations used but other combinations should not be a problem. For ex, if one wants to keep CLS for any reason and experiment with that
num_additional_image_tokens = 1ANDvision_feature_select_strategy = "full"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.
Ok, I hope I got it now 😄 let's ensure we have some docs and comments regarding it, cause it looks not obvious
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.
Maybe "default" is not the best name for it, cause I expected it to be like "remove cls token if it exists", but it looks like it is "remove first token in any case"
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.
hehe, the naming comes from original implementation. I will update the docstring for more clarity then, in a subsequent PR since this one is about fixing a bug