Skip to content

Commit

Permalink
Add condition when dimension is greater than 2 (#4390)
Browse files Browse the repository at this point in the history
When dimension is greater than 2, grad_bias should be calculated differently.
  • Loading branch information
ajindal1 authored Sep 27, 2023
1 parent 5861940 commit 28b9d5c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion deepspeed/runtime/zero/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ def backward(ctx, grad_output):
#print(f"Computed grad weight grad_weight {grad_weight.shape}")
if bias is not None and ctx.needs_input_grad[2]:
#print("Computing grad bias")
grad_bias = grad_output.sum(0)
if dim > 2:
grad_bias = grad_output.sum([i for i in range(dim - 1)])
else:
grad_bias = grad_output.sum(0)
#print("Done computing grad bias")
#print("needs bias")
#print(f"backward shaped grad_input {grad_input.shape}, grad_weight {grad_weight.shape}, grad_bias {grad_bias.shape if grad_bias is not None else None}")
Expand Down

0 comments on commit 28b9d5c

Please sign in to comment.