{"record":{"id":"ba8bf433d9fce5fe","repo":"Lightning-AI/pytorch-lightning","slug":"could-not-find-a-fsdp-model-in-the-provided-checkp-ba8bf4","errorCode":null,"errorMessage":"Could not find a FSDP model in the provided checkpoint state. Please provide the model as part of the state like so: `load_checkpoint(..., state={'model': model, ...})`. Make sure you set up the model (and optimizers if any) through the strategy before loading the checkpoint.","messagePattern":"Could not find a FSDP model in the provided checkpoint state\\. Please provide the model as part of the state like so: `load_checkpoint\\(\\.\\.\\., state=(.+?)\\)`\\. Make sure you set up the model \\(and optimizers if any\\) through the strategy before loading the checkpoint\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/strategies/fsdp.py","lineNumber":556,"sourceCode":"        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\n        from torch.distributed.checkpoint.optimizer import load_sharded_optimizer_state_dict\n        from torch.distributed.fsdp import FullyShardedDataParallel as FSDP\n\n        modules = {key: module for key, module in state.items() if _has_fsdp_modules(module)}\n        if len(modules) == 0:\n            raise ValueError(\n                \"Could not find a FSDP model in the provided checkpoint state. Please provide the model as\"\n                \" part of the state like so: `load_checkpoint(..., state={'model': model, ...})`. Make sure\"\n                \" you set up the model (and optimizers if any) through the strategy before loading the checkpoint.\"\n            )\n        optimizers = {key: optim for key, optim in state.items() if isinstance(optim, Optimizer)}\n        if len(modules) > 1:\n            raise ValueError(\n                \"Found multiple FSDP models in the given state. Loading checkpoints with FSDP is\"\n                \" currently limited to a single model per checkpoint. To load multiple models, call the\"\n                \" load method for each model separately with a different path.\"\n            )\n        module_key, module = list(modules.items())[0]\n\n        if _is_sharded_checkpoint(path):\n            state_dict_ctx = _get_sharded_state_dict_context(module)\n\n            with state_dict_ctx:\n                module_state = {module_key: module.state_dict()}","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/fsdp.py#L538-L574","documentation":"When loading, the strategy scans the state dict for entries containing FSDP modules; if none are found it cannot determine where to restore weights. This happens when the model was never wrapped in FSDP (not set up through the strategy) or the state dict has no model at all.","triggerScenarios":"Calling load_checkpoint(path, {'model': plain_module}) where plain_module was not passed through fabric.setup/strategy.setup; or passing only non-module metadata like {'step': 1000}.","commonSituations":"Forgetting fabric.setup(model) before load; loading into a fresh, unwrapped module; applying FSDP wrapping manually after calling load; the model being wrapped in a non-FSDP parallel wrapper.","solutions":["Create the model and call fabric.setup(model) (which wraps it in FSDP) before load_checkpoint","Pass the wrapped model explicitly: state={'model': model} and verify isinstance(model, FullyShardedDataParallel) or that it contains FSDP submodules","If you wrapped FSDP manually, make sure the wrapper is on the object you pass in, not a discarded copy"],"exampleFix":"# before\nmodel = MyModel()\nstrategy.load_checkpoint(path, state={'model': model})\n# after\nmodel = MyModel()\nmodel, optimizer = fabric.setup(model, optimizer)\nstrategy.load_checkpoint(path, state={'model': model, 'optimizer': optimizer})","handlingStrategy":"validation","validationCode":"from torch.distributed.fsdp import FullyShardedDataParallel as FSDP\nassert any(isinstance(m, FSDP) for v in state.values() if hasattr(v, 'modules') for m in v.modules()), 'set up the model through fabric/strategy first'","typeGuard":"def state_has_fsdp(state: dict) -> bool:\n    from torch.distributed.fsdp import FullyShardedDataParallel as FSDP\n    return any(isinstance(m, FSDP) for v in state.values() if hasattr(v, 'modules') for m in v.modules())","tryCatchPattern":null,"preventionTips":["Call fabric.setup(model) before load_checkpoint","Keep a reference to the object returned by setup; that is the wrapped module to pass"],"tags":["fsdp","checkpoint","load","setup","pytorch-lightning"],"backgroundTag":"model-not-wrapped-by-strategy","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}