Lightning-AI / Lightning-AI/pytorch-lightning

Appears that LightningCLI --ckpt_path=last doesn't work?

Open
#18,524 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug lightningcli ver: 2.0.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

In a simple case when testing `--ckpt_path=last` CLI argument with LightningCLI() interface & --trainer.logger True it didn't seem to actually load the last model checkpoint (**because metrics were abysmal (for `validate`), i.e. comparable to fresh model, also the tensorboard logs indicated it was starting from epoch=0 (for `fit`), & the problem was fixed by a manual workaround I did to find the last checkpoint myself and load it**).

**NOTE: I didn't actually use the ModelCheckpoint Callback explicitly but according to the CLI this shouldn't matter because it says its enabled by default:**
"--trainer.enable_checkpointing {true,false}
If ``True``, enable checkpointing. It will configure a default ModelCheckpoint callback if there is no user-defined ModelCheckpoint in
:paramref:`~pytorch_lightning.trainer.trainer.Trainer.callbacks`. Default: ``True``. (type: bool, **default: True)**"

P.S. see my [SO question](https://stackoverflow.com/questions/77054387/how-is-ckpt-path-last-supposed-to-work-in-pytorch-lightning) & [forum question](https://lightning.ai/forums/t/why-is-ckpt-path-last-not-working/3687)

Also lmk if you need more details.

### What version are you seeing the problem on?

v1.9

### How to reproduce the bug

Use `LightningCLI()` + `--trainer.logger True --trainer.max_epochs -1`, for training.
Then do `LightningCLI()` + `--trainer.logger True --trainer.max_epochs -1 --ckpt_path=last`

### Error messages and logs

There is no error message, it simply doesn't load the last checkpoint and appears to instead create a fresh model. It seems to do this even when

### Environment

Current environment

```
#- Lightning Component: Trainer
#- PyTorch Lightning Version: 1.9.0
#- Lightning App Version (e.g., 0.5.2): ??
#- PyTorch Version (e.g., 2.0): 1.10.0
#- Python version (e.g., 3.9): 3.8
#- OS: Linux
#- CUDA/cuDNN version: nvidia-cudnn-cu11==8.5.0.96
#- GPU models and configuration: V100
#- How you installed Lightning(`conda`, `pip`, source): pip
#- Running environment of LightningApp (e.g. local, cloud): local
```

cc @carmocca @mauvilsa

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two LightningCLI command sequences with --trainer.logger True and --ckpt_path=last, then trace how LightningCLI and Trainer resolve the default checkpoint. Confirm the behavior for both fit and validate, and consider the issue done when the latest checkpoint is loaded reliably and regression coverage verifies it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
cli, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.