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

Call any trainer function from the LightningCLI #7508

Merged
merged 74 commits into from
Aug 28, 2021

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented May 12, 2021

What does this PR do?

Fixes #7226

Pitch

# LightningCLI(..., run=False)
python script.py ...  # does not run anything but parses arguments

# LightningCLI(..., run=True)  # default
python script.py fit ...  # current behaviour
python script.py tune ...
python script.py validate ...
python script.py test ...
python script.py predict ...

where {fit,tune,validate,test,predict} are all the available subcommands.

The implementation needs to allow implementing custom subcommands. This will be useful in Flash to implement the finetune subcommand.

A follow-up PR (out of scope for this one) could add subcommands which chain commands. Some potential examples would be tune-and-fit, fit-and-validate, or fit-and-test.

Breaking changes

This change will be breaking for all previous CLI users. They will now need to pass the fit subcommand to keep the old behaviour. Any users who were adding subcommand already will need to update their position too.

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 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 May 12, 2021
@carmocca carmocca added this to the v1.4 milestone May 12, 2021
@carmocca carmocca self-assigned this May 12, 2021
@pep8speaks
Copy link

pep8speaks commented May 12, 2021

Hello @carmocca! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-08-10 15:10:38 UTC

@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #7508 (620703b) into master (b5fb49a) will increase coverage by 0%.
The diff coverage is 99%.

@@          Coverage Diff           @@
##           master   #7508   +/-   ##
======================================
  Coverage      88%     88%           
======================================
  Files         176     176           
  Lines       14804   14857   +53     
======================================
+ Hits        13032   13084   +52     
- Misses       1772    1773    +1     

awaelchli
awaelchli previously approved these changes May 12, 2021
docs/source/common/lightning_cli.rst Outdated Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
@carmocca carmocca marked this pull request as draft May 12, 2021 18:56
@carmocca carmocca marked this pull request as ready for review August 24, 2021 19:16
@carmocca
Copy link
Contributor Author

carmocca commented Aug 24, 2021

This is ready to go again, just waiting on a jsonargparse release with omni-us/jsonargparse#88 fixed (minor fix)

Pinging reviewers: @tchaton @ethanwharris @mauvilsa @Borda @awaelchli (dismissed old reviews)

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.

Looks neat !

docs/source/common/lightning_cli.rst Outdated Show resolved Hide resolved
docs/source/common/lightning_cli.rst Show resolved Hide resolved
docs/source/common/lightning_cli.rst Show resolved Hide resolved
docs/source/common/lightning_cli.rst Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Show resolved Hide resolved
pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
docs/source/common/lightning_cli.rst Outdated Show resolved Hide resolved
docs/source/common/lightning_cli.rst Outdated Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Aug 25, 2021
@carmocca carmocca force-pushed the feat/lightning-cli-trainer-fn branch 3 times, most recently from 63940e4 to 6ab08a1 Compare August 27, 2021 14:56
@carmocca carmocca force-pushed the feat/lightning-cli-trainer-fn branch from 6ab08a1 to 338f267 Compare August 27, 2021 15:29
@carmocca carmocca force-pushed the feat/lightning-cli-trainer-fn branch from 899cc6a to 8d1c423 Compare August 27, 2021 16:04
@carmocca carmocca enabled auto-merge (squash) August 27, 2021 16:06
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, ...) design Includes a design discussion 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.

10 participants