Skip to content

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
TransformerLensOrg:devfrom
Aaron-d-k:bug/siglip-transformers-fix
Open

Fix: Prevent crash when trying to load SigLIP/CLIP encoders with transformers >= 5.6.0#1443
Aaron-d-k wants to merge 2 commits into
TransformerLensOrg:devfrom
Aaron-d-k:bug/siglip-transformers-fix

Conversation

@Aaron-d-k

Copy link
Copy Markdown

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:

  1. Adding <5.6.0 to the toml
  2. Porting the entire library to 5.6.0
  3. Adding a backward compatible method that checks for the version and corrects for it.

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_component is called and tries to monkey patch it in if it is necessary.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Before (transformers==5.8.1, demos/Gemma3_Multimodal.ipynb):
Screenshot 2026-06-26 at 00-30-51 Gemma3_Multimodal - Jupyter Notebook
After fix:
Screenshot 2026-06-26 at 00-29-13 Gemma3_Multimodal - Jupyter Notebook

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (I am unsure how I should add tests for this)
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@jlarson4

Copy link
Copy Markdown
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 tests/unit/model_bridge/supported_architectures/test_gemma3_multimodal_adapter.py. It build a stub using SimpleNamespace that doesn't download the model, but can validate shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants