Lightning-AI / Lightning-AI/pytorch-lightning

Improve error message when `LightningCLI(run=False)` but user passes a stage as argument

Open
#18,203 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3rd party feature lightningcli
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Description & Motivation

This is a proposal to adjust the current error message

```
error: Unrecognized arguments: fit
```

to something more meaningful when `run=False` and passing a stage is not needed. Below is a minimal example that demonstrates this:

```py
from lightning.pytorch import LightningModule
from lightning.pytorch.cli import LightningCLI

class BoringModel(LightningModule):
pass

def main():
cli = LightningCLI(BoringModel, run=False)
cli.trainer.fit(cli.model)

if __name__ == "__main__":
main()

```

Run it like so:

```bash
python bug_report/bug_report_model.py fit
```

Error:
```
...
bug_report_model.py: error: Unrecognized arguments: fit
```

### Pitch

Adjust the error for this case to a message like this, pointing out that `run=False` was configured.

> Error: You passed 'fit' as stage but the LightningCLI is configured with `run=False`. Selecting a stage in this case is not supported.

### Alternatives

Keep as is

### Additional context

Raised by a question of a user in slack channel

cc @borda @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 with the LightningCLI entry point and reproduce the command shown in bug_report/bug_report_model.py using run=False and the fit argument. Done means the error explains that stage selection is unsupported when run=False, rather than only reporting an unrecognized argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.