class_docstr: Gradient descent (with momentum) optimizer.
  
  Update rule for parameter `w` with gradient `g` when `momentum` is 0:
  
  ```python
  w = w - learning_rate * g
  ```
  
  Update rule when `momentum` is larger than 0:
  
  ```python
  velocity = momentum * velocity - learning_rate * g
  w = w + velocity
  ```
  
  When `nesterov=True`, this rule becomes:
  
  ```python
  velocity = momentum * velocity - learning_rate * g
  w = w + momentum * velocity - learning_rate * g
  ```
  
  Args:
      learning_rate: A float, a
          `keras.optimizers.schedules.LearningRateSchedule` instance, or
          a callable that takes no arguments and returns the actual value to
          use. The learning rate. Defaults to `0.01`.
      momentum: float hyperparameter >= 0 that accelerates gradient descent in
          the relevant direction and dampens oscillations. 0 is vanilla
          gradient descent. Defaults to `0.0`.
      nesterov: boolean. Whether to apply Nesterov momentum.
          Defaults to `False`.
      {{base_optimizer_keyword_args}}
docstr: Initialize optimizer variables.
  
  SGD optimizer has one variable `momentums`, only set if `self.momentum`
  is not 0.
  
  Args:
    var_list: list of model variables to build SGD variables on.
docstr_tok: ["Initialize","optimizer","variables",".","SGD","optimizer","has","one","variable","`","momentums","`",",","only","set","if","`","self.momentum","`","is","not","0",".","Args",":","var_list",":","list","of","model","variables","to","build","SGD","variables","on","."]
code: def build(self, variables):
      """Initialize optimizer variables.
  
      SGD optimizer has one variable `momentums`, only set if `self.momentum`
      is not 0.
  
      Args:
        var_list: list of model variables to build SGD variables on.
      """
      if self.built:
          return
      super().build(variables)
      self.momentums = []
      if self.momentum != 0:
          for variable in variables:
              self.momentums.append(
                  self.add_variable_from_reference(
                      reference_variable=variable, name="momentum"
                  )
              )
  
file_path: keras/keras/optimizers/sgd.py
imports: from keras import ops
  from keras.api_export import keras_export
  from keras.optimizers import optimizer
label_desc: Use image node_id 2 for calling the SGD obj's underlying member method code with example usage: obj.build(variables) without return types