{
  "id": "pytorch/fsdp-unexpected-key",
  "signature": "RuntimeError: FSDP checkpoint loading failed: Unexpected key(s) in state_dict: \"module._fsdp_wrapped_module.flat_param\"",
  "signature_zh": "运行时错误：FSDP 检查点加载失败：状态字典中存在意外键：\"module._fsdp_wrapped_module.flat_param\"",
  "regex": "RuntimeError: FSDP checkpoint loading failed: Unexpected key\\(s\\) in state_dict",
  "domain": "pytorch",
  "category": "module_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "状态字典包含 FSDP 内部键（例如 flat_param），加载到非 FSDP 模型时这些键是意外的，或者保存和加载时的 FSDP 包装层次不匹配。",
  "versions": [
    {
      "version": "torch>=2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "FSDP>=1.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Simply ignoring the unexpected keys with strict=False may lead to incorrect model weights.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Renaming state_dict keys manually often introduces errors and is not scalable.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Save the model state_dict with `state_dict` method instead of the FSDP wrapped module's state_dict, using `model.state_dict()` after unwrapping.",
      "success_rate": 0.85,
      "how": "Save the model state_dict with `state_dict` method instead of the FSDP wrapped module's state_dict, using `model.state_dict()` after unwrapping.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `torch.distributed.fsdp.FullyShardedDataParallel.summon_full_params(model)` to get a full state_dict without FSDP keys.",
      "success_rate": 0.8,
      "how": "Use `torch.distributed.fsdp.FullyShardedDataParallel.summon_full_params(model)` to get a full state_dict without FSDP keys.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Save the model state_dict with `state_dict` method instead of the FSDP wrapped module's state_dict, using `model.state_dict()` after unwrapping.",
    "Use `torch.distributed.fsdp.FullyShardedDataParallel.summon_full_params(model)` to get a full state_dict without FSDP keys."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/fsdp.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2023-09-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}