code: def testDynamicLossScaleWithSlots(self, strategy_fn):
      with strategy_fn().scope() as strategy:
          var = variables.Variable([1.0, 2.0])
          # An SGD optimizer with momentum has slot variables.
          opt = momentum.MomentumOptimizer(1.0, momentum=1.0)
          initial_loss_scale = 2.0
          loss_scale = loss_scale_module.DynamicLossScale(
              initial_loss_scale=initial_loss_scale,
              increment_period=1,
              multiplier=4,
          )
          opt = loss_scale_optimizer.MixedPrecisionLossScaleOptimizer(
              opt, loss_scale
          )
          loss = lambda: var / strategy.num_replicas_in_sync
          run_fn = lambda: opt.minimize(loss, var_list=[var])
          run_op = strategy.experimental_run(run_fn)
          self.evaluate(variables.global_variables_initializer())
          self._run_if_in_graph_mode(run_op)
          # The momentum accumulator starts at 0 and the gradient is 1. The
          # accumulator is incremented by the gradient, so it is now 1. Then the
          # variable is subtracted by the accumulator, so the variable is subtracted
          # by 1.
          self.assertAllClose([0.0, 1.0], self.evaluate(var))
          self.assertEqual(
              self.evaluate(opt._loss_scale()), initial_loss_scale * 4
          )
  
          run_op = strategy.experimental_run(run_fn)
          self._run_if_in_graph_mode(run_op)
          # The momentum accumulator was 1 before this step and the gradient is 1.
          # The accumulator is incremented by the gradient, so it is now 2. Then the
          # variable is subtracted by the accumulator, so the variable is subtracted
          # by 2.
          self.assertAllClose([-2.0, -1.0], self.evaluate(var))
          self.assertEqual(
              self.evaluate(opt._loss_scale()), initial_loss_scale * 16
          )
  
imports: import os
  from absl.testing import parameterized
  from tensorflow.python.checkpoint import checkpoint
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.distribute import mirrored_strategy
  from tensorflow.python.eager import context
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_conversion
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import check_ops
  from tensorflow.python.ops import custom_gradient
  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 gradient_descent
  from tensorflow.python.training import momentum
  from tensorflow.python.training.experimental import loss_scale
  from tensorflow.python.training.experimental import loss_scale_optimizer
label_desc: Use image node_id 7 for calling the MixedPrecisionLossScaleOptimizerTest obj's underlying member method code with example usage: obj.testDynamicLossScaleWithSlots(strategy_fn) without return types