MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / step

Method step

deepspeed/runtime/engine.py:3727–3846  ·  view source on GitHub ↗

r"""Execute the weight update step after forward and backward propagation on effective_train_batch. In managed gradient accumulation (default), the optimizer update is applied only on the accumulation boundary tracked by the internal micro-step counter. With ``manage

(self, lr_kwargs=None)

Source from the content-addressed store, hash-verified

3725 self.global_samples += self.train_batch_size()
3726
3727 def step(self, lr_kwargs=None):
3728 r"""Execute the weight update step after forward and backward propagation
3729 on effective_train_batch.
3730
3731 In managed gradient accumulation (default), the optimizer update is applied only
3732 on the accumulation boundary tracked by the internal micro-step counter. With
3733 ``managed_gradient_accumulation=false``, every ``step()`` is the accumulation
3734 boundary: it finalizes the locally accumulated gradients and applies an update.
3735 """
3736 assert not self.inside_no_sync_ctxt, \
3737 "It is illegal to call Engine.step() inside no_sync context manager"
3738
3739 see_memory_usage("Engine before step", force=self.memory_breakdown())
3740
3741 # Check early because self.global_steps is incremented at some point here.
3742 # TODO: Delay self.global_steps increment until very end of this function.
3743 flops_profiler_active = self.flops_profiler_enabled(
3744 ) and self.global_steps == self.flops_profiler_profile_step() and self.global_rank == 0
3745
3746 self._start_timers(self.engine_timers.step_timers)
3747
3748 assert self.optimizer is not None and not isinstance(self.optimizer, DummyOptim), \
3749 "must provide optimizer during init in order to use step"
3750
3751 report_progress = False
3752
3753 self._step_applied = False # assume False, will flip to True
3754
3755 # Unmanaged mode: step() is the accumulation boundary.
3756 self._running_engine_step = True
3757
3758 # Unmanaged boundary: stage 2/3 already reduced/partitioned per backward so only finalize (incl. offload); stage 0/1/DDP reduce here.
3759 if not self.managed_gradient_accumulation():
3760 if self.zero_optimization_partition_gradients():
3761 self.optimizer.finalize_gradient_accumulation_boundary()
3762 elif self.enable_backward_allreduce and not self.inside_no_sync_ctxt:
3763 self.allreduce_gradients()
3764
3765 if self.zenflow:
3766 self.optimizer._sync_selective_optimizer_lr()
3767 if self.auto_update:
3768 self.update_interval += 1
3769
3770 # Update the model when we reach gradient accumulation boundaries
3771 if self.is_gradient_accumulation_boundary():
3772 if self.checkpoint_engine.is_decoupled():
3773 self._commit_decoupled_checkpoint()
3774
3775 if any(dw_staging.has_staged_rows for dw_staging in getattr(self, "_autoep_dw_stagings", ())):
3776 raise RuntimeError("Expert weight gradients are still staged at an optimizer step, which would "
3777 "apply them one step late. deferred_dw_flush_period needs the backward that "
3778 "closes each gradient accumulation window to run through the engine.")
3779
3780 self._take_model_step(lr_kwargs)
3781
3782 report_progress = self.global_rank == 0 if self.global_rank else True
3783
3784 if self.zenflow:

Callers 1

_take_model_stepMethod · 0.45

Calls 15

memory_breakdownMethod · 0.95
_start_timersMethod · 0.95
allreduce_gradientsMethod · 0.95
_take_model_stepMethod · 0.95
_stop_timersMethod · 0.95
get_lrMethod · 0.95

Tested by

no test coverage detected