-
Notifications
You must be signed in to change notification settings - Fork 31.4k
fix: Add method to get image features in PaliGemmaForConditionalGeneration #38730
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7451359
fix: Add method to retrieve image features in PaliGemmaForConditional…
YushunXiang ca15ded
feat: Add get_image_features method to multiple models for image feat…
YushunXiang 247f9ce
Merge branch 'huggingface:main' into fix-paligemma
YushunXiang 5e17cd1
fix: reformat the files with ruff.
YushunXiang 9fe8078
feat: Add methods for packing and retrieving image and video features…
YushunXiang 67461fb
feat: Implement get_image_features method in Aria, Mistral3, and VipL…
YushunXiang 7ed85ba
fix: reformatted the code with fix-style
YushunXiang 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -747,6 +747,28 @@ def set_decoder(self, decoder): | |
| def get_decoder(self): | ||
| return self.model | ||
|
|
||
| def pack_image_features(self, image_features, image_sizes, vision_feature_select_strategy, image_newline=None): | ||
| return self.model.pack_image_features( | ||
| image_features=image_features, | ||
| image_sizes=image_sizes, | ||
| vision_feature_select_strategy=vision_feature_select_strategy, | ||
| image_newline=image_newline, | ||
| ) | ||
|
|
||
| def get_image_features( | ||
|
Member
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. can we also add the |
||
| self, | ||
| pixel_values: torch.FloatTensor, | ||
| image_sizes: torch.Tensor, | ||
| vision_feature_layer: Optional[Union[int, List[int]]] = None, | ||
| vision_feature_select_strategy: Optional[str] = None, | ||
| ): | ||
| return self.model.get_image_features( | ||
| pixel_values=pixel_values, | ||
| image_sizes=image_sizes, | ||
| vision_feature_layer=vision_feature_layer, | ||
| vision_feature_select_strategy=vision_feature_select_strategy, | ||
| ) | ||
|
|
||
| # Make modules available throught conditional class for BC | ||
| @property | ||
| def language_model(self): | ||
|
|
@@ -988,5 +1010,17 @@ def _prepare_4d_causal_attention_mask_with_cache_position( | |
|
|
||
| return causal_mask | ||
|
|
||
| def get_video_features( | ||
| self, | ||
| pixel_values: torch.FloatTensor, | ||
| vision_feature_layer: Optional[Union[int, List[int]]] = None, | ||
| vision_feature_select_strategy: Optional[str] = None, | ||
| ): | ||
| return self.model.get_video_features( | ||
| pixel_values=pixel_values, | ||
| vision_feature_layer=vision_feature_layer, | ||
| vision_feature_select_strategy=vision_feature_select_strategy, | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ["LlavaOnevisionModel", "LlavaOnevisionForConditionalGeneration", "LlavaOnevisionPreTrainedModel"] | ||
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
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
Oops, something went wrong.
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.
for chameleon and emu3, the helper was
get_image_tokens. Can we propagate that too?