Fix compatibility with transformers >= 5#123
Open
zeyuyang8 wants to merge 1 commit into
Open
Conversation
BLIP's vendored BERT (med.py) and tokenizer setup (blip.py) predate the
transformers 5 refactor. Fixes, all backward-compatible:
- med.py: transformers 5 dropped find_pruneable_heads_and_indices from
pytorch_utils (moved there from modeling_utils in 4.x); vendor the original
implementation as a fallback.
- med.py: transformers 5 stripped get_head_mask / _convert_head_mask_to_5d from
ModuleUtilsMixin; vendor them on BertPreTrainedModel.
- med.py: transformers 5 reworked weight tying (all_tied_weights_keys); the
BLIP BERT ties nothing at inference, so override tie_weights as a no-op.
- blip.py: BertTokenizer no longer exposes additional_special_tokens_ids;
use convert_tokens_to_ids('[ENC]') instead.
zeyuyang8
force-pushed
the
fix/transformers5-compat
branch
from
July 24, 2026 00:57
6bd2ef3 to
183f0e4
Compare
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.
image-reward(PyPI 1.5) fails to import/run undertransformers >= 5. BLIP's vendored BERT predates the transformers 5 refactor. Fixes (all backward-compatible — older transformers keep hitting the original paths):find_pruneable_heads_and_indicesremoved frompytorch_utilsin 5.x (it moved there frommodeling_utilsin 4.x). Vendor the original implementation as a fallback.get_head_mask/_convert_head_mask_to_5dremoved fromModuleUtilsMixin. Vendor them onBertPreTrainedModel.all_tied_weights_keys); this BLIP BERT ties nothing at inference, sotie_weightsis overridden as a no-op.BertTokenizer.additional_special_tokens_idsgone; useconvert_tokens_to_ids('[ENC]').Tested against transformers 5.14.1:
RM.load('ImageReward-v1.0')loads andscore()returns sensible values.