-
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 configure_gradient_clipping
hook in LightningModule
#9584
Conversation
@carmocca should we deprecate |
@rohitgr7 imo we should discuss this more on the issue. I think there are some design aspects that have to be worked out first |
clip_gradients
hook in `LightningModuleclip_gradients
hook in LightningModule
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 don't understand this PR. It seems to be incomplete.
Today I am doing this:
Trainer(gradient_clip_val=15.0)
or
python train.py --trainer.gradient_clip_val 15.0
This PR aims at deprecating this option. How do I achieve the above now? There seems to be a hook attempting to replace this functionality, but this is missing the point why the Trainer argument exists in the first place. 99.9% of the time the user does not need to implement gradient clipping because Lightning can do it. But by removing this now, you force the user to 100% of the time have to implement a hook? IMO you are removing a perfectly fine feature and I vote against going in this direction. If configurability is desired, it should be entirely optional.
51bf84c
to
7a221fb
Compare
so for now I have implemented option 2 from here: #6346 (comment) feel free to put your suggestions/recommendations here or on the issue :) |
Codecov Report
@@ Coverage Diff @@
## master #9584 +/- ##
======================================
Coverage 93% 93%
======================================
Files 178 178
Lines 15652 15717 +65
======================================
+ Hits 14508 14572 +64
- Misses 1144 1145 +1 |
clip_gradients
hook in LightningModule
configure_gradient_clipping
hook in LightningModule
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 ! Nice work :)
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.
while this addition is probably needed and desired from a practical point of view, it also shows where Lightning's automatic optimization breaks down imo, because the desire of configuration here means ignoring settings that were provided through the trainer, which then in turn also challenges reproducibility.
settings provided in the trainer will still work and one doesn't need to change their code at all since those trainer args are passed here by default. This is completely optional for those who want to configure it as per their requirement. Doesn't break automatic optimization. |
Yes it does! Let me make it explicit with an example:
Now:
Same issue when configuration is done externally:
This is where Lightning reaches the limit and essentially breaks. This is an issue we will face more in the future. |
okay.. so for this what we can do is make these two trainer arguments None by default. Now inside clip_gradients we can check:
wdyt @awaelchli ? |
af6b692
to
36ff5b5
Compare
…g-AI#9584) * init hook * docs * dep train args * update tests * doc * doc * .gitignore * not dep * add trainer args * add & update tests * fix tests * pre-commit * docs * add docs * add exception * code review * deepspeed * update tests * not * try fix * Apply suggestions from code review * update deepspeed * disable some tests * disable some tests * enable all tests
What does this PR do?
Fixes #6346
Does your PR introduce any breaking changes? If yes, please list them.
Before submitting
PR review
Anyone in the community is welcome to review the PR.
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 🙃