{"record":{"id":"2d02c912aec46047","repo":"Lightning-AI/pytorch-lightning","slug":"unknown-state-dict-type-self-state-dict-type-2d02c9","errorCode":null,"errorMessage":"Unknown state_dict_type: {self._state_dict_type}","messagePattern":"Unknown state_dict_type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/strategies/fsdp.py","lineNumber":528,"sourceCode":"        cls._registered_strategies.append(\"fsdp\")\n\n        strategy_registry.register(\n            \"fsdp_cpu_offload\",\n            cls,\n            description=\"Fully Sharded Data Parallel (FSDP) training with Full Sharding and CPU Offloading\",\n            cpu_offload=True,\n        )\n        cls._registered_strategies.append(\"fsdp_cpu_offload\")\n\n    @override\n    def lightning_module_state_dict(self) -> dict[str, Any]:\n        assert self.model is not None\n        if self._state_dict_type == \"sharded\":\n            state_dict_ctx = _get_sharded_state_dict_context(self.model)\n        elif self._state_dict_type == \"full\":\n            state_dict_ctx = _get_full_state_dict_context(self.model, world_size=self.world_size)\n        else:\n            raise ValueError(f\"Unknown state_dict_type: {self._state_dict_type}\")\n        with state_dict_ctx:\n            return self.model.state_dict()\n\n    @override\n    def load_model_state_dict(self, checkpoint: Mapping[str, Any], strict: bool = True) -> None:\n        # Override to do nothing, FSDP already loaded the states in `load_checkpoint()`\n        pass\n\n    @override\n    def optimizer_state(self, optimizer: Optimizer) -> dict[str, Tensor]:\n        from torch.distributed.fsdp import FullyShardedDataParallel as FSDP\n        from torch.distributed.fsdp import OptimStateKeyType\n\n        if isinstance(optimizer, LightningOptimizer):\n            optimizer = optimizer._optimizer\n\n        assert self.model is not None\n        if self._state_dict_type == \"sharded\":","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/fsdp.py#L510-L546","documentation":"FSDPStrategy can produce model state dicts in 'sharded' or 'full' format depending on self._state_dict_type. lightning_module_state_dict selects a context manager per type and raises ValueError for any other value, guarding against misconfigured strategy arguments.","triggerScenarios":"Constructing `FSDPStrategy(state_dict_type=<anything other than \"sharded\"/\"full\">)` and then saving a checkpoint (or otherwise asking for the module state dict), which invokes lightning_module_state_dict.","commonSituations":"Typos like `state_dict_type=\"full_state_dict\"` or `\"sharded_state_dict\"` (names from raw torch.distributed.fsdp APIs); passing an enum value where the string \"sharded\"/\"full\" is expected.","solutions":["Use one of the two supported literals: `FSDPStrategy(state_dict_type=\"sharded\")` or `\"full\"`","Check the strategy attribute before checkpointing if it comes from config: assert it in {\"sharded\", \"full\"}"],"exampleFix":"# before\nstrategy = FSDPStrategy(state_dict_type=\"full_state_dict\")\n\n# after\nstrategy = FSDPStrategy(state_dict_type=\"full\")","handlingStrategy":"validation","validationCode":"VALID = {\"sharded\", \"full\"}\nassert state_dict_type in VALID, f\"state_dict_type must be one of {VALID}\"\nstrategy = FSDPStrategy(state_dict_type=state_dict_type)","typeGuard":"def is_valid_state_dict_type(v: str) -> bool:\n    return v in (\"sharded\", \"full\")","tryCatchPattern":null,"preventionTips":["Use only the literals 'sharded' or 'full'","Fail fast on strategy construction rather than at checkpoint time"],"tags":["fsdp","state-dict","invalid-argument","checkpointing"],"backgroundTag":"invalid-state-dict-type","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}