code: def adam(
      params: List[Tensor],
      grads: List[Tensor],
      exp_avgs: List[Tensor],
      exp_avg_sqs: List[Tensor],
      max_exp_avg_sqs: List[Tensor],
      state_steps: List[Tensor],
      # kwonly args with defaults are not supported by functions compiled with torchscript issue #70627
      # setting this as kwarg for now as functional API is compiled by torch/distributed/optim
      foreach: Optional[bool] = None,
      capturable: bool = False,
      differentiable: bool = False,
      fused: Optional[bool] = None,
      grad_scale: Optional[Tensor] = None,
      found_inf: Optional[Tensor] = None,
      has_complex: bool = False,
      *,
      amsgrad: bool,
      beta1: float,
      beta2: float,
      lr: Union[float, Tensor],
      weight_decay: float,
      eps: float,
      maximize: bool,
  ):
      r"""Functional API that performs Adam algorithm computation.
  
      See :class:`~torch.optim.Adam` for details.
      """
      # Respect when the user inputs False/True for foreach or fused. We only want to change
      # the default when neither have been user-specified. Note that we default to foreach
      # and pass False to use_fused. This is not a mistake--we want to give the fused impl
      # bake-in time before making it the default, even if it is typically faster.
      if fused is None and foreach is None:
          _, foreach = _default_to_fused_or_foreach(
              params, differentiable, use_fused=False
          )
          # Do not flip on foreach for the unsupported case where lr is a Tensor and capturable=False.
          if foreach and isinstance(lr, Tensor) and not capturable:
              foreach = False
      if fused is None:
          fused = False
      if foreach is None:
          foreach = False
  
      # this check is slow during compilation, so we skip it
      # if it's strictly needed we can add this check back in dynamo
      if not torch._utils.is_compiling() and not all(
          isinstance(t, torch.Tensor) for t in state_steps
      ):
          raise RuntimeError(
              "API has changed, `state_steps` argument must contain a list of singleton tensors"
          )
  
      if foreach and torch.jit.is_scripting():
          raise RuntimeError(
              "torch.jit.script not supported with foreach optimizers"
          )
      if fused and torch.jit.is_scripting():
          raise RuntimeError(
              "torch.jit.script not supported with fused optimizers"
          )
  
      if fused and not torch.jit.is_scripting():
          func = _fused_adam
      elif foreach and not torch.jit.is_scripting():
          func = _multi_tensor_adam
      else:
          func = _single_tensor_adam
  
      func(
          params,
          grads,
          exp_avgs,
          exp_avg_sqs,
          max_exp_avg_sqs,
          state_steps,
          amsgrad=amsgrad,
          has_complex=has_complex,
          beta1=beta1,
          beta2=beta2,
          lr=lr,
          weight_decay=weight_decay,
          eps=eps,
          maximize=maximize,
          capturable=capturable,
          differentiable=differentiable,
          grad_scale=grad_scale,
          found_inf=found_inf,
      )
  
file_path: pytorch/torch/optim/adam.py
imports: from typing import List, Optional, Union, Tuple
  import torch
  from torch import Tensor
  from .optimizer import Optimizer, ParamsT, _use_grad_for_differentiable, _get_value, _stack_if_compiling, _dispatch_sqrt, _default_to_fused_or_foreach, _get_scalar_dtype, _capturable_doc, _differentiable_doc, _foreach_doc, _fused_doc, _maximize_doc, _view_as_real
  from torch.utils._foreach_utils import _get_fused_kernels_supported_devices
label_desc: Use image node_id 1 for calling a global function with example usage: adam(params, grads, exp_avgs, exp_avg_sqs, max_exp_avg_sqs, state_steps, foreach, capturable, differentiable, fused, grad_scale, found_inf, has_complex) without return types