code: def testComputeAverageLossSampleWeights(self, distribution):
      with distribution.scope():
          # Scalar sample weight
          per_replica_losses = distribution.run(
              nn_impl_distribute.compute_average_loss,
              args=([2.0, 4.0, 6.0],),
              kwargs={"sample_weight": 2},
          )
          loss = distribution.reduce(
              "SUM", per_replica_losses, axis=None
          )
          self.assertAllClose(
              self.evaluate(loss), (2.0 + 4.0 + 6.0) * 2.0 / 3
          )
  
          # Per example sample weight
          per_replica_losses = distribution.run(
              nn_impl_distribute.compute_average_loss,
              args=([2.0, 4.0, 6.0],),
              kwargs={"sample_weight": [0.3, 0.5, 0.2]},
          )
          loss = distribution.reduce(
              "SUM", per_replica_losses, axis=None
          )
          self.assertAllClose(
              self.evaluate(loss),
              (2.0 * 0.3 + 4.0 * 0.5 + 6.0 * 0.2) / 3,
          )
  
          # Time-step sample weight
          per_replica_losses = distribution.run(
              nn_impl_distribute.compute_average_loss,
              args=([[2.0, 0.5], [4.0, 1.0]],),
              kwargs={"sample_weight": [[0.3, 0.7], [0.2, 0.8]]},
          )
          loss = distribution.reduce(
              "SUM", per_replica_losses, axis=None
          )
          self.assertAllClose(
              self.evaluate(loss),
              (2.0 * 0.3 + 0.5 * 0.7 + 4.0 * 0.2 + 1.0 * 0.8) / 2,
          )
  
imports: from absl.testing import parameterized
  from tensorflow.python.distribute import combinations
  from tensorflow.python.distribute import strategy_combinations
  from tensorflow.python.eager import context
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import nn_impl_distribute
  from tensorflow.python.platform import test
label_desc: Use image node_id 8 for calling the LossUtilitiesTest obj's underlying member method code with example usage: obj.testComputeAverageLossSampleWeights(distribution) without return types