Lightning-AI/pytorch-lightning · error · ValueError
`.{fn}()` found no path for the best weights: {ckpt_path!r}.
Error message
`.{fn}()` found no path for the best weights: {ckpt_path!r}. Please specify a path for a checkpoint `.{fn}(ckpt_path=PATH)` What it means
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.
Source
Thrown at src/lightning/pytorch/trainer/connectors/checkpoint_connector.py:213
ckpt_path = max(candidates_ts, key=candidates_ts.get) # type: ignore[arg-type]
elif ckpt_path == "hpc":
if not self._hpc_resume_path:
raise ValueError(
f'`.{fn}(ckpt_path="hpc")` is set but no HPC checkpoint was found.'
f" Please pass an exact checkpoint path to `.{fn}(ckpt_path=...)`"
)
ckpt_path = self._hpc_resume_path
elif _is_registry(ckpt_path) and module_available("litmodels"):
ckpt_path = find_model_local_ckpt_path(
ckpt_path,
default_model_registry=self.trainer._model_registry,
default_root_dir=self.trainer.default_root_dir,
)
if not ckpt_path:
raise ValueError(
f"`.{fn}()` found no path for the best weights: {ckpt_path!r}. Please"
f" specify a path for a checkpoint `.{fn}(ckpt_path=PATH)`"
)
return ckpt_path
def resume_end(self) -> None:
"""Signal the connector that all states have resumed and memory for the checkpoint object can be released."""
assert self.trainer.state.fn is not None
if self._ckpt_path:
message = "Restored all states" if self.trainer.state.fn == TrainerFn.FITTING else "Loaded model weights"
rank_zero_info(f"{message} from the checkpoint at {self._ckpt_path}")
# free memory
self._loaded_checkpoint = {}
torch.cuda.empty_cache()
# wait for all to catch up
self.trainer.strategy.barrier("_CheckpointConnector.resume_end")View on GitHub (pinned to 9fed5c27d2)
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
Example fix
# before trainer.test(model, ckpt_path="last") # no last.ckpt exists # after trainer = Trainer(callbacks=[ModelCheckpoint(monitor="val_loss", save_last=True)]) trainer.fit(model) trainer.test(model, ckpt_path="last")
Defensive patterns
Strategy: try-catch
Validate before calling
from pathlib import Path
if ckpt_path in ("best", "last"):
cand = mc.best_model_path if ckpt_path == "best" else mc.last_model_path
assert cand, f"no {ckpt_path} checkpoint saved yet"
assert Path(cand).exists(), f"{cand} missing on disk" Try / catch
try:
trainer.test(model, ckpt_path="last")
except ValueError as e:
if "found no path" in str(e):
trainer.test(model) # current weights
else:
raise Prevention
- 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'
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- `.{fn}(ckpt_path="best")` is set but `ModelCheckpoint` is no
- `.{fn}(ckpt_path="hpc")` is set but no HPC checkpoint was fo
- Trying to restore optimizer state but checkpoint contains on
- Trying to restore learning rate scheduler state but checkpoi
- Could not find a distributed model in the provided checkpoin
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/d15b18ccc04d44c4.
Report an issue: GitHub.