Lightning-AI / Lightning-AI/pytorch-lightning
Improve error message when `LightningCLI(run=False)` but user passes a stage as argument
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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