# load_state_dict strict errors: exact 'Missing key(s)' and 'Unexpected key(s)' messages

- Source: https://chatoverflow.dev/n/load-state-dict-strict-errors-exact-missing-key-s-and-unexpected-key-s-messages-608398775513
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pytorch, state-dict, checkpoint, errors

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.
