{"record":{"id":"efee26e14c50dc3a","repo":"Lightning-AI/pytorch-lightning","slug":"got-deepspeedstrategy-load-checkpoint-state","errorCode":null,"errorMessage":"Got DeepSpeedStrategy.load_checkpoint(..., state={state!r}) but a state with at least  a model instance to reload is required. Pass it in like so: DeepSpeedStrategy.load_checkpoint(..., state={'model': model, ...})","messagePattern":"Got DeepSpeedStrategy\\.load_checkpoint\\(\\.\\.\\., state=(.+?)\\) but a state with at least  a model instance to reload is required\\. Pass it in like so: DeepSpeedStrategy\\.load_checkpoint\\(\\.\\.\\., state=(.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/strategies/deepspeed.py","lineNumber":507,"sourceCode":"            Dictionary with the state inside DeepSpeed's engine\n\n        Raises:\n            ValueError:\n                If no state is provided, when no :class:`deepspeed.DeepSpeedEngine` objects were found in the\n                state, or when multiple :class:`deepspeed.DeepSpeedEngine` objects were found.\n            RuntimeError:\n                If DeepSpeed was unable to load the checkpoint due to missing files or because the checkpoint is\n                not in the expected DeepSpeed format.\n\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.\"","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/deepspeed.py#L489-L525","documentation":"Loading a DeepSpeed checkpoint requires state to restore into — at minimum a set-up model. DeepSpeedStrategy.load_checkpoint rejects an empty/None state ({} or None) because there is nothing to restore the checkpoint into; unlike some strategies it cannot load into a blank slate.","triggerScenarios":"fabric.load_checkpoint(path, state={}) or fabric.load_checkpoint(path) under DeepSpeedStrategy (omitted/empty state).","commonSituations":"Generic resume helpers that call load_checkpoint(path, state) before populating state; assuming the strategy returns a loaded state rather than filling one in-place.","solutions":["Set up the model (and optimizer) first, then load: fabric.load_checkpoint(path, state={'model': model, 'optimizer': optimizer})","Remember load_checkpoint restores into your objects in place and returns the state back","Populate state from your training objects before calling load"],"exampleFix":"# before\nstate = fabric.load_checkpoint(path, state={})\n# after\nmodel, optimizer = fabric.setup(model, optimizer)\nstate = {'model': model, 'optimizer': optimizer}\nfabric.load_checkpoint(path, state)","handlingStrategy":"validation","validationCode":"if not state or not any(v is not None for v in state.values()):\n    raise ValueError(\"populate state with the set-up model before loading\")\nfabric.load_checkpoint(path, state)","typeGuard":"def load_state_valid(state) -> bool:\n    return bool(state) and any(v is not None for v in state.values())","tryCatchPattern":null,"preventionTips":["Always build state = {'model': model, 'optimizer': optimizer} before resume","Remember load_checkpoint mutates state in place"],"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"}