class_docstr: SGD with Momentum module.
  
  Attributes:
    learning_rate: Learning rate.
    momentum: Momentum scalar.
    use_nesterov: `True` if using Nesterov momentum.
    accumulated_momentum: Accumulated momentum for each parameter.
class_docstr_tok: ["SGD","with","Momentum","module",".","Attributes",":","learning_rate",":","Learning","rate",".","momentum",":","Momentum","scalar",".","use_nesterov",":","`","True","`","if","using","Nesterov","momentum",".","accumulated_momentum",":","Accumulated","momentum","for","each","parameter","."]
docstr: Applies updates to parameters.
  
  By default it applies the momentum update rule for each update, parameter
  pair:
  
      accum_t <- momentum * accum_{t-1} + update
      parameter <- parameter - learning_rate * accum_t
  
  And when using Nesterov momentum (`use_nesterov=True`) it applies:
  
      accum_t <- momentum * accum_{t-1} + update
      parameter <- parameter - (learning_rate * update +
      learning_rate * momentum * accum_t)
  
  Args:
    updates: A list of updates to apply to parameters. Updates are often
      gradients as returned by `tf.GradientTape.gradient`.
    parameters: A list of parameters. A parameter is a `tf.Variable`.
  
  Raises:
    ValueError: If `updates` and `parameters` are empty, have different
      lengths, or have inconsistent types.
docstr_tok: ["Applies","updates","to","parameters",".","By","default","it","applies","the","momentum","update","rule","for","each","update",",","parameter","pair",":","accum_t","<","-","momentum","*","accum_","{","t-1","}","+","update","parameter","<","-","parameter","-","learning_rate","*","accum_t","And","when","using","Nesterov","momentum","(","`","use_nesterov=True","`",")","it","applies",":","accum_t","<","-","momentum","*","accum_","{","t-1","}","+","update","parameter","<","-","parameter","-","(","learning_rate","*","update","+","learning_rate","*","momentum","*","accum_t",")","Args",":","updates",":","A","list","of","updates","to","apply","to","parameters",".","Updates","are","often","gradients","as","returned","by","`","tf.GradientTape.gradient","`",".","parameters",":","A","list","of","parameters",".","A","parameter","is","a","`","tf.Variable","`",".","Raises",":","ValueError",":","If","`","updates","`","and","`","parameters","`","are","empty",",","have","different","lengths",",","or","have","inconsistent","types","."]
code: def apply(
      self,
      updates: Sequence[types.ParameterUpdate],
      parameters: Sequence[tf.Variable],
  ):
      """Applies updates to parameters.
  
      By default it applies the momentum update rule for each update, parameter
      pair:
  
          accum_t <- momentum * accum_{t-1} + update
          parameter <- parameter - learning_rate * accum_t
  
      And when using Nesterov momentum (`use_nesterov=True`) it applies:
  
          accum_t <- momentum * accum_{t-1} + update
          parameter <- parameter - (learning_rate * update +
          learning_rate * momentum * accum_t)
  
      Args:
        updates: A list of updates to apply to parameters. Updates are often
          gradients as returned by `tf.GradientTape.gradient`.
        parameters: A list of parameters. A parameter is a `tf.Variable`.
  
      Raises:
        ValueError: If `updates` and `parameters` are empty, have different
          lengths, or have inconsistent types.
      """
      optimizer_utils.check_distribution_strategy()
      optimizer_utils.check_updates_parameters(updates, parameters)
      self._initialize(parameters)
      for update, param, momentum_var in zip(
          updates, parameters, self.accumulated_momentum
      ):
          if update is None:
              continue
  
          optimizer_utils.check_same_dtype(update, param)
          learning_rate = tf.cast(self.learning_rate, update.dtype)
          mu = tf.cast(self.momentum, update.dtype)
  
          if isinstance(update, tf.IndexedSlices):
              # Sparse read our state.
              (
                  update,
                  indices,
              ) = optimizer_utils.deduplicate_indexed_slices(update)
              momentum = momentum_var.sparse_read(indices)
  
              # Compute and apply a sparse update to our parameter and state.
              update, momentum = momentum_update(
                  update, learning_rate, mu, momentum, self.use_nesterov
              )
              momentum_var.scatter_update(
                  tf.IndexedSlices(momentum, indices)
              )
              param.scatter_sub(tf.IndexedSlices(update, indices))
  
          else:
              # Compute and apply a dense update.
              update, momentum = momentum_update(
                  update,
                  learning_rate,
                  mu,
                  momentum_var,
                  self.use_nesterov,
              )
              momentum_var.assign(momentum)
              param.assign_sub(update)
  
file_path: sonnet/sonnet/src/optimizers/momentum.py
imports: from typing import Optional, Sequence, Union
  from sonnet.src import base
  from sonnet.src import once
  from sonnet.src import types
  from sonnet.src import utils
  from sonnet.src.optimizers import optimizer_utils
  import tensorflow
label_desc: Use image node_id 3 for calling the Momentum obj's underlying member method code with example usage: obj.apply(updates, parameters) without return types