Skip to content

Commit 75c3d3c

Browse files
committed
Assert on a missing gradient in the ZenFlow parallel offload copy
ZenFlowZeroOptimizerParallel.async_inplace_copy_grad_to_fp32_buffer_from_gpu branches on `grad_accum is None` and then calls `.view(-1)` on it in both branches, so the None branch raises AttributeError instead of handling None. DeepSpeedZeroOptimizer's own copy of this method asserts the attribute is present rather than branching. Do the same here: identical behaviour when the gradient exists, and a clear assertion instead of an AttributeError when it does not. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
1 parent d4ed1f1 commit 75c3d3c

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

deepspeed/runtime/zenflow/zenflow_stage_1_and_2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,9 @@ def async_inplace_copy_grad_to_fp32_buffer_from_gpu(self, param):
685685
0, dest_offset, num_elements)
686686

687687
grad_accum = self.get_param_gradient_attribute(param)
688-
if grad_accum is None:
689-
src_tensor = grad_accum.view(-1).narrow(0, source_offset, num_elements)
690-
else:
691-
src_tensor = grad_accum.view(-1).narrow(0, source_offset, num_elements)
688+
assert grad_accum is not None
689+
690+
src_tensor = grad_accum.view(-1).narrow(0, source_offset, num_elements)
692691
if src_tensor.dtype != self.master_weights_and_grads_dtype:
693692
src_tensor = src_tensor.to(self.master_weights_and_grads_dtype)
694693

0 commit comments

Comments
 (0)