{"record":{"id":"aae2711626dd4e86","repo":"Lightning-AI/pytorch-lightning","slug":"the-checkpoint-path-exists-and-is-a-directory-pa-aae271","errorCode":null,"errorMessage":"The checkpoint path exists and is a directory: {path}","messagePattern":"The checkpoint path exists and is a directory: (.+?)","errorType":"exception","errorClass":"IsADirectoryError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/strategies/model_parallel.py","lineNumber":313,"sourceCode":"\n    @override\n    def load_optimizer_state_dict(self, checkpoint: Mapping[str, Any]) -> None:\n        # Override to do nothing, the strategy already loaded the states in `load_checkpoint()`\n        pass\n\n    @override\n    def save_checkpoint(\n        self, checkpoint: dict[str, Any], filepath: _PATH, storage_options: Optional[Any] = None\n    ) -> None:\n        if storage_options is not None:\n            raise TypeError(\n                f\"`{type(self).__name__}.save_checkpoint(..., storage_options=...)` is not supported because\"\n                f\" `{type(self).__name__}` does not use the `CheckpointIO`.\"\n            )\n        # broadcast the path from rank 0 to ensure all the checkpoints are saved to a common path\n        path = _resolve_path(self.broadcast(filepath))\n        if _is_checkpoint_dir(path) and not self._save_distributed_checkpoint and not _is_sharded_checkpoint(path):\n            raise IsADirectoryError(f\"The checkpoint path exists and is a directory: {path}\")\n\n        if self._save_distributed_checkpoint:\n            _prepare_directory_checkpoint(path)\n\n            converted_state = {\"state_dict\": checkpoint.pop(\"state_dict\")}\n            converted_state.update({\n                f\"optimizer_{idx}\": optim_state\n                for idx, optim_state in enumerate(checkpoint.pop(\"optimizer_states\", []))\n            })\n            _distributed_checkpoint_save(converted_state, path)\n\n            if self.global_rank == 0:\n                _atomic_save(checkpoint, _checkpoint_join(path, _METADATA_FILENAME))\n        else:\n            if _is_sharded_checkpoint(path):\n                _remove_checkpoint(path)\n            return super().save_checkpoint(checkpoint=checkpoint, filepath=path)\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/model_parallel.py#L295-L331","documentation":"When saving a checkpoint with ModelParallelStrategy without distributed checkpointing (_save_distributed_checkpoint=False), the target path must be a file. If the resolved path already exists as a directory (and is not recognized as a sharded checkpoint being resumed), Lightning raises IsADirectoryError.","triggerScenarios":"Calling save_checkpoint with a path that is an existing directory (e.g. passing a run dir like 'checkpoints/run1/' rather than 'checkpoints/run1/last.ckpt'), while not using distributed checkpoints and the dir not being a sharded checkpoint.","commonSituations":"Passing ModelCheckpoint.dirpath instead of a filename; reusing a resume path that points at a DCP directory while the strategy is in full-checkpoint mode.","solutions":["Pass a full file path, e.g. os.path.join(dirpath, 'last.ckpt')","If the target really should be a sharded/distributed checkpoint directory, enable the strategy's distributed checkpoint option (_save_distributed_checkpoint=True)","Remove or rename the conflicting directory if it was created by mistake"],"exampleFix":"# before\nstrategy.save_checkpoint(ckpt, \"checkpoints/run1/\")\n\n# after\nstrategy.save_checkpoint(ckpt, \"checkpoints/run1/last.ckpt\")","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(filepath)\nassert not (p.exists() and p.is_dir()), f\"{filepath} is a directory; pass a file path like {p}/last.ckpt\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build checkpoint paths as dirpath + filename","Enable distributed checkpointing if directory checkpoints are intended"],"tags":["checkpoint","is-a-directory","model-parallel","path"],"backgroundTag":"path-is-directory","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}