Repository navigation
fix(vid_vec_rep): handle transformers >=5.0 wrapping get_image_features in BaseModelOutputWithPooling #702
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
Open
kodepareek
wants to merge
1
commit into
main
Choose a base branch
from
fix/vid-vec-rep-transformers-v5-compat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: tattle-made/feluda
Length of output: 8284
🏁 Script executed:
Repository: tattle-made/feluda
Length of output: 8848
🌐 Web query:
site:github.com/huggingface/transformers CLIPModel get_image_features return_dict PR 42564💡 Result:
Pull Request
#42564in the Hugging Face transformers library introduced a breaking change (BC) to theget_image_features(along withget_text_features,get_audio_features, andget_video_features) methods for multi-modal models like CLIP [1][2]. Prior to this change, these helper methods typically returned a pooled embedding tensor directly [2]. With this update, they now return aBaseModelOutputWithPooling(or a subclass) by default, which includes thepooler_outputalongside other potential outputs such aslast_hidden_state,hidden_states(whenoutput_hidden_states=True), andattentions(whenoutput_attentions=True) [2]. If your existing code expects a tensor output (e.g.,features = model.get_image_features(inputs)), you must update it to access thepooler_outputattribute [2]. The recommended migration pattern is:python # Before image_features = model.get_image_features(inputs) # After outputs = model.get_image_features(inputs, return_dict=True) image_features = outputs.pooler_outputIf you explicitly passreturn_dict=True, the method returns aModelOutputobject [2]. This change was part of the preparation for Transformers v5 to provide more consistent output structures across different model architectures [2][3].Citations:
🏁 Script executed:
Repository: tattle-made/feluda
Length of output: 17788
🏁 Script executed:
Repository: tattle-made/feluda
Length of output: 2458
🌐 Web query:
Hugging Face transformers commit 55dadb865681d9330f7b1e8fec92156cc38cd253 modeling_clip.py get_image_features💡 Result:
Hugging Face transformers commit 55dadb865681d9330f7b1e8fec92156cc38cd253, titled "[BC] Update get_(text|image|audio|video)_features methods to return BaseModelOutputWithPooling", introduced a breaking change regarding how convenience methods like get_image_features behave [1]. Before this commit, get_image_features typically returned a pooled embedding tensor directly [1]. With this change, the method now returns a BaseModelOutputWithPooling object (or a subclass) [1]. This object contains several fields, most notably: - pooler_output: The pooled representation (equivalent to what was previously returned as the tensor) [1]. - last_hidden_state: The unpooled token or patch embeddings [1]. - hidden_states and attentions: Available when output_hidden_states=True or output_attentions=True are passed [1]. If your existing code expects a tensor, you should update it to extract the pooler_output from the returned object [1]:
python # Old way image_features = model.get_image_features(inputs) # New way outputs = model.get_image_features(inputs, return_dict=True) image_features = outputs.pooler_outputThis change was implemented as part of pull request#42564to standardize the output format for these multi-modal convenience methods across the library [1][2].Citations:
🏁 Script executed:
Repository: tattle-made/feluda
Length of output: 3748
Handle tuple outputs before reading
pooler_output.When Transformers v5 returns a tuple from
self.model.get_image_features(), the current branch accessespooler_outputon the tuple and can raiseAttributeError. Handle tuple outputs explicitly and add a regression test.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: MCP tools