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)
| 3377 | |
| 3378 | @contextmanager |
| 3379 | def no_sync(self): |
| 3380 | r""" |
| 3381 | Context manager to disable gradient reduction during backward pass. |
| 3382 | This context manager has the following effects on other DeepSpeed features: |
| 3383 | 1. Incompatible with ZeRO stage 2/3 which rely on reduction for gradient partitioning. |
| 3384 | 2. It is illegal to call engine.step() within the context manager. |
| 3385 | 3. Tracking of gradient accumulation steps is disabled. |
| 3386 | """ |
| 3387 | assert not self.zero_optimization_partition_gradients(), \ |
| 3388 | f"no_sync context manager is incompatible with gradient partitioning logic of ZeRO stage {self.zero_optimization_stage()}" |
| 3389 | |
| 3390 | assert not self.inside_no_sync_ctxt, "no_sync context manager reentry is unsupported" |
| 3391 | |
| 3392 | self.inside_no_sync_ctxt = True |
| 3393 | try: |
| 3394 | yield |
| 3395 | finally: |
| 3396 | self.inside_no_sync_ctxt = False |
| 3397 | |
| 3398 | @contextmanager |
| 3399 | def coalesce_grad_reduction(self): |