-
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
Set precision=16 when use_amp is passed as True #1145
Conversation
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.
rather define deprecated API
Made the requested changes as far as I can tell. If I missed something, let me know! |
Hmm - it looks like trainer sets use_amp at some point and maybe this causes conflicts. I will debug and test locally. |
Ok, I have found and fixed the previous issue and run tests locally, so I believe things should work. One concern is that it looks like the trainer uses
Do you have a preference / other suggestions? |
in such case, it would make sense to have |
Right now, the trainer has this line if self.precision == 16 and self.num_tpu_cores is None:
use_amp = True
self.init_amp(use_amp) Then in def init_amp(self, use_amp):
self.use_amp = use_amp and APEX_AVAILABLE That means that the trainer, by default, accesses the setter for @property
def use_amp(self):
return self.precision < 32 and self.num_tpu_cores is None and APEX_AVAILABLE
@use_amp.setter
def use_amp(self, use_amp):
warnings.warn("`use_amp` has been deprecated in favor of `precision` since v0.7.0"
" and will be removed in v0.9.0", DeprecationWarning)
self.precision = 16 if use_amp else 32 But I'm not sure what to do about |
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.
good approach, just a bit cleaning according to your comment that we need use_amp
elsewhere
pls do changes as you suggest in #1145 (comment)
Can make those changes. What should I do about def init_amp(self, use_amp):
self.use_amp = use_amp and APEX_AVAILABLE
if self.use_amp:
log.info('Using 16bit precision.')
if use_amp and not APEX_AVAILABLE: # pragma: no cover
msg = """
You set `use_amp=True` but do not have apex installed.
Install apex first using this guide and rerun with use_amp=True:
https://github.com/NVIDIA/apex#linux
this run will NOT use 16 bit precision
"""
raise ModuleNotFoundError(msg) That means that the trainer access the One option is to make the following change: def init_amp(self, precision):
if isinstance(precision, bool):
# raise deprecation warning
self.use_amp = precision
if self.use_amp:
log.info('Using 16bit precision.') |
Codecov Report
@@ Coverage Diff @@
## master #1145 +/- ##
======================================
- Coverage 92% 92% -0%
======================================
Files 63 63
Lines 3323 3330 +7
======================================
+ Hits 3051 3057 +6
- Misses 272 273 +1 |
@rmrao I have applied all previous suggestions, but we still need to as test for this one |
This pull request is now in conflict... :( |
@rmrao how is it going, could I help? |
Hello @rmrao! Thanks for updating this PR.
Comment last updated at 2020-04-06 07:42:59 UTC |
@Borda can we merge this? |
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.
LGTM 🚀 @williamFalcon ^^
it seems that there is incompatibility with master... @rmrao ^^ |
Ok I just went back to the easy solution. Tests passed locally, so should be good. |
@rmrao it seems that I do have permission to push to your master to edit this PR, do you have enabled edit for maintained? |
I definitely have edit access for maintained enabled, just double checked. |
just curious, there is also |
This pull request is now in conflict... :( |
@rmrao did some more cleaning, could you please check and resolve conflicts... |
It looks good to me! |
@rmrao mind rebasing? |
@williamFalcon rebased ^^ |
* Set precision=16 when use_amp is passed as True * Update CHANGELOG.md * add use_amp to deprecated API * Update trainer.py * Update trainer.py * move the use_amp attribute to deprecated API * move use_amp deprecation back to Trainer's __init__ * drop unsed * drop deprecated * reorder imports * typing Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: William Falcon <waf2107@columbia.edu> Co-authored-by: J. Borovec <jirka.borovec@seznam.cz>
Before submitting
What does this PR do?
Fixes #1143
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 🙃