-
Notifications
You must be signed in to change notification settings - Fork 806
[PyTorch] Type the grouped wgrad from main_grad for distributed weights #3397
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
| materialize_weight_for_forward, | ||
| materialize_weight_for_backward, | ||
| finalize_weight_grads, | ||
| weight_grad_buffers, | ||
| weight_grad_dtype, | ||
| ) | ||
| from ...module.base import _2X_ACC_WGRAD | ||
| from ...quantization import Recipe | ||
|
|
@@ -573,7 +575,7 @@ def _compute_grad_params( | |
| shapes=[weight_shape] * num_groups, | ||
| quantizer=None, | ||
| device=device, | ||
| dtype=dtype, | ||
| dtype=weight_grad_dtype(weights, dtype), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont understand how this will help, since we will never enter this else condition of allocating using torch.empty, if main_grad is attached to the parameter.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we will, if accumulate_into_main_grad is False, but why are we attaching main_grad to parameter in that case in Megatron?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @vthumbe1503 , for you first question why this line's change is required: we need to follow Details:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for MLM:
|
||
| ) | ||
| wgrad_output = grouped_wgrad | ||
| w_list = [grouped_wgrad.rowwise_data.view(num_groups, *weight_shape)] | ||
|
|
@@ -586,13 +588,7 @@ def _compute_grad_params( | |
| w_list = [get_main_grad_from_param(w, op_label=op_label) for w in weights] | ||
| accumulate_into_main_grad = get_accumulate_flag_in_param(weights[0]) | ||
| else: | ||
| wgrad_packed = torch.empty( | ||
| num_groups, | ||
| *weight_shape, | ||
| dtype=dtype, | ||
| device=device, | ||
| ) | ||
| w_list = [wgrad_packed[i] for i in range(num_groups)] | ||
| w_list = weight_grad_buffers(weights, weight_shape, dtype, device) | ||
| wgrad_output = w_list | ||
|
|
||
| if ctx.weight_requires_grad: | ||
|
|
||
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.
When a distributed weight group uses a protocol-bearing leader with ordinary tensor followers,
weight_grad_bufferschecks only the leader but callsgrad_buffer()on every member, causing backward to fail withAttributeError.Knowledge Base Used: PyTorch Distributed/Parallel Training Support