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

CLI: add arg - instantiate_only #8251

Closed
wants to merge 3 commits into from
Closed

CLI: add arg - instantiate_only #8251

wants to merge 3 commits into from

Conversation

Borda
Copy link
Member

@Borda Borda commented Jul 1, 2021

What does this PR do?

allow instantiate_only

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

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • 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

Did you have fun?

Make sure you had fun coding 🙃

@Borda Borda added feature Is an improvement or enhancement argparse (removed) Related to argument parsing (argparse, Hydra, ...) labels Jul 1, 2021
@codecov
Copy link

codecov bot commented Jul 1, 2021

Codecov Report

Merging #8251 (14b5a6c) into master (365a9ba) will increase coverage by 4%.
The diff coverage is 50%.

@@           Coverage Diff           @@
##           master   #8251    +/-   ##
=======================================
+ Coverage      88%     92%    +4%     
=======================================
  Files         212     213     +1     
  Lines       13701   13800    +99     
=======================================
+ Hits        12125   12732   +607     
+ Misses       1576    1068   -508     

@Borda Borda requested a review from a team July 1, 2021 23:45
@carmocca
Copy link
Contributor

carmocca commented Jul 2, 2021

Can you elaborate why one would want this?

@Borda
Copy link
Member Author

Borda commented Jul 2, 2021

Can you elaborate why one would want this?

at him moment you have to always run the fit, right? but if you want just to get the instances of Trainer, Model, and Data and then your own staff you need to overwrite CLI.fit(...) to be empty...
moreover (well it is docs) but from API is it not intuitive that with creating a CLI instance it automatically perform training

@Borda Borda added the ready PRs ready to be merged label Jul 2, 2021
@carmocca carmocca removed the ready PRs ready to be merged label Jul 2, 2021
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

at him moment you have to always run the fit, right? but if you want just to get the instances of Trainer, Model, and Data and then your own staff you need to overwrite CLI.fit(...) to be empty...
moreover (well it is docs) but from API is it not intuitive that with creating a CLI instance it automatically perform training

This is the whole point of the CLI. With #7508 we could make it so not passing the function to run has the same effect as what this PR wants.

But this flag doesn't fit right with me when the only purpose of the CLI is to fit right now.

cc @mauvilsa for thoughts

@Borda
Copy link
Member Author

Borda commented Jul 2, 2021

But this flag doesn't fit right with me when the only purpose of the CLI is to fit right now.

for me, the main purpose of CLI is to instantiate all main actors - Trainer, Model and Data
then the fix is something extra and so I would rather have it as optional than mandatory

So what I have to do for use Tuner:

class TuneFitCLI(LightningCLI):

    def before_fit(self) -> None:
        """Implement to run some code before fit is started"""
        res = self.trainer.tune(**self.fit_kwargs, scale_batch_size_kwargs=dict(max_trials=5))
        self.instantiate_classes()
        torch.cuda.empty_cache()
        self.datamodule.batch_size = int(res['scale_batch_size'] * 0.9)


if __name__ == '__main__':
    cli = TuneFitCLI(
        model_class=MultiPlantPathology,
        datamodule_class=PlantPathologyDM,
        trainer_defaults=TRAINER_DEFAULTS,
        seed_everything_default=42,
    )

@mauvilsa
Copy link
Contributor

mauvilsa commented Jul 6, 2021

I think we should not add a skip_fit parameter. The purpose of LightningCLI is to run a command. As @carmocca said, right now it is fit, but with #7508 there will be multiple commands. Having this parameter would not make much sense once #7508 is done.

@Borda
Copy link
Member Author

Borda commented Jul 6, 2021

I think we should not add a skip_fit parameter. The purpose of LightningCLI is to run a command. As @carmocca said, right now it is fit, but with #7508 there will be multiple commands. Having this parameter would not make much sense once #7508 is done.

So you say that if don't want to run any Trainer method by default I cannot use CLI or need to overwrite the CLI.fit()?
@PyTorchLightning/core-contributors

@mauvilsa
Copy link
Contributor

mauvilsa commented Jul 6, 2021

I think we should not add a skip_fit parameter. The purpose of LightningCLI is to run a command. As @carmocca said, right now it is fit, but with #7508 there will be multiple commands. Having this parameter would not make much sense once #7508 is done.

So you say that if don't want to run any Trainer method by default I cannot use CLI or need to overwrite the CLI.fit()?
@PyTorchLightning/core-contributors

I am saying that skip_fit parameter conflicts with #7508. If there is a need that LightningCLI not run on instantiation, then there would be a run disable, not specific to fit. Anyway you always want to run something. The idea is that this something is implemented as part of a subclass of LightningCLI. Maybe can you explain better why use LightningCLI without running anything?

@Borda
Copy link
Member Author

Borda commented Jul 6, 2021

Maybe can you explain better why use LightningCLI without running anything?

for example for the tune, or does extra action before fit or just print model details, you can see any past CLI in Bolts

@mauvilsa so are we just about the name? so let's call it intantiate_only?

@tchaton
Copy link
Contributor

tchaton commented Jul 6, 2021

Hey @mauvilsa @carmocca @Borda,

I understand Jirka use-case. I believe more users might want to rely on the LightningCLI only as an instantiation tool.
I believe having an instantiate_only=False argument might be useful in the long run.

Best,
T.C

@Borda Borda requested a review from carmocca July 6, 2021 10:58
@Borda Borda changed the title CLI: skip fit CLI: add arg - instantiate_only Jul 6, 2021
@carmocca
Copy link
Contributor

carmocca commented Jul 6, 2021

The discussion is scattered on both PR. Writing here what I think is the best way forward is:

@Borda
Copy link
Member Author

Borda commented Jul 6, 2021

@carmocca if your PR has the option to not run any trainer method, then it is fine and we do not need this :]

@tchaton
Copy link
Contributor

tchaton commented Jul 8, 2021

@Borda @carmocca Good to close this PR then ?

@Borda Borda added the won't fix This will not be worked on label Jul 14, 2021
@Borda
Copy link
Member Author

Borda commented Jul 14, 2021

closing this one in favor of #7508

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 won't fix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants