{"record":{"id":"fd8c653feec18fff","repo":"Lightning-AI/pytorch-lightning","slug":"got-fsdpstrategy-load-checkpoint-state-state","errorCode":null,"errorMessage":"Got FSDPStrategy.load_checkpoint(..., state={state!r}) but a state with at least  a model instance to reload is required. Pass it in like so: FSDPStrategy.load_checkpoint(..., state={'model': model, ...})","messagePattern":"Got FSDPStrategy\\.load_checkpoint\\(\\.\\.\\., state=(.+?)\\) but a state with at least  a model instance to reload is required\\. Pass it in like so: FSDPStrategy\\.load_checkpoint\\(\\.\\.\\., state=(.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/strategies/fsdp.py","lineNumber":532,"sourceCode":"                        converted = obj.state_dict() if isinstance(obj, _Stateful) else obj\n                    _apply_filter(key, filter or {}, converted, full_state)\n\n            if self.global_rank == 0:\n                _atomic_save(full_state, path)\n        else:\n            raise ValueError(f\"Unknown state_dict_type: {self._state_dict_type}\")\n\n    @override\n    def load_checkpoint(\n        self,\n        path: _PATH,\n        state: Optional[Union[Module, Optimizer, dict[str, Union[Module, Optimizer, Any]]]] = None,\n        strict: bool = True,\n        weights_only: Optional[bool] = None,\n    ) -> dict[str, Any]:\n        \"\"\"Load the contents from a checkpoint and restore the state of the given objects.\"\"\"\n        if not state:\n            raise ValueError(\n                f\"Got FSDPStrategy.load_checkpoint(..., state={state!r}) but a state with at least \"\n                f\" a model instance to reload is required. Pass it in like so:\"\n                \" FSDPStrategy.load_checkpoint(..., state={'model': model, ...})\"\n            )\n        # broadcast the path from rank 0 to ensure all the states are loaded from a common path\n        path = _resolve_path(self.broadcast(path))\n\n        if isinstance(state, Module):\n            from lightning.fabric.strategies.model_parallel import _load_raw_module_state_from_path\n\n            _load_raw_module_state_from_path(path, module=state, world_size=self.world_size, strict=strict)\n            return {}\n\n        if isinstance(state, Optimizer):\n            raise NotImplementedError(\n                \"Loading a single optimizer object from a checkpoint is not supported yet with the FSDP strategy.\"\n            )\n","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/fsdp.py#L514-L550","documentation":"FSDPStrategy.load_checkpoint requires the caller to pass a state containing at least one model instance so it knows which module to load the sharded weights into. Passing None, an empty dict, or a falsy state is rejected up front.","triggerScenarios":"Calling fsdp_strategy.load_checkpoint(path) with no state argument, or load_checkpoint(path, {}) or load_checkpoint(path, None).","commonSituations":"Assuming load_checkpoint returns a fully constructed model (as some checkpoint utilities do); adapting code from a strategy whose load_checkpoint accepts state=None; forgetting to pass the model after refactoring a training script.","solutions":["Pass the model: load_checkpoint(path, {'model': model, 'optimizer': optimizer})","Ensure the model was set up through the strategy (fabric.setup(module)) before loading","If you only want raw weights, use the single-module form load_checkpoint(path, module)"],"exampleFix":"# before\nstate = strategy.load_checkpoint(path)\nmodel = state['model']\n# after\nstrategy.load_checkpoint(path, state={'model': model, 'optimizer': optimizer})","handlingStrategy":"validation","validationCode":"if not state or not any(hasattr(v, 'load_state_dict') for v in state.values()):\n    raise ValueError('state must contain the model to load into')","typeGuard":"def has_loadable_model(state) -> bool:\n    return bool(state) and any(hasattr(v, 'load_state_dict') for v in state.values())","tryCatchPattern":null,"preventionTips":["Always pass state={'model': model, ...} to load_checkpoint","Remember FSDP loading restores into your existing objects; it does not return new ones"],"tags":["fsdp","checkpoint","load","validation","pytorch-lightning"],"backgroundTag":"missing-required-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}