code: def testTensorLearningRateAndMomentum(self):
      for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
          # train.MomentumOptimizer is V1 only API.
          with ops.Graph().as_default(), self.cached_session():
              var0 = variables.Variable([1.0, 2.0], dtype=dtype)
              var1 = variables.Variable([3.0, 4.0], dtype=dtype)
              grads0 = constant_op.constant([0.1, 0.1], dtype=dtype)
              grads1 = constant_op.constant([0.01, 0.01], dtype=dtype)
              mom_opt = momentum_lib.MomentumOptimizer(
                  learning_rate=constant_op.constant(2.0),
                  momentum=constant_op.constant(0.9),
              )
              mom_update = mom_opt.apply_gradients(
                  zip([grads0, grads1], [var0, var1])
              )
              self.evaluate(variables.global_variables_initializer())
              # Check we have slots
              self.assertEqual(["momentum"], mom_opt.get_slot_names())
              slot0 = mom_opt.get_slot(var0, "momentum")
              self.assertEqual(slot0.get_shape(), var0.get_shape())
              self.assertFalse(slot0 in variables.trainable_variables())
              slot1 = mom_opt.get_slot(var1, "momentum")
              self.assertEqual(slot1.get_shape(), var1.get_shape())
              self.assertFalse(slot1 in variables.trainable_variables())
  
              # Fetch params to validate initial values
              self.assertAllClose([1.0, 2.0], self.evaluate(var0))
              self.assertAllClose([3.0, 4.0], self.evaluate(var1))
              # Step 1: the momentum accumulators where 0. So we should see a normal
              # update: v -= grad * learning_rate
              mom_update.run()
              # Check that the momentum accumulators have been updated.
              self.assertAllCloseAccordingToType(
                  np.array([0.1, 0.1]), self.evaluate(slot0)
              )
              self.assertAllCloseAccordingToType(
                  np.array([0.01, 0.01]), self.evaluate(slot1)
              )
              # Check that the parameters have been updated.
              self.assertAllCloseAccordingToType(
                  np.array([1.0 - (0.1 * 2.0), 2.0 - (0.1 * 2.0)]),
                  self.evaluate(var0),
              )
              self.assertAllCloseAccordingToType(
                  np.array([3.0 - (0.01 * 2.0), 4.0 - (0.01 * 2.0)]),
                  self.evaluate(var1),
              )
              # Step 2: the momentum accumulators contain the previous update.
              mom_update.run()
              # Check that the momentum accumulators have been updated.
              self.assertAllCloseAccordingToType(
                  np.array([(0.9 * 0.1 + 0.1), (0.9 * 0.1 + 0.1)]),
                  self.evaluate(slot0),
              )
              self.assertAllCloseAccordingToType(
                  np.array([(0.9 * 0.01 + 0.01), (0.9 * 0.01 + 0.01)]),
                  self.evaluate(slot1),
              )
              # Check that the parameters have been updated.
              self.assertAllCloseAccordingToType(
                  np.array(
                      [
                          1.0 - (0.1 * 2.0) - ((0.9 * 0.1 + 0.1) * 2.0),
                          2.0 - (0.1 * 2.0) - ((0.9 * 0.1 + 0.1) * 2.0),
                      ]
                  ),
                  self.evaluate(var0),
              )
              self.assertAllCloseAccordingToType(
                  np.array(
                      [
                          2.98 - ((0.9 * 0.01 + 0.01) * 2.0),
                          3.98 - ((0.9 * 0.01 + 0.01) * 2.0),
                      ]
                  ),
                  self.evaluate(var1),
              )
  
imports: import numpy
  from tensorflow.python.eager import context
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import indexed_slices
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import embedding_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
  from tensorflow.python.training import momentum
label_desc: Use image node_id 11 for calling the MomentumOptimizerTest obj's underlying member method code with example usage: obj.testTensorLearningRateAndMomentum() without return types