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
docstr: Returns the state of the optimizer as a :class:`dict`.
  
  It contains two entries:
  * state - a dict holding current optimization state. Its content
      differs between optimizer classes.
  * param_groups - a dict containing all parameter groups
docstr_tok: ["Returns","the","state","of","the","optimizer","as","a",":","class",":","`","dict","`",".","It","contains","two","entries",":","*","state","-","a","dict","holding","current","optimization","state",".","Its","content","differs","between","optimizer","classes",".","*","param_groups","-","a","dict","containing","all","parameter","groups"]
code: def state_dict(self) -> State:
      r"""Returns the state of the optimizer as a :class:`dict`.
  
      It contains two entries:
      * state - a dict holding current optimization state. Its content
          differs between optimizer classes.
      * param_groups - a dict containing all parameter groups
      """
      slow_state_dict = super(Lookahead, self).state_dict()
      fast_state_dict = self.optimizer.state_dict()
      fast_state = fast_state_dict["state"]
      param_groups = fast_state_dict["param_groups"]
      return {
          "fast_state": fast_state,
          "slow_state": slow_state_dict["state"],
          "param_groups": param_groups,
      }
  
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 4 for calling the Lookahead obj's underlying member method code with example usage: obj.state_dict() and returns: dict