code: def sgd(
      params: List[Tensor],
      d_p_list: List[Tensor],
      momentum_buffer_list: List[Optional[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
      has_sparse_grad: bool = None,
      foreach: Optional[bool] = None,
      fused: Optional[bool] = None,
      grad_scale: Optional[Tensor] = None,
      found_inf: Optional[Tensor] = None,
      *,
      weight_decay: float,
      momentum: float,
      lr: float,
      dampening: float,
      nesterov: bool,
      maximize: bool,
  ):
      r"""Functional API that performs SGD algorithm computation.
  
      See :class:`~torch.optim.SGD` 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 foreach is None and fused is None:
          # why must we be explicit about an if statement for torch.jit.is_scripting here?
          # because JIT can't handle Optionals nor fancy conditionals when scripting
          if not torch.jit.is_scripting():
              fused, foreach = _default_to_fused_or_foreach(
                  params, differentiable=False, use_fused=False
              )
          else:
              foreach = False
              fused = False
      if foreach is None:
          foreach = False
      if fused is None:
          fused = False
  
      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 foreach and not torch.jit.is_scripting():
          func = _multi_tensor_sgd
      elif fused and not torch.jit.is_scripting():
          func = _fused_sgd
      else:
          func = _single_tensor_sgd
  
      func(
          params,
          d_p_list,
          momentum_buffer_list,
          weight_decay=weight_decay,
          momentum=momentum,
          lr=lr,
          dampening=dampening,
          nesterov=nesterov,
          has_sparse_grad=has_sparse_grad,
          maximize=maximize,
          grad_scale=grad_scale,
          found_inf=found_inf,
      )
  
file_path: pytorch/torch/optim/sgd.py
imports: import torch
  from torch import Tensor
  from .optimizer import Optimizer, _use_grad_for_differentiable, _default_to_fused_or_foreach, _differentiable_doc, _foreach_doc, _maximize_doc, _fused_doc
  from typing import List, Optional
label_desc: Use image node_id 1 for calling a global function with example usage: sgd(params, d_p_list, momentum_buffer_list, has_sparse_grad, foreach, fused, grad_scale, found_inf) without return types