code: def testComputeAverageLossInvalidRank(self):
      per_example_loss = constant_op.constant(2.0)
  
      # Static rank
      with self.assertRaisesRegex(
          ValueError,
          "Invalid value passed for `per_example_loss`. "
          "Expected a tensor with at least rank 1.",
      ):
          nn_impl_distribute.compute_average_loss(per_example_loss)
  
      with context.graph_mode():
          # Dynamic rank
          per_example_loss = array_ops.placeholder(dtype=dtypes.float32)
          loss = nn_impl_distribute.compute_average_loss(
              per_example_loss
          )
  
          with self.cached_session() as sess:
              with self.assertRaisesRegex(
                  errors.InvalidArgumentError,
                  "Invalid value passed for `per_example_loss`. "
                  "Expected a tensor with at least rank 1.",
              ):
                  sess.run(loss, {per_example_loss: 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 12 for calling the LossUtilitiesTest obj's underlying member method code with example usage: obj.testComputeAverageLossInvalidRank() without return types