{"record":{"id":"d15b18ccc04d44c4","repo":"Lightning-AI/pytorch-lightning","slug":"fn-found-no-path-for-the-best-weights-ckp","errorCode":null,"errorMessage":"`.{fn}()` found no path for the best weights: {ckpt_path!r}. Please specify a path for a checkpoint `.{fn}(ckpt_path=PATH)`","messagePattern":"`\\.(.+?)\\(\\)` found no path for the best weights: (.+?)\\. Please specify a path for a checkpoint `\\.(.+?)\\(ckpt_path=PATH\\)`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/checkpoint_connector.py","lineNumber":213,"sourceCode":"            ckpt_path = max(candidates_ts, key=candidates_ts.get)  # type: ignore[arg-type]\n\n        elif ckpt_path == \"hpc\":\n            if not self._hpc_resume_path:\n                raise ValueError(\n                    f'`.{fn}(ckpt_path=\"hpc\")` is set but no HPC checkpoint was found.'\n                    f\" Please pass an exact checkpoint path to `.{fn}(ckpt_path=...)`\"\n                )\n            ckpt_path = self._hpc_resume_path\n\n        elif _is_registry(ckpt_path) and module_available(\"litmodels\"):\n            ckpt_path = find_model_local_ckpt_path(\n                ckpt_path,\n                default_model_registry=self.trainer._model_registry,\n                default_root_dir=self.trainer.default_root_dir,\n            )\n\n        if not ckpt_path:\n            raise ValueError(\n                f\"`.{fn}()` found no path for the best weights: {ckpt_path!r}. Please\"\n                f\" specify a path for a checkpoint `.{fn}(ckpt_path=PATH)`\"\n            )\n        return ckpt_path\n\n    def resume_end(self) -> None:\n        \"\"\"Signal the connector that all states have resumed and memory for the checkpoint object can be released.\"\"\"\n        assert self.trainer.state.fn is not None\n        if self._ckpt_path:\n            message = \"Restored all states\" if self.trainer.state.fn == TrainerFn.FITTING else \"Loaded model weights\"\n            rank_zero_info(f\"{message} from the checkpoint at {self._ckpt_path}\")\n\n        # free memory\n        self._loaded_checkpoint = {}\n        torch.cuda.empty_cache()\n\n        # wait for all to catch up\n        self.trainer.strategy.barrier(\"_CheckpointConnector.resume_end\")","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/checkpoint_connector.py#L195-L231","documentation":"Final guard in _parse_ckpt_path: after all resolution logic (best/last/hpc/registry), the resulting ckpt_path is still empty/falsy. This means the requested resolution mode produced no usable path and Lightning cannot proceed to load weights.","triggerScenarios":"ckpt_path=\"last\" when no last checkpoint was saved (checkpointing disabled or no run yet), a registry/model reference that resolved to nothing, or best-model resolution yielding \"\" from the checkpoint callback; then calling trainer.validate/test/predict.","commonSituations":"Calling .test(ckpt_path=\"last\") before or without a prior fit; fresh output directory; ModelCheckpoint with save_top_k=0; registry lookup returning an empty path.","solutions":["Pass an explicit filesystem or registry path to ckpt_path","Ensure a checkpoint actually exists: fit first, keep enable_checkpointing=True, and configure save_last=True or a monitor","Use ckpt_path=None to use current in-memory weights if that is acceptable"],"exampleFix":"# before\ntrainer.test(model, ckpt_path=\"last\")  # no last.ckpt exists\n# after\ntrainer = Trainer(callbacks=[ModelCheckpoint(monitor=\"val_loss\", save_last=True)])\ntrainer.fit(model)\ntrainer.test(model, ckpt_path=\"last\")","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nif ckpt_path in (\"best\", \"last\"):\n    cand = mc.best_model_path if ckpt_path == \"best\" else mc.last_model_path\n    assert cand, f\"no {ckpt_path} checkpoint saved yet\"\n    assert Path(cand).exists(), f\"{cand} missing on disk\"","typeGuard":null,"tryCatchPattern":"try:\n    trainer.test(model, ckpt_path=\"last\")\nexcept ValueError as e:\n    if \"found no path\" in str(e):\n        trainer.test(model)  # current weights\n    else:\n        raise","preventionTips":["Check that the checkpoint file exists before calling validate/test/predict","Save resolved paths (best/last) right after fit and reuse them","Configure save_last=True when you rely on 'last'"],"tags":["lightning","checkpoint","resume","path-resolution","test"],"backgroundTag":"checkpoint-not-found","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}