code: def __init__(
      self,
      params,
      lr=1e-3,
      betas=(0.9, 0.999),
      eps=1e-8,
      maximize: bool = False,
  ):
      if not 0.0 < lr:
          raise ValueError(f"Invalid learning rate: {lr}")
      if not 0.0 < eps:
          raise ValueError(f"Invalid epsilon value: {eps}")
      if not 0.0 <= betas[0] < 1.0:
          raise ValueError(
              f"Invalid beta parameter at index 0: {betas[0]}"
          )
      if not 0.0 <= betas[1] < 1.0:
          raise ValueError(
              f"Invalid beta parameter at index 1: {betas[1]}"
          )
  
      defaults = dict(lr=lr, betas=betas, eps=eps, maximize=maximize)
      super().__init__(params, defaults)
  
      sparse_params = []
      for index, param_group in enumerate(self.param_groups):
          assert isinstance(
              param_group, dict
          ), f"param_groups must be a list of dicts, but got {type(param_group)}"
          # given param group, convert given params to a list first before iterating
          for d_index, d_param in enumerate(param_group["params"]):
              if d_param.is_sparse:
                  sparse_params.append([index, d_index])
      if sparse_params:
          raise ValueError(
              f"Sparse params at indices {sparse_params}: SparseAdam requires dense parameter tensors"
          )
  
imports: import torch
  from .None import _functional
  from .optimizer import Optimizer, _maximize_doc
label_desc: Use image node_id 1 to create a new SparseAdam object from inherited base classes: Optimizer with example: obj = SparseAdam(params, lr, betas, eps, maximize)