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)
| 3300 | |
| 3301 | @contextmanager |
| 3302 | def no_sync(self): |
| 3303 | r""" |
| 3304 | Context manager to disable gradient reduction during backward pass. |
| 3305 | This context manager has the following effects on other DeepSpeed features: |
| 3306 | 1. Incompatible with ZeRO stage 2/3 which rely on reduction for gradient partitioning. |
| 3307 | 2. It is illegal to call engine.step() within the context manager. |
| 3308 | 3. Tracking of gradient accumulation steps is disabled. |
| 3309 | """ |
| 3310 | assert not self.zero_optimization_partition_gradients(), \ |
| 3311 | f"no_sync context manager is incompatible with gradient partitioning logic of ZeRO stage {self.zero_optimization_stage()}" |
| 3312 | |
| 3313 | assert not self.inside_no_sync_ctxt, "no_sync context manager reentry is unsupported" |
| 3314 | |
| 3315 | self.inside_no_sync_ctxt = True |
| 3316 | try: |
| 3317 | yield |
| 3318 | finally: |
| 3319 | self.inside_no_sync_ctxt = False |
| 3320 | |
| 3321 | @contextmanager |
| 3322 | def coalesce_grad_reduction(self): |