code: def _single_tensor_adagrad(
      params: List[Tensor],
      grads: List[Tensor],
      state_sums: List[Tensor],
      state_steps: List[Tensor],
      *,
      lr: float,
      weight_decay: float,
      lr_decay: float,
      eps: float,
      has_sparse_grad: bool,
      maximize: bool,
      differentiable: bool,
      has_complex: bool,
  ):
      for param, grad, state_sum, step_t in zip(
          params, grads, state_sums, state_steps
      ):
          # update step
          step_t += 1
          step = _get_value(step_t)
          grad = grad if not maximize else -grad
  
          if weight_decay != 0:
              if grad.is_sparse:
                  raise RuntimeError(
                      "weight_decay option is not compatible with sparse gradients"
                  )
              grad = grad.add(param, alpha=weight_decay)
  
          clr = lr / (1 + (step - 1) * lr_decay)
  
          if grad.is_sparse:
              grad = (
                  grad.coalesce()
              )  # the update is non-linear so indices must be unique
              grad_indices = grad._indices()
              grad_values = grad._values()
  
              state_sum.add_(
                  _make_sparse(grad, grad_indices, grad_values.pow(2))
              )
              std = state_sum.sparse_mask(grad)
              std_values = std._values().sqrt_().add_(eps)
              param.add_(
                  _make_sparse(
                      grad, grad_indices, grad_values / std_values
                  ),
                  alpha=-clr,
              )
          else:
              is_complex = torch.is_complex(param)
              if is_complex:
                  grad = torch.view_as_real(grad)
                  state_sum = torch.view_as_real(state_sum)
                  param = torch.view_as_real(param)
              state_sum.addcmul_(grad, grad, value=1)
              if differentiable:
                  std = state_sum.sqrt() + eps
              else:
                  std = state_sum.sqrt().add_(eps)
              param.addcdiv_(grad, std, value=-clr)
              if is_complex:
                  param = torch.view_as_complex(param)
                  state_sum = torch.view_as_complex(state_sum)
  
file_path: pytorch/torch/optim/adagrad.py
imports: import torch
  from torch import Tensor
  from .optimizer import Optimizer, _use_grad_for_differentiable, _get_value, _view_as_real, _default_to_fused_or_foreach, _get_scalar_dtype, _differentiable_doc, _foreach_doc, _maximize_doc
  from typing import List, Optional
label_desc: Use image node_id 3 for calling a global function with example usage: _single_tensor_adagrad(params, grads, state_sums, state_steps) without return types