-
Notifications
You must be signed in to change notification settings - Fork 282
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 main_grad #1140
base: ngoyal_changes_for_pp_fp8
Are you sure you want to change the base?
Add main_grad #1140
Conversation
3f34441
to
239ed36
Compare
@@ -1713,6 +1713,13 @@ def _post_backward_hook(self, param: Parameter, *unused: Any) -> None: | |||
|
|||
# Switch to FP32 shard after backward. | |||
self._use_fp32_param_shard([param]) | |||
if self.mixed_precision and self.fp32_reduce_scatter: |
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.
Currently for fp8, we do not use mixed_precision
, so we should remove this.
Only check
if self.fp32_reduce_scatter:
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.
Addressed the comment.
239ed36
to
ad54660
Compare
|
||
if self.fp32_reduce_scatter: | ||
# Cast grad to FP32. | ||
param.grad.data = param.grad.data.float() | ||
|
||
orig_grad_data = param.grad.data |
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.
Move here to make orig_grad_data
FP32. This was from #1139 (comment)
@@ -1721,23 +1728,31 @@ def _post_backward_hook(self, param: Parameter, *unused: Any) -> None: | |||
# reductions in post_backward stream. | |||
self._streams["post_backward"].wait_stream(torch.cuda.current_stream()) | |||
with torch.cuda.stream(self._streams["post_backward"]): | |||
orig_grad_data = param.grad.data | |||
|
|||
if self.fp32_reduce_scatter: | |||
# Cast grad to FP32. | |||
param.grad.data = param.grad.data.float() |
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 feel this is right since param.grad will be None from L1722.
Overall, this PR creates main_grad for flat parameters while what we need to do is main_grad visible to TE modules. So probably we need to change FlatParameter as well?
Is this based on one of Naman's branches?
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 have a branch where i am adding param.main_grad to FlatParams to enable fuse wgrad accumulation. here is the PR : #1142
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.
Thanks! Feel free to ignore the changes in this PR. Still learning about FlatParams etc.
What does this PR do?
Fixes main_grad following up #1139 (comment)
Before submitting
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.