How to ignore and initialize Missing key(s) in state_dict

Hello,
My saved state_dict does not contain all the layers that are in my model. How can I ignore the Missing key(s) in state_dict error and initialize the remaining weights?
Thank you!

Pass strict=False to load_state_dict.
Then you can iterate for n, p in model.named_parameters() and do whatever you want for n not in sd or so.

Best regards

Thomas

2 Likes

It’s exactly what I was looking for, thank you so much!