{"record":{"id":"5a9fe2782db70f29","repo":"Lightning-AI/pytorch-lightning","slug":"unable-to-find-latest-file-at-latest-path","errorCode":null,"errorMessage":"Unable to find 'latest' file at {latest_path}","messagePattern":"Unable to find 'latest' file at (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/utilities/deepspeed.py","lineNumber":36,"sourceCode":"import os\nfrom typing import Any\n\nimport torch\n\nfrom lightning.fabric.utilities.types import _PATH\nfrom lightning.pytorch.strategies.deepspeed import _DEEPSPEED_AVAILABLE\n\nCPU_DEVICE = torch.device(\"cpu\")\n\n\ndef ds_checkpoint_dir(checkpoint_dir: _PATH, tag: str | None = None) -> str:\n    if tag is None:\n        latest_path = os.path.join(checkpoint_dir, \"latest\")\n        if os.path.isfile(latest_path):\n            with open(latest_path) as fd:\n                tag = fd.read().strip()\n        else:\n            raise ValueError(f\"Unable to find 'latest' file at {latest_path}\")\n\n    directory = os.path.join(checkpoint_dir, tag)\n\n    if not os.path.isdir(directory):\n        raise FileNotFoundError(f\"Directory '{ds_checkpoint_dir}' doesn't exist\")\n    return directory\n\n\n# Modified script from https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/utils/zero_to_fp32.py\ndef convert_zero_checkpoint_to_fp32_state_dict(\n    checkpoint_dir: _PATH, output_file: _PATH, tag: str | None = None\n) -> dict[str, Any]:\n    \"\"\"Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be loaded with\n    ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed. It gets copied into the top\n    level checkpoint dir, so the user can easily do the conversion at any point in the future. Once extracted, the\n    weights don't require DeepSpeed and can be used in any application. Additionally the script has been modified to\n    ensure we keep the lightning state inside the state dict for being able to run\n    ``LightningModule.load_from_checkpoint('...')```.","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/utilities/deepspeed.py#L18-L54","documentation":"Raised as a ValueError by Lightning's ds_checkpoint_dir helper when converting a DeepSpeed ZeRO checkpoint: no tag was given and the 'latest' file, which DeepSpeed writes into the checkpoint directory to record the most recent tag, was not found. Without a tag, the location of the sharded ZeRO files cannot be determined.","triggerScenarios":"Calling convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file) without tag= on a directory that lacks a 'latest' file; common with checkpoints saved by DeepSpeed versions/paths that only write numbered tag subdirectories, or when pointing at a copied/partial checkpoint directory.","commonSituations":"Checkpoint dir was copied without the 'latest' marker; ZeRO stage 2/3 checkpoints where the tag folder exists but the marker is missing; manually assembled checkpoint folders.","solutions":["Pass the tag explicitly: convert_zero_checkpoint_to_fp32_state_dict(ckpt_dir, out_file, tag='<existing-tag-folder>')","List os.listdir(ckpt_dir) and use the tag subdirectory name that exists","Re-save the checkpoint from DeepSpeed/Lightning so the 'latest' file is written"],"exampleFix":"# before\nconvert_zero_checkpoint_to_fp32_state_dict('checkpoints/last', 'model.pt')\n\n# after\nconvert_zero_checkpoint_to_fp32_state_dict('checkpoints/last', 'model.pt', tag='2000')","handlingStrategy":"validation","validationCode":"import os\nckpt_dir = 'path/to/ckpt'\nif not os.path.isfile(os.path.join(ckpt_dir, 'latest')):\n    tags = sorted(d for d in os.listdir(ckpt_dir) if d.isdigit())\n    assert tags, f'no tag dirs in {ckpt_dir}'\n    tag = tags[-1]\nelse:\n    tag = None\nconvert_zero_checkpoint_to_fp32_state_dict(ckpt_dir, 'model.pt', tag=tag)","typeGuard":null,"tryCatchPattern":"try:\n    convert_zero_checkpoint_to_fp32_state_dict(ckpt_dir, out)\nexcept ValueError as e:\n    if \"Unable to find 'latest'\" in str(e):\n        tag = sorted(d for d in os.listdir(ckpt_dir) if d.isdigit())[-1]\n        convert_zero_checkpoint_to_fp32_state_dict(ckpt_dir, out, tag=tag)\n    else:\n        raise","preventionTips":["Copy the entire DeepSpeed checkpoint directory including the 'latest' file","Pass tag= explicitly when the marker may be absent","Verify checkpoint contents with os.listdir before conversion"],"tags":["pytorch-lightning","deepspeed","checkpoint","conversion"],"backgroundTag":"deepspeed-checkpoint-tag-missing","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}