Skip to content
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

[Bug] grad_weight can't be NoneType when running with DeepSpeed on Zero3. #428

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions megatron/core/tensor_parallel/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def forward(ctx, input, weight, bias, gradient_accumulation_fusion,
@staticmethod
@custom_bwd
def backward(ctx, grad_output):
args = get_args()
input, weight = ctx.saved_tensors
use_bias = ctx.use_bias

Expand Down Expand Up @@ -366,9 +367,13 @@ def backward(ctx, grad_output):
# grad_weight = None
# else:
# grad_weight = grad_output.t().matmul(total_input)
from megatron.core.tensor_parallel.weight_grad_store import WeightGradStore
WeightGradStore.put(total_input, grad_output, weight, gradientUpdateFunction)
grad_weight = None
if args.enable_zbh1_pipeline:
from megatron.core.tensor_parallel.weight_grad_store import WeightGradStore
WeightGradStore.put(total_input, grad_output, weight, gradientUpdateFunction)
grad_weight = None
else:
grad_weight = grad_output.t().matmul(total_input)

grad_bias = grad_output.sum(dim=0) if use_bias else None

if ctx.sequence_parallel:
Expand Down