Skip to content

Fix compatibility with transformers >= 5#123

Open
zeyuyang8 wants to merge 1 commit into
zai-org:mainfrom
zeyuyang8:fix/transformers5-compat
Open

Fix compatibility with transformers >= 5#123
zeyuyang8 wants to merge 1 commit into
zai-org:mainfrom
zeyuyang8:fix/transformers5-compat

Conversation

@zeyuyang8

@zeyuyang8 zeyuyang8 commented Jul 24, 2026

Copy link
Copy Markdown

image-reward (PyPI 1.5) fails to import/run under transformers >= 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_indices removed from pytorch_utils in 5.x (it moved there from modeling_utils in 4.x). Vendor the original implementation as a fallback.
  • get_head_mask / _convert_head_mask_to_5d removed from ModuleUtilsMixin. Vendor them on BertPreTrainedModel.
  • Weight tying reworked (all_tied_weights_keys); this BLIP BERT ties nothing at inference, so tie_weights is overridden as a no-op.
  • BertTokenizer.additional_special_tokens_ids gone; use convert_tokens_to_ids('[ENC]').

Tested against transformers 5.14.1: RM.load('ImageReward-v1.0') loads and score() returns sensible values.

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
zeyuyang8 force-pushed the fix/transformers5-compat branch from 6bd2ef3 to 183f0e4 Compare July 24, 2026 00:57
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.

1 participant