Not supporting closure.
(self, closure=None)
| 2548 | |
| 2549 | @instrument_w_nvtx |
| 2550 | def step(self, closure=None): |
| 2551 | """ |
| 2552 | Not supporting closure. |
| 2553 | """ |
| 2554 | self._pre_step() |
| 2555 | self._partition_all_parameters() |
| 2556 | |
| 2557 | #checks for overflow, adjust the loss scale accordingly |
| 2558 | if self._overflow_check_and_loss_scale_update(): |
| 2559 | if self.swap_optimizer: |
| 2560 | self.optimizer_swapper.log_timers() |
| 2561 | return |
| 2562 | |
| 2563 | norm_groups = self._get_norm_groups() |
| 2564 | scaled_global_grad_norm = torch.linalg.vector_norm(torch.stack(norm_groups)) |
| 2565 | |
| 2566 | # Stash unscaled gradient norm |
| 2567 | self._global_grad_norm = scaled_global_grad_norm / self.loss_scale |
| 2568 | |
| 2569 | timer_names = set() |
| 2570 | |
| 2571 | timer_names.add(OPTIMIZER_STEP_TIMER) |
| 2572 | self.timers(OPTIMIZER_STEP_TIMER).start() |
| 2573 | |
| 2574 | #update parameters one sub group at a time |
| 2575 | for sub_group_id, group in enumerate(self.fp16_groups): |
| 2576 | |
| 2577 | #prepare optimizer states, gradients and fp32 parameters for update |
| 2578 | self._prepare_sub_group(sub_group_id, timer_names) |
| 2579 | |
| 2580 | #scale the fp32 gradients |
| 2581 | self.unscale_and_clip_grads(sub_group_id, scaled_global_grad_norm) |
| 2582 | |
| 2583 | #apply the optimizer step on the sub group and copy fp32 parameters to fp16 |
| 2584 | self._optimizer_step(sub_group_id) |
| 2585 | |
| 2586 | #put fp16 parameters in appropriate location |
| 2587 | self._reassign_or_swap_out_partitioned_parameters(sub_group_id) |
| 2588 | |
| 2589 | #release memory or swap out optimizer states of fp32 parameters |
| 2590 | self._release_sub_group(sub_group_id, timer_names) |
| 2591 | |
| 2592 | self.timers(OPTIMIZER_STEP_TIMER).stop() |
| 2593 | |
| 2594 | self._post_step(timer_names) |
| 2595 | |
| 2596 | # warn user about caching allocator flushes |
| 2597 | memory_stats = get_accelerator().memory_stats() |
| 2598 | alloc_retries = memory_stats.get("num_alloc_retries") |
| 2599 | if alloc_retries is None: |
| 2600 | alloc_retries = 0 |
| 2601 | if alloc_retries > self.n_caching_allocator_flushes: |
| 2602 | if dist.get_rank() == 0: |
| 2603 | logger.warning( |
| 2604 | "%d pytorch allocator cache flushes since last step. this happens " |
| 2605 | "when there is high memory pressure and is detrimental to " |
| 2606 | "performance. if this is happening frequently consider adjusting " |
| 2607 | "settings to reduce memory consumption. If you are unable to " |
no test coverage detected