r""" Args: Loads the ExponentialMovingAverage state. This method is used by accelerate during checkpointing to save the ema state dict. state_dict (dict): EMA state. Should be an object returned from a call to :meth:`state_dict`.
(self, state_dict: dict)
| 559 | self.temp_stored_params = None |
| 560 | |
| 561 | def load_state_dict(self, state_dict: dict) -> None: |
| 562 | r""" |
| 563 | Args: |
| 564 | Loads the ExponentialMovingAverage state. This method is used by accelerate during checkpointing to save the |
| 565 | ema state dict. |
| 566 | state_dict (dict): EMA state. Should be an object returned |
| 567 | from a call to :meth:`state_dict`. |
| 568 | """ |
| 569 | # deepcopy, to be consistent with module API |
| 570 | state_dict = copy.deepcopy(state_dict) |
| 571 | |
| 572 | self.decay = state_dict.get("decay", self.decay) |
| 573 | if self.decay < 0.0 or self.decay > 1.0: |
| 574 | raise ValueError("Decay must be between 0 and 1") |
| 575 | |
| 576 | self.min_decay = state_dict.get("min_decay", self.min_decay) |
| 577 | if not isinstance(self.min_decay, float): |
| 578 | raise ValueError("Invalid min_decay") |
| 579 | |
| 580 | self.optimization_step = state_dict.get("optimization_step", self.optimization_step) |
| 581 | if not isinstance(self.optimization_step, int): |
| 582 | raise ValueError("Invalid optimization_step") |
| 583 | |
| 584 | self.update_after_step = state_dict.get("update_after_step", self.update_after_step) |
| 585 | if not isinstance(self.update_after_step, int): |
| 586 | raise ValueError("Invalid update_after_step") |
| 587 | |
| 588 | self.use_ema_warmup = state_dict.get("use_ema_warmup", self.use_ema_warmup) |
| 589 | if not isinstance(self.use_ema_warmup, bool): |
| 590 | raise ValueError("Invalid use_ema_warmup") |
| 591 | |
| 592 | self.inv_gamma = state_dict.get("inv_gamma", self.inv_gamma) |
| 593 | if not isinstance(self.inv_gamma, (float, int)): |
| 594 | raise ValueError("Invalid inv_gamma") |
| 595 | |
| 596 | self.power = state_dict.get("power", self.power) |
| 597 | if not isinstance(self.power, (float, int)): |
| 598 | raise ValueError("Invalid power") |
| 599 | |
| 600 | shadow_params = state_dict.get("shadow_params", None) |
| 601 | if shadow_params is not None: |
| 602 | self.shadow_params = shadow_params |
| 603 | if not isinstance(self.shadow_params, list): |
| 604 | raise ValueError("shadow_params must be a list") |
| 605 | if not all(isinstance(p, torch.Tensor) for p in self.shadow_params): |
| 606 | raise ValueError("shadow_params must all be Tensors") |
no outgoing calls