class_docstr: Optimizer that implements the LAMBOptimizer as tf.train.Optimizer.
code: def _apply_sparse_shared(self, grad, var, indices, scatter_add):
      beta1_power, beta2_power = self._get_beta_accumulators()
      beta1_power = math_ops.cast(beta1_power, var.dtype.base_dtype)
      beta2_power = math_ops.cast(beta2_power, var.dtype.base_dtype)
      lr_t = math_ops.cast(self._lr_t, var.dtype.base_dtype)
      beta1_t = math_ops.cast(self._beta1_t, var.dtype.base_dtype)
      beta2_t = math_ops.cast(self._beta2_t, var.dtype.base_dtype)
      epsilon_t = math_ops.cast(self._epsilon_t, var.dtype.base_dtype)
      weight_decay_rate_t = math_ops.cast(
          self._weight_decay_rate_t, var.dtype.base_dtype
      )
      # m_t = beta1 * m + (1 - beta1) * g_t
      m = self.get_slot(var, "m")
      m_scaled_g_values = grad * (1 - beta1_t)
      m_t = state_ops.assign(
          m, m * beta1_t, use_locking=self._use_locking
      )
      with ops.control_dependencies([m_t]):
          m_t = scatter_add(m, indices, m_scaled_g_values)
      # v_t = beta2 * v + (1 - beta2) * (g_t * g_t)
      v = self.get_slot(var, "v")
      v_scaled_g_values = (grad * grad) * (1 - beta2_t)
      v_t = state_ops.assign(
          v, v * beta2_t, use_locking=self._use_locking
      )
      with ops.control_dependencies([v_t]):
          v_t = scatter_add(v, indices, v_scaled_g_values)
  
      # ==== The following is with m_t_hat and v_t_hat
      m_t_hat = m_t / (1.0 - beta1_power)
      v_t_hat = v_t / (1.0 - beta2_power)
  
      v_sqrt = math_ops.sqrt(v_t_hat)
      update = m_t_hat / (v_sqrt + epsilon_t)
  
      # ==== The following is the original LAMBOptimizer implementation
      # v_sqrt = math_ops.sqrt(v_t_hat)
      # update = m_t / (v_sqrt + epsilon_t)
  
      var_name = self._get_variable_name(var.name)
      if self._do_use_weight_decay(var_name):
          update += weight_decay_rate_t * var
  
      ratio = 1.0
      if self._do_layer_adaptation(var_name):
          w_norm = linalg_ops.norm(var, ord=2)
          g_norm = linalg_ops.norm(update, ord=2)
          ratio = array_ops.where(
              math_ops.greater(w_norm, 0),
              array_ops.where(
                  math_ops.greater(g_norm, 0), (w_norm / g_norm), 1.0
              ),
              1.0,
          )
      var_update = state_ops.assign_sub(
          var, ratio * lr_t * update, use_locking=self._use_locking
      )
      return control_flow_ops.group(*[var_update, m_t, v_t])
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import re
  import tensorflow.compat.v1
  from tensorflow.python.eager import context
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import linalg_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import state_ops
  from tensorflow.python.training import optimizer
label_desc: Use image node_id 8 for calling the LAMBOptimizer obj's underlying member method code with example usage: obj._apply_sparse_shared(grad, var, indices, scatter_add) and returns: control_flow_ops