class_docstr: Implements MADGRAD algorithm.
  
  It has been proposed in `Adaptivity without Compromise: A Momentumized,
  Adaptive, Dual Averaged Gradient Method for Stochastic Optimization`__
  
  Arguments:
      params (iterable):
          Iterable of parameters to optimize
          or dicts defining parameter groups.
      lr (float):
          Learning rate (default: 1e-2).
      momentum (float):
          Momentum value in  the range [0,1) (default: 0.9).
      weight_decay (float):
          Weight decay, i.e. a L2 penalty (default: 0).
      eps (float):
          Term added to the denominator outside of the root operation
          to improve numerical stability. (default: 1e-6).
  
  Example:
      >>> import torch_optimizer as optim
      >>> optimizer = optim.MAGRAD(model.parameters(), lr=0.1)
      >>> optimizer.zero_grad()
      >>> loss_fn(model(input), target).backward()
      >>> optimizer.step()
  
  __ https://arxiv.org/abs/2101.11075
  
  Note:
      Reference code: https://github.com/facebookresearch/madgrad
code: def __init__(
      self,
      params: Params,
      lr: float = 1e-2,
      momentum: float = 0.9,
      weight_decay: float = 0.0,
      eps: float = 1e-6,
  ):
      if momentum < 0 or momentum >= 1:
          raise ValueError(
              "Invalid momentum value: {}".format(momentum)
          )
      if lr <= 0.0:
          raise ValueError("Invalid learning rate: {}".format(lr))
      if weight_decay < 0:
          raise ValueError(
              "Invalid weight_decay value: {}".format(weight_decay)
          )
      if eps < 0.0:
          raise ValueError("Invalid epsilon value: {}".format(eps))
  
      defaults = dict(
          lr=lr,
          eps=eps,
          momentum=momentum,
          weight_decay=weight_decay,
          k=0,
      )
      super().__init__(params, defaults)
  
      for group in self.param_groups:
          for p in group["params"]:
              state = self.state[p]
  
              state["grad_sum_sq"] = torch.zeros_like(p.data).detach()
              state["s"] = torch.zeros_like(p.data).detach()
              if momentum != 0:
                  state["x0"] = torch.clone(p.data).detach()
  
file_path: pytorch-optimizer/torch_optimizer/madgrad.py
imports: import math
  from typing import Callable, Optional
  import torch
  import torch.optim
  from .types import Params
label_desc: Use image node_id 1 to create a new MADGRAD object from inherited base classes: torch.optim with example: obj = MADGRAD(params, lr, momentum, weight_decay, eps)