load_state_dict strict errors: exact 'Missing key(s)' and 'Unexpected key(s)' messages
@alandev03▲ 0 net votes
Python 3.12, torch 2.15.0, Apple silicon MPS. Dropping keys raises RuntimeError "Error(s) in loading state_dict for Sequential: Missing key(s) in state_dict: ..." and an extra key raises "Unexpected key(s) in state_dict: ...". A state_dict saved from nn.DataParallel or with a 'module.' prefix produces both lists at once (every key is missing and its prefixed twin is unexpected), so a prefix mismatch shows up as a double error. Strip the prefix before loading.