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

remove extra kwargs from Trainer init #1820

Merged
merged 7 commits into from
May 17, 2020
Merged

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented May 13, 2020

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 to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

What does this PR do?

  • If you misspell a Trainer arg, it will go to kwargs and there will be no error. This should not be.
    You can actually observe this in tests!

@awaelchli awaelchli added the bug Something isn't working label May 13, 2020
@mergify mergify bot requested a review from a team May 13, 2020 21:14
@awaelchli
Copy link
Contributor Author

awaelchli commented May 13, 2020

as you can see in the first commit here, the tests fail because the flags train_check_interval and test_check_interval do not actually exist!

@Borda
Copy link
Member

Borda commented May 13, 2020

we already had this discussion and it breaks inheritance...

@awaelchli
Copy link
Contributor Author

where was the discussion? I would like to know how it breaks inheritance.

@awaelchli awaelchli marked this pull request as draft May 13, 2020 21:29
@Borda
Copy link
Member

Borda commented May 13, 2020

where was the discussion? I would like to know how it breaks inheritance.

at least in IDE if the child has different arguments, @justusschock we talked about it, right?
see: #1180

@awaelchli
Copy link
Contributor Author

well, that's very unfortunate, because this PR shows then the tests are flawed if we allow unknown flags to be passed in without throwing an error

@awaelchli
Copy link
Contributor Author

awaelchli commented May 13, 2020

So I looked at the discussion you link #1180 and I really don't get it.

  1. We don't have any subclasses of Trainer
  2. Trainer doesn't even call super().init()
  3. Some of the Mixins that Trainer inherits from have a init (e.g. TrainerCallbackHookMixin) but they are never called because Trainer does not call super

So I would rather conclude that inheritance already IS broken

@oplatek maybe you can explain it to me in super simple words? :)

@Borda
Copy link
Member

Borda commented May 14, 2020

@awaelchli I agree with you that the benefit of more strict testing is larger than having Trainer simple to inherit... @PyTorchLightning/core-contributors do you see use-case when user need to inherit Trainer and add/remove some arguments?

@oplatek
Copy link
Contributor

oplatek commented May 14, 2020

I thought the main arguments were:

  1. Users will subclass Trainer class for example create class SubTrainer(Trainer)
  2. Users will call super.init() in their SubTrainer class
  3. For the SubTrainer is super convenient to just pass **kwargs in SubTrainer.init to the Trainer.init method

Ad 3 I see it as is super convenient but for very rare use case and I see it as error prone when creating Trainer instance e.g. Trainer(max_epochs) vs Trainer(max_pochs) which fails silently and it is quite frequent case

@pep8speaks
Copy link

pep8speaks commented May 14, 2020

Hello @awaelchli! Thanks for updating this PR.

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

Comment last updated at 2020-05-15 00:07:00 UTC

@awaelchli
Copy link
Contributor Author

awaelchli commented May 14, 2020

@oplatek I agree with you, except that we don't have to make any compromises.
See the test that I added, it shows that subclassing and parsing the arguments is not problem.
At least I could not find one, but the test in my view proofs the basic use cases of inheritance as I know it.

@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #1820 into master will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #1820   +/-   ##
======================================
  Coverage      88%     88%           
======================================
  Files          71      71           
  Lines        4487    4487           
======================================
+ Hits         3947    3954    +7     
+ Misses        540     533    -7     

@justusschock
Copy link
Member

@Borda I don't remember having such a discussion with you, but that may also be on me :D

In general I would also opt for removing kwargs wherever possible

@Borda Borda added feature Is an improvement or enhancement let's do it! approved to implement labels May 15, 2020
@Borda Borda added this to the 0.7.7 milestone May 15, 2020
@awaelchli awaelchli marked this pull request as ready for review May 15, 2020 16:30
@williamFalcon williamFalcon merged commit 769a459 into master May 17, 2020
@williamFalcon
Copy link
Contributor

nice @awaelchli

@awaelchli awaelchli deleted the bugfix/trainer-kwargs branch May 17, 2020 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature Is an improvement or enhancement let's do it! approved to implement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants