{"record":{"id":"9c22c46340d68730","repo":"Lightning-AI/pytorch-lightning","slug":"the-checkpoint-path-exists-and-is-a-directory-pa-9c22c4","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/fsdp.py","lineNumber":577,"sourceCode":"\n    @override\n    def load_optimizer_state_dict(self, checkpoint: Mapping[str, Any]) -> None:\n        # Override to do nothing, the FSDP 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                \"`FSDPStrategy.save_checkpoint(..., storage_options=...)` is not supported because\"\n                \" `FSDPStrategy` does not use the `CheckpointIO`.\"\n            )\n\n        path = _resolve_path(self.broadcast(filepath))\n        if self._state_dict_type == \"full\" and _is_checkpoint_dir(path) and not _is_sharded_checkpoint(path):\n            raise IsADirectoryError(f\"The checkpoint path exists and is a directory: {path}\")\n\n        if self._state_dict_type == \"sharded\":\n            _prepare_directory_checkpoint(path)\n\n            converted_state = {\"model\": 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\n            _distributed_checkpoint_save(converted_state, path)\n\n            if self.global_rank == 0:\n                _atomic_save(checkpoint, _checkpoint_join(path, _METADATA_FILENAME))\n        elif self._state_dict_type == \"full\":\n            if _is_sharded_checkpoint(path):\n                _remove_checkpoint(path)\n            return super().save_checkpoint(checkpoint=checkpoint, filepath=path)","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/fsdp.py#L559-L595","documentation":"With state_dict_type=\"full\", FSDP saves a single consolidated file and expects `filepath` to be a file path. If the broadcast path resolves to an existing directory that is not a sharded checkpoint (no sharded metadata), save_checkpoint raises IsADirectoryError to avoid writing a file over a checkpoint directory.","triggerScenarios":"`FSDPStrategy(state_dict_type=\"full\")` + `trainer.save_checkpoint(path)` where path exists on disk as a directory (e.g. a previous sharded checkpoint dir or a logs dir).","commonSituations":"Reusing the same checkpoint path for a full save after earlier sharded saves; pointing save path at a run directory like `logs/run1/`; callbacks deriving paths from existing dirs.","solutions":["Point save_checkpoint at a file path such as `.../last.ckpt` that does not exist as a directory","Delete or move the existing directory before saving","Keep sharded and full checkpoint outputs in separate paths"],"exampleFix":"# before\ntrainer.save_checkpoint(\"checkpoints/run1\")  # existing dir\n\n# after\ntrainer.save_checkpoint(\"checkpoints/run1/last.ckpt\")","handlingStrategy":"validation","validationCode":"from pathlib import Path\npath = Path(\"checkpoints/run1/last.ckpt\")\nif path.is_dir():\n    raise IsADirectoryError(f\"pick a file path, got dir: {path}\")\ntrainer.save_checkpoint(str(path))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always save full checkpoints to a file-like path ending in .ckpt","Keep sharded checkpoint dirs and full checkpoint files under separate roots","Clean stale checkpoint paths before switching state_dict_type"],"tags":["fsdp","save-checkpoint","is-a-directory","paths"],"backgroundTag":"checkpoint-path-is-directory","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}