# RuntimeError: FSDP checkpoint loading failed: Unexpected key(s) in state_dict: "module._fsdp_wrapped_module.flat_param"

- **ID:** `pytorch/fsdp-unexpected-key`
- **Domain:** pytorch
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The state_dict contains FSDP internal keys (e.g., flat_param) that are not expected when loading into a non-FSDP model, or the FSDP wrapping hierarchy mismatches between save and load.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| torch>=2.0.0 | active | — | — |
| FSDP>=1.12 | active | — | — |

## Workarounds

1. **Save the model state_dict with `state_dict` method instead of the FSDP wrapped module's state_dict, using `model.state_dict()` after unwrapping.** (85% success)
   ```
   Save the model state_dict with `state_dict` method instead of the FSDP wrapped module's state_dict, using `model.state_dict()` after unwrapping.
   ```
2. **Use `torch.distributed.fsdp.FullyShardedDataParallel.summon_full_params(model)` to get a full state_dict without FSDP keys.** (80% success)
   ```
   Use `torch.distributed.fsdp.FullyShardedDataParallel.summon_full_params(model)` to get a full state_dict without FSDP keys.
   ```

## Dead Ends

- **** — Simply ignoring the unexpected keys with strict=False may lead to incorrect model weights. (80% fail)
- **** — Renaming state_dict keys manually often introduces errors and is not scalable. (90% fail)
