Skip to content

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

Open
@awaelchli

Description

@awaelchli

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd partyRelated to a 3rd-partyfeatureIs an improvement or enhancementlightningclipl.cli.LightningCLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions