The issue of model-parameter mismatch.

#1
by JeeXR - opened

I download the file 'model_safetensors' from the files and versions. However, when I use 'timm.create_model('swinv2_tiny_window16_256.ms_in1k', checkpoint_path='./model.safetensors') to load this mode, there is an error stating that some unexpected keys in the state_dict, such as 'layers.0.blocks.1.attn_mask' and 'layers.1.blocks.1.attn_mask'.

PyTorch Image Models org
edited Apr 11

@JeeXR when you load via checkpoint_path it assumes an exact match between model and checkpoint. There are some pretrained weights were adaptation is done on load, attn_mask were changed from being persistent to non-persistent at some point.

You need to override the pretrained location with a local file as in this example

https://github.com/huggingface/pytorch-image-models/discussions/2069#discussioncomment-8532295

timm.create_model(
  'swinv2_tiny_window16_256.ms_in1k,
  pretrained=True,
  pretrained_cfg_overlay=dict(file='./model.safetensors'),
)

Sign up or log in to comment