Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LightningCLI(run=False|True) #8751

Merged
merged 8 commits into from
Aug 10, 2021
Merged

Add LightningCLI(run=False|True) #8751

merged 8 commits into from
Aug 10, 2021

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Aug 5, 2021

What does this PR do?

Fixes #8615, #8251
Part of #7508

After discussing with @mauvilsa, we came to the conclusion that the solution of having a __init__(run: bool) flag to disable fit is better than doing it by not passing a subcommand:

# what this PR implements
# LightningCLI(..., run=False)
$ python script.py ...

# vs

# what was the previous idea
# LightningCLI(...)
$ python script.py ...

This is because there is no case where the user would go from doing python script.py fit <some_args> to python script.py <some_args> without code changes because to do so, the user would need to write cli.trainer.fit(cli.model) anyways after the CLI instantiation.

With that in consideration, we require the user to explicitly set run=False.
This way, you have to really mess up to run fit twice accidentally.

Does your PR introduce any breaking changes? If yes, please list them.

None

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

@carmocca carmocca added feature Is an improvement or enhancement argparse (removed) Related to argument parsing (argparse, Hydra, ...) labels Aug 5, 2021
@carmocca carmocca added this to the v1.5 milestone Aug 5, 2021
@carmocca carmocca self-assigned this Aug 5, 2021
@codecov
Copy link

codecov bot commented Aug 5, 2021

Codecov Report

Merging #8751 (ad6458d) into master (f1cc6e3) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #8751    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         169     169            
  Lines       14068   14069     +1     
=======================================
- Hits        13038   12461   -577     
- Misses       1030    1608   +578     

tests/utilities/test_cli.py Outdated Show resolved Hide resolved
docs/source/common/lightning_cli.rst Outdated Show resolved Hide resolved
docs/source/common/lightning_cli.rst Show resolved Hide resolved
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks the same as mine #8251 which you blocked :P

@mergify mergify bot added the ready PRs ready to be merged label Aug 6, 2021
Copy link
Contributor

@mauvilsa mauvilsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there will be multiple ways of using LightningCLI there is one thing that could be done to prevent mistakes. When run==True after running, the Trainer instance could be modified overriding the fit, test, etc. methods such that it shows an error instead of running.

@carmocca
Copy link
Contributor Author

carmocca commented Aug 6, 2021

after running, the Trainer instance could be modified overriding the fit, test, etc. methods such that it shows an error instead of running.

This would limit those who want to fit with run=True and still call test manually later (or fit again!)

@carmocca carmocca enabled auto-merge (squash) August 6, 2021 10:05
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @carmocca.

Can you share why run is set to True by default ?
This seems counter-intuitive as you could argue that test should also be run too.
Furthermore, it doesn't fully resolve #8615 as it will run fit by default.
IMO, I would prefer user to opt-in on a running fit to avoid confusion.

@mergify mergify bot removed the ready PRs ready to be merged label Aug 9, 2021
@carmocca
Copy link
Contributor Author

carmocca commented Aug 9, 2021

Can you share why run is set to True by default ?

Because the entire design is focused on getting up-and-running as easily as possible.

Setting it to False would require a full restructure of the docs.

Furthermore, it doesn't fully resolve #8615 as it will run fit by default.

We can remove that issue from the "fixes" list. This PR adds support for having the choice

This seems counter-intuitive

The CLI docs only mention that it is designed to run fit by default so that is documented.

you could argue that test should also be run too.

This is entirely fair, running fit only was just the initial design. #7508 will add support for test

I would prefer user to opt-in on a running fit to avoid confusion.

Again, #7508 will make it opt-in as providing a subcommand will be a requirement with run=True (default)

@carmocca carmocca requested a review from tchaton August 9, 2021 14:25
@mergify mergify bot added the has conflicts label Aug 9, 2021
@mergify mergify bot removed the has conflicts label Aug 9, 2021
@carmocca carmocca merged commit cb2a8ed into master Aug 10, 2021
@carmocca carmocca deleted the feat/cli-run branch August 10, 2021 13:01
@mergify mergify bot added the ready PRs ready to be merged label Aug 10, 2021
four4fish pushed a commit to four4fish/pytorch-lightning that referenced this pull request Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
argparse (removed) Related to argument parsing (argparse, Hydra, ...) feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LightningCLI shouldn't run fit by default
7 participants