code: def testDynamicUpdate(self, strategy_fn):
      with strategy_fn().scope() as strategy:
          var = variables.Variable([1.0, 2.0])
          opt = gradient_descent.GradientDescentOptimizer(1.0)
          loss_scale = loss_scale_module.DynamicLossScale(
              initial_loss_scale=2, increment_period=1, multiplier=2
          )
          opt = loss_scale_optimizer.MixedPrecisionLossScaleOptimizer(
              opt, loss_scale
          )
  
          # Test optimizer with finite gradients
          loss = lambda: var * 2.0 / 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)
          # Gradient is 2, so variable will have 2 subtracted from it
          self.assertAllClose([-1.0, 0.0], self.evaluate(var))
          # Loss scale has doubled from 2 to 4
          self.assertEqual(4.0, self.evaluate(opt._loss_scale()))
  
          # Test optimizer with NaN gradients
          loss = lambda: var * float("NaN")
          run_fn = lambda: opt.minimize(loss, var_list=[var])
          run_op = strategy.experimental_run(run_fn)
          self._run_if_in_graph_mode(run_op)
          # Variable should not change from before, due to NaN gradients.
          self.assertAllClose(self.evaluate(var), [-1.0, 0.0])
          # Loss scale should half due to NaN gradients.
          self.assertEqual(2.0, self.evaluate(opt._loss_scale()))
  
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 6 for calling the MixedPrecisionLossScaleOptimizerTest obj's underlying member method code with example usage: obj.testDynamicUpdate(strategy_fn) without return types