Skip to content

Commit

Permalink
Fix text.transformer.embeddings.position_ids key error (#595)
Browse files Browse the repository at this point in the history
* fix create_model & test

* better fix: explained & strict
  • Loading branch information
EIFY authored Aug 28, 2023
1 parent ab1ae01 commit 8556945
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/open_clip/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def load_checkpoint(model, checkpoint_path, strict=True):
# detect old format and make compatible with new format
if 'positional_embedding' in state_dict and not hasattr(model, 'positional_embedding'):
state_dict = convert_to_custom_text_state_dict(state_dict)
# Certain text transformers no longer expect position_ids after transformers==4.31
position_id_key = 'text.transformer.embeddings.position_ids'
if position_id_key in state_dict and not hasattr(model, position_id_key):
del state_dict[position_id_key]
resize_pos_embed(state_dict, model)
incompatible_keys = model.load_state_dict(state_dict, strict=strict)
return incompatible_keys
Expand Down

0 comments on commit 8556945

Please sign in to comment.