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

Recursive inspection of subclasses init in from_argparse_args #3316

Closed
wants to merge 3 commits into from
Closed

Recursive inspection of subclasses init in from_argparse_args #3316

wants to merge 3 commits into from

Conversation

nathanpainchaud
Copy link
Contributor

@nathanpainchaud nathanpainchaud commented Sep 2, 2020

What does this PR do?

Fixes #3315

This PR improves add_argparse_args and from_argparse_args methods in LightningDataModule and Trainer so that they can support more than one level of subclassing from their base Lightning class.

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@Borda Borda added the feature Is an improvement or enhancement label Sep 2, 2020
valid_kwargs = inspect.signature(cls.__init__).parameters
valid_kwargs = {}
trainer_cls = cls
while trainer_cls != Trainer:
Copy link
Member

Choose a reason for hiding this comment

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

what would be the case you want Trainer subclass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't personally encountered a need to subclass Trainer, but I thought some other might have (I don't know about any reason why we shouldn't, if there are).

My main motivation to apply it to both LightningDataModule and Trainer was to keep the behavior the same. The methods with the same name behave the same way, and I thought it should be kept that way. I saw talks in this issue that some might want to refactor the argparse methods to avoid duplicating them. So I figured having similar but not identical functions would be more trouble in the end.

@nathanpainchaud
Copy link
Contributor Author

A question about the exact behavior this should implement: do we want to inspect the signature of the base Lightning class (e.g. LigthningDataModule or Trainer) as well as that of the subclasses? Because right now, I stop at the user class that directly subclasses the base Ligthing class, but I realized this might not be the best decision. Any thoughts?

@codecov
Copy link

codecov bot commented Sep 3, 2020

Codecov Report

Merging #3316 into master will decrease coverage by 7%.
The diff coverage is 84%.

@@           Coverage Diff           @@
##           master   #3316    +/-   ##
=======================================
- Coverage      90%     83%    -7%     
=======================================
  Files          90      90            
  Lines        8157    8552   +395     
=======================================
- Hits         7362    7078   -284     
- Misses        795    1474   +679     

@codecov
Copy link

codecov bot commented Sep 3, 2020

Codecov Report

Merging #3316 into master will increase coverage by 0%.
The diff coverage is 84%.

@@          Coverage Diff           @@
##           master   #3316   +/-   ##
======================================
  Coverage      90%     90%           
======================================
  Files          90      90           
  Lines        8138    8160   +22     
======================================
+ Hits         7349    7369   +20     
- Misses        789     791    +2     

@nathanpainchaud nathanpainchaud marked this pull request as ready for review September 3, 2020 19:27
@mergify mergify bot requested a review from a team September 3, 2020 19:28
@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2020

This pull request is now in conflict... :(

@nathanpainchaud
Copy link
Contributor Author

I noticed that some changes might conflict in the future with PR #3428 which also deals with argparse for Trainer (and I expect LightningDataModule as well eventually). So how do you want to proceed between the 2 PRs @Borda ?

@williamFalcon
Copy link
Contributor

yeah, that PR is an intermediate step.
I think the goal is to use the same logic for the trainer, datamodule and lightning module since we currently have multiple implementations

@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2020

This pull request is now in conflict... :(

@edenlightning edenlightning added this to the 1.1 milestone Oct 4, 2020
@stale
Copy link

stale bot commented Oct 21, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions.

@stale stale bot added the won't fix This will not be worked on label Oct 21, 2020
@stale
Copy link

stale bot commented Oct 26, 2020

This pull request is going to be closed. Please feel free to reopen it create a new from the actual master.

@stale stale bot closed this Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Support multiple levels of subclassing in from_argparse_args
4 participants