class_docstr: Implements Lookahead optimization algorithm.
  
  It has been proposed in `Lookahead Optimizer: k steps forward, 1
  step back`__
  
  Arguments:
      optimizer: base inner optimizer optimize, like Yogi, DiffGrad or Adam.
      k: number of lookahead steps (default: 5)
      alpha: linear interpolation factor. 1.0 recovers the inner optimizer.
          (default: 5)
  
  Example:
      >>> import torch_optimizer as optim
      >>> yogi = optim.Yogi(model.parameters(), lr=0.1)
      >>> optimizer = optim.Lookahead(yogi, k=5, alpha=0.5)
      >>> optimizer.zero_grad()
      >>> loss_fn(model(input), target).backward()
      >>> optimizer.step()
  
  __ https://arxiv.org/abs/1907.08610
  
  Note:
      Reference code: https://github.com/alphadl/lookahead.pytorch
code: def __init__(
      self, optimizer: Optimizer, k: int = 5, alpha: float = 0.5
  ) -> None:
      if k < 0.0:
          raise ValueError(
              "Invalid number of lookahead steps: {}".format(k)
          )
      if alpha < 0:
          raise ValueError(
              "Invalid linear interpolation factor: {}".format(alpha)
          )
  
      self.optimizer = optimizer
      self.k = k
      self.alpha = alpha
      self.param_groups = self.optimizer.param_groups
      self.state = defaultdict(dict)
      self.fast_state = self.optimizer.state
      for group in self.param_groups:
          group["counter"] = 0
      self.defaults = {"k": k, "alpha": alpha, **optimizer.defaults}
  
file_path: pytorch-optimizer/torch_optimizer/lookahead.py
imports: from collections import defaultdict
  from typing import Any, Dict
  import torch
  from torch.optim.optimizer import Optimizer
  from .types import OptFloat, OptLossClosure, State
label_desc: Use image node_id 1 to create a new Lookahead object from inherited base classes: Optimizer with example: obj = Lookahead(optimizer, k, alpha)