-
Notifications
You must be signed in to change notification settings - Fork 441
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 grad norm logging single device #1451
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1451
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2d46255 with merge base dfc69e2 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@@ -132,6 +136,10 @@ def __init__(self, cfg: DictConfig) -> None: | |||
self._resume_from_checkpoint = cfg.resume_from_checkpoint | |||
self._save_adapter_weights_only = cfg.get("save_adapter_weights_only", False) | |||
self._gradient_accumulation_steps = cfg.gradient_accumulation_steps | |||
self._clip_grad_norm = cfg.get("clip_grad_norm", None) | |||
self._log_grad_norm = cfg.get("log_grad_norm", False) |
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.
We don't really need log_grad_norm
. If clip_grad_norm
is set, we can log grad norm by default. Computing this each step doesn't increase the time for single device.
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.
Yeah based on your results I agree, seems like no negative perf impact to just logging by default. Can you also make the same changes in full_finetune_single_device.py and confirm that no negative perf impact there? (I think we should enable for both recipes in one go.)
Distributed may be a different story if we have to sync, but we can consider that out of scope for this PR.
If the results look similar for full finetune, I agree it makes sense to go ahead and remove the log_grad_norm
config. I would even bias towards just always logging grad norm (that way you don't have to awkwardly set it to 'inf'
to turn on logging, imo that's a bit unintuitive).
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.
This looks good! Apart from my comment around enabling for full finetune, we can also run a version with clip_grad_norm
set to some finite value to ensure that we see it reflected correctly in the logs.
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.
This looks great, thank you!
Context
What is the purpose of this PR? Is it to
Please link to any issues this PR addresses.
Changelog
What are the changes made in this PR?
clip_grad_norm
is setTest plan
Please make sure to do each of the following if applicable to your PR. (If you're not sure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.)
pre-commit install
)pytest tests
pytest tests -m integration_test
Did not observe any changes to overall compute time or loss.
log_grad_norm=True
, blue is baselineObserved no increase in batch/s. Verified clip_grad_norm clips gradients (in orange)
UX