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)
| 3405 | |
| 3406 | @contextmanager |
| 3407 | def no_sync(self): |
| 3408 | r""" |
| 3409 | Context manager to disable gradient reduction during backward pass. |
| 3410 | This context manager has the following effects on other DeepSpeed features: |
| 3411 | 1. Incompatible with ZeRO stage 2/3 which rely on reduction for gradient partitioning. |
| 3412 | 2. It is illegal to call engine.step() within the context manager. |
| 3413 | 3. Tracking of gradient accumulation steps is disabled. |
| 3414 | """ |
| 3415 | assert not self.zero_optimization_partition_gradients(), \ |
| 3416 | f"no_sync context manager is incompatible with gradient partitioning logic of ZeRO stage {self.zero_optimization_stage()}" |
| 3417 | |
| 3418 | assert not self.inside_no_sync_ctxt, "no_sync context manager reentry is unsupported" |
| 3419 | |
| 3420 | self.inside_no_sync_ctxt = True |
| 3421 | try: |
| 3422 | yield |
| 3423 | finally: |
| 3424 | self.inside_no_sync_ctxt = False |
| 3425 | |
| 3426 | @contextmanager |
| 3427 | def coalesce_grad_reduction(self): |