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

Method no_sync

deepspeed/runtime/engine.py:2897–2914  ·  view source on GitHub ↗

r""" Context manager to disable gradient reduction during backward pass. This context manager has the following effects on other DeepSpeed features: 1. Incompatible with ZeRO stage 2/3 which rely on reduction for gradient partitioning. 2. It is illegal

(self)

Source from the content-addressed store, hash-verified

2895
2896 @contextmanager
2897 def no_sync(self):
2898 r"""
2899 Context manager to disable gradient reduction during backward pass.
2900 This context manager has the following effects on other DeepSpeed features:
2901 1. Incompatible with ZeRO stage 2/3 which rely on reduction for gradient partitioning.
2902 2. It is illegal to call engine.step() within the context manager.
2903 3. Tracking of gradient accumulation steps is disabled.
2904 """
2905 assert not self.zero_optimization_partition_gradients(), \
2906 f"no_sync context manager is incompatible with gradient partitioning logic of ZeRO stage {self.zero_optimization_stage()}"
2907
2908 assert not self.inside_no_sync_ctxt, "no_sync context manager reentry is unsupported"
2909
2910 self.inside_no_sync_ctxt = True
2911 try:
2912 yield
2913 finally:
2914 self.inside_no_sync_ctxt = False
2915
2916 @contextmanager
2917 def coalesce_grad_reduction(self):