{"record":{"id":"e20adf0ba0466355","repo":"Lightning-AI/pytorch-lightning","slug":"could-not-find-a-deepspeed-model-in-the-provided-c-e20adf","errorCode":null,"errorMessage":"Could not find a DeepSpeed 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 DeepSpeed 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/deepspeed.py","lineNumber":516,"sourceCode":"\n        \"\"\"\n        if isinstance(state, (Module, Optimizer)) or self.load_full_weights and self.zero_stage_3:\n            # This code path to enables loading a checkpoint from a non-deepspeed checkpoint or from\n            # a consolidated checkpoint\n            path = self.broadcast(path)\n            return super().load_checkpoint(path=path, state=state, strict=strict, weights_only=weights_only)\n\n        if not state:\n            raise ValueError(\n                f\"Got DeepSpeedStrategy.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                \" DeepSpeedStrategy.load_checkpoint(..., state={'model': model, ...})\"\n            )\n        _validate_checkpoint_directory(path)\n\n        engines = _get_deepspeed_engines_from_state(state)\n        if len(engines) == 0:\n            raise ValueError(\n                \"Could not find a DeepSpeed 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        if len(engines) > 1:\n            raise ValueError(\n                \"Found multiple DeepSpeed engine modules in the given state. Saving and loading checkpoints\"\n                \" with DeepSpeed is currently limited to a single model per checkpoint. To load multiple model\"\n                \" states, call the load method for each model checkpoint separately.\"\n            )\n        engine = engines[0]\n\n        from deepspeed.runtime.base_optimizer import DeepSpeedOptimizer\n\n        optimzer_state_requested = any(isinstance(item, (Optimizer, DeepSpeedOptimizer)) for item in state.values())\n\n        torch.cuda.empty_cache()\n        _, client_state = engine.load_checkpoint(","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/deepspeed.py#L498-L534","documentation":"Symmetric to saving: DeepSpeed loads checkpoints through the DeepSpeedEngine, so the state passed to load_checkpoint must contain at least one module set up via the strategy. If no engine is found in state, this ValueError is raised.","triggerScenarios":"fabric.load_checkpoint(path, state={'something': x}) where none of the values is a DeepSpeedEngine-backed module — e.g. model not passed through fabric.setup, or state holds only raw tensors/dicts.","commonSituations":"Resuming with a freshly constructed model that was never set up; calling load_checkpoint before setup; model set up under a different Fabric instance than the one loading.","solutions":["Call fabric.setup(model, optimizer) before fabric.load_checkpoint and include the model in state","Use the same Fabric/strategy instance for setup and loading","For raw weights, load with torch.load + model.load_state_dict instead of the strategy checkpoint API"],"exampleFix":"# before\nmodel = MyModel()\nfabric.load_checkpoint(path, state={'weights': sd})\n# after\nmodel, optimizer = fabric.setup(MyModel(), make_optimizer())\nfabric.load_checkpoint(path, state={'model': model, 'optimizer': optimizer})","handlingStrategy":"validation","validationCode":"from deepspeed import DeepSpeedEngine\ndef has_engine(state) -> bool:\n    return any(isinstance(v, DeepSpeedEngine) for v in state.values())\nmodel, optimizer = fabric.setup(model, optimizer)\nassert has_engine({'model': model})","typeGuard":"from deepspeed import DeepSpeedEngine\n\ndef load_state_valid(state: dict) -> bool:\n    return any(isinstance(v, DeepSpeedEngine) for v in state.values())","tryCatchPattern":null,"preventionTips":["Call fabric.setup before fabric.load_checkpoint","Use the same Fabric instance for setup and resume"],"tags":["deepspeed","checkpointing","resume","state-validation","pytorch-lightning"],"backgroundTag":"invalid-state-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}