{"record":{"id":"ccdcfdcca7ee6832","repo":"Lightning-AI/pytorch-lightning","slug":"fn-ckpt-path-best-is-set-but-modelcheckpo","errorCode":null,"errorMessage":"`.{fn}(ckpt_path=\"best\")` is set but `ModelCheckpoint` is not configured.","messagePattern":"`\\.(.+?)\\(ckpt_path=\"best\"\\)` is set but `ModelCheckpoint` is not configured\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/checkpoint_connector.py","lineNumber":166,"sourceCode":"            )\n            rank_zero_warn(\n                f\"`.{fn}(ckpt_path=None)` was called without a model.\"\n                \" The best model of the previous `fit` call will be used.\"\n                + ft_tip\n                + f\" You can pass `.{fn}(ckpt_path='best')` to use the best model or\"\n                f\" `.{fn}(ckpt_path='last')` to use the last model.\"\n                \" If you pass a value, this warning will be silenced.\"\n            )\n\n        if ckpt_path == \"best\":\n            if len(self.trainer.checkpoint_callbacks) > 1:\n                rank_zero_warn(\n                    f'`.{fn}(ckpt_path=\"best\")` is called with Trainer configured with multiple `ModelCheckpoint`'\n                    \" callbacks. It will use the best checkpoint path from first checkpoint callback.\"\n                )\n\n            if not self.trainer.checkpoint_callback:\n                raise ValueError(f'`.{fn}(ckpt_path=\"best\")` is set but `ModelCheckpoint` is not configured.')\n\n            has_best_model_path = self.trainer.checkpoint_callback.best_model_path\n            if hasattr(self.trainer.checkpoint_callback, \"best_model_path\") and not has_best_model_path:\n                if self.trainer.fast_dev_run:\n                    raise ValueError(\n                        f'You cannot execute `.{fn}(ckpt_path=\"best\")` with `fast_dev_run=True`.'\n                        f\" Please pass an exact checkpoint path to `.{fn}(ckpt_path=...)`\"\n                    )\n                raise ValueError(\n                    f'`.{fn}(ckpt_path=\"best\")` is set but `ModelCheckpoint` is not configured to save the best model.'\n                )\n            # load best weights\n            ckpt_path = getattr(self.trainer.checkpoint_callback, \"best_model_path\", None)\n\n        elif ckpt_path == \"last\":\n            candidates = {getattr(ft, \"ckpt_path\", None) for ft in ft_checkpoints}\n            for callback in self.trainer.checkpoint_callbacks:\n                if isinstance(callback, ModelCheckpoint):","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/checkpoint_connector.py#L148-L184","documentation":"Raised by CheckpointConnector._parse_ckpt_path when ckpt_path=\"best\" is passed to .validate()/.test()/.predict() but no ModelCheckpoint callback is configured. \"best\" requires the checkpoint callback to have recorded a best_model_path, which only exists if checkpointing was enabled during fit.","triggerScenarios":"trainer.validate(ckpt_path=\"best\") or trainer.test(ckpt_path=\"best\") / .predict(ckpt_path=\"best\") on a Trainer built with enable_checkpointing=False and no ModelCheckpoint in callbacks.","commonSituations":"Running evaluation-only workflows where the user assumed the best checkpoint is tracked automatically; disabling checkpointing for the fit run and then asking for the best weights; separating fit and eval into different Trainer instances without passing a path.","solutions":["Pass the explicit checkpoint path: trainer.test(ckpt_path=\"/path/to/best.ckpt\")","Add a ModelCheckpoint callback and keep enable_checkpointing=True during fit, then use ckpt_path=\"best\"","Load weights into the model manually (model = MyModel.load_from_checkpoint(path)) and call trainer.test(model) with ckpt_path=None"],"exampleFix":"# before\ntrainer = Trainer(enable_checkpointing=False)\ntrainer.fit(model)\ntrainer.test(model, ckpt_path=\"best\")\n# after\ntrainer = Trainer(callbacks=[ModelCheckpoint(monitor=\"val_loss\", save_top_k=1)])\ntrainer.fit(model)\ntrainer.test(model, ckpt_path=\"best\")","handlingStrategy":"validation","validationCode":"mode = \"test\"\nif ckpt_path == \"best\":\n    assert trainer.checkpoint_callback is not None, \"configure ModelCheckpoint before using ckpt_path='best'\"","typeGuard":null,"tryCatchPattern":"try:\n    trainer.test(model, ckpt_path=\"best\")\nexcept ValueError as e:\n    if \"not configured\" in str(e):\n        trainer.test(model, ckpt_path=explicit_path)\n    else:\n        raise","preventionTips":["Always pass explicit checkpoint paths in eval-only pipelines","Keep checkpointing enabled during fit if you plan to use 'best'","Store resolved best_model_path from ModelCheckpoint and reuse it"],"tags":["lightning","checkpoint","best-model","validate","test","predict"],"backgroundTag":"checkpoint-not-found","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}