code: def __init__(self, base_optimizer, alpha=0.5, k=6):
      # NOTE super().__init__() not called on purpose
      self._optimizer_step_pre_hooks: Dict[
          int, Callable
      ] = OrderedDict()
      self._optimizer_step_post_hooks: Dict[
          int, Callable
      ] = OrderedDict()
      if not 0.0 <= alpha <= 1.0:
          raise ValueError(f"Invalid slow update rate: {alpha}")
      if not 1 <= k:
          raise ValueError(f"Invalid lookahead steps: {k}")
      defaults = dict(
          lookahead_alpha=alpha, lookahead_k=k, lookahead_step=0
      )
      self._base_optimizer = base_optimizer
      self.param_groups = base_optimizer.param_groups
      self.defaults = base_optimizer.defaults
      self.defaults.update(defaults)
      self.state = defaultdict(dict)
      # manually add our defaults to the param groups
      for name, default in defaults.items():
          for group in self._base_optimizer.param_groups:
              group.setdefault(name, default)
  
file_path: pytorch-image-models/timm/optim/lookahead.py
imports: from collections import OrderedDict
  from typing import Callable, Dict
  import torch
  from torch.optim.optimizer import Optimizer
  from collections import defaultdict
label_desc: Use image node_id 1 to create a new Lookahead object from inherited base classes: Optimizer with example: obj = Lookahead(base_optimizer, alpha, k)