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

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



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