-
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
Add Trainer max_time argument + Callback #6823
Conversation
Hello @awaelchli! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-04-16 11:00:49 UTC |
Codecov Report
@@ Coverage Diff @@
## master #6823 +/- ##
=======================================
- Coverage 92% 90% -2%
=======================================
Files 194 195 +1
Lines 12386 12904 +518
=======================================
+ Hits 11414 11611 +197
- Misses 972 1293 +321 |
I actually am worried this is not the right design. @edenafek had sugggested this should be built into the core of the |
Ah @awaelchli Sorry I missed the stuff at the top about If that is what is planned, and this is not a user-enabled argument, then the internal design is none of my business of course :-) |
pytorch_lightning/callbacks/timer.py
Outdated
def on_train_start(self, trainer, *args, **kwargs) -> None: | ||
self._start_time = datetime.now() | ||
|
||
def on_train_batch_end(self, trainer, *args, **kwargs) -> None: | ||
if self._interval != Interval.step: | ||
return | ||
self._check_time_remaining(trainer) | ||
|
||
def on_train_epoch_end(self, trainer, *args, **kwargs) -> None: | ||
if self._interval != Interval.epoch: | ||
return | ||
self._check_time_remaining(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.
in case people extend this callback, *args/**kwargs makes these callbacks harder to provide typehints for
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'm not sure I understand, because I am a typehint noob.
The arguments are unused, therefore they can be of type Any.
If I did specify all the args, linter will complain they are unused.
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.
Pushed a few commits with improvements.
LGTM
pytorch_lightning/callbacks/timer.py
Outdated
def on_train_start(self, *args, **kwargs) -> None: | ||
self._start_time[RunningStage.TRAINING] = datetime.now() | ||
|
||
def on_train_end(self, *args, **kwargs) -> None: | ||
self._end_time[RunningStage.TRAINING] = datetime.now() | ||
|
||
def on_validation_start(self, *args, **kwargs) -> None: | ||
self._start_time[RunningStage.VALIDATING] = datetime.now() | ||
|
||
def on_validation_end(self, *args, **kwargs) -> None: | ||
self._end_time[RunningStage.VALIDATING] = datetime.now() | ||
|
||
def on_test_start(self, *args, **kwargs) -> None: | ||
self._start_time[RunningStage.TESTING] = datetime.now() | ||
|
||
def on_test_end(self, *args, **kwargs) -> None: | ||
self._end_time[RunningStage.TESTING] = datetime.now() |
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.
n00b q: would this fail with daylight savings time? should we use time.monotonic()
in case system clocks are reset or rewound?
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 switched everything to monotonic, but note now time_elapsed() etc returns seconds.
Hope that's fine.
Co-authored-by: Akihiro Nitta <[email protected]>
What does this PR do?
Partial #6795
RFC about naming suggestions and API (class, arguments, methods).
Proposed solution:
TODO:
Comment on the PR with preferences/opinion about the following questions:
Before submitting
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:
Did you have fun?
Make sure you had fun coding 🙃