-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Recursive inspection of subclasses init in from_argparse_args
#3316
Conversation
pytorch_lightning/trainer/trainer.py
Outdated
valid_kwargs = inspect.signature(cls.__init__).parameters | ||
valid_kwargs = {} | ||
trainer_cls = cls | ||
while trainer_cls != Trainer: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
A question about the exact behavior this should implement: do we want to inspect the signature of the base Lightning class (e.g. |
Codecov Report
@@ Coverage Diff @@
## master #3316 +/- ##
=======================================
- Coverage 90% 83% -7%
=======================================
Files 90 90
Lines 8157 8552 +395
=======================================
- Hits 7362 7078 -284
- Misses 795 1474 +679 |
Codecov Report
@@ Coverage Diff @@
## master #3316 +/- ##
======================================
Coverage 90% 90%
======================================
Files 90 90
Lines 8138 8160 +22
======================================
+ Hits 7349 7369 +20
- Misses 789 791 +2 |
This pull request is now in conflict... :( |
- With test for DataModule recursive argparse inspection
yeah, that PR is an intermediate step. |
This pull request is now in conflict... :( |
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. |
This pull request is going to be closed. Please feel free to reopen it create a new from the actual master. |
What does this PR do?
Fixes #3315
This PR improves
add_argparse_args
andfrom_argparse_args
methods inLightningDataModule
andTrainer
so that they can support more than one level of subclassing from their base Lightning class.Before submitting
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 🙃