Fix: Prevent crash when trying to load SigLIP/CLIP encoders with transformers >= 5.6.0#1443
Open
Aaron-d-k wants to merge 2 commits into
Open
Fix: Prevent crash when trying to load SigLIP/CLIP encoders with transformers >= 5.6.0#1443Aaron-d-k wants to merge 2 commits into
Aaron-d-k wants to merge 2 commits into
Conversation
Collaborator
|
Hi @Aaron-d-k! Thank you for both finding and fixing this bug. This is an excellent solution to the problem. For testing, I'd recommend following the example set in |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Currently, trying to run any model using the SigLIP or CLIP encoder (Eg: google/gemma-3-4b-it) using a default installation of transformer-lens from PyPI crashes due to a change introduced in the transformers library in 5.6.0 (commits: huggingface/transformers#44431). Both SiglipVisionModel and CLIPVisionModel had their structure slightly changed.
This issue arises because currently pyproject.toml in transformer-lens only specifies a minimum version.
There are three fixes I considered:
I have done 3. My change should not affect any users with transformers<5.6.0 or those who do not use the model, so is entirely backward compatible. It basically checks if the required attribute is missing when
set_original_componentis called and tries to monkey patch it in if it is necessary.Type of change
Screenshots
Before (transformers==5.8.1, demos/Gemma3_Multimodal.ipynb):


After fix:
Checklist: