code: def _testIndexedSlicesAllReduce(
      self, devices, cross_device_ops_instance, reduce_op, batch_reduce
  ):
      with self.cached_session() as sess:
          dense_shape = [5, 2]
          t0 = _make_indexed_slices(
              [[1.0, 2.0]], [1], dense_shape, devices[0]
          )
          t1 = _make_indexed_slices(
              [[3.0, 4.0], [5.0, 6.0]], [1, 3], dense_shape, devices[1]
          )
          per_replica = value_lib.PerReplica((t0, t1))
  
          if batch_reduce:
              result = cross_device_ops_instance.batch_reduce(
                  reduce_op, [(per_replica, per_replica)]
              )
          else:
              result = cross_device_ops_instance.reduce(
                  reduce_op, per_replica, per_replica
              )
  
          total_indices_with_dups = [1, 1, 3]
          total_indices_without_dups = [1, 3]
  
          if reduce_op == reduce_util.ReduceOp.SUM:
              total_values_with_dups = [
                  [1.0, 2.0],
                  [3.0, 4.0],
                  [5.0, 6.0],
              ]
              total_values_without_dups = [[4.0, 6.0], [5.0, 6.0]]
          else:
              assert reduce_op == reduce_util.ReduceOp.MEAN
              total_values_with_dups = [
                  [0.5, 1.0],
                  [1.5, 2.0],
                  [2.5, 3.0],
              ]
              total_values_without_dups = [[2.0, 3.0], [2.5, 3.0]]
  
          total_mirrored_with_dups = _make_mirrored_indexed_slices(
              devices,
              total_values_with_dups,
              total_indices_with_dups,
              dense_shape,
          )
          total_mirrored_without_dups = _make_mirrored_indexed_slices(
              devices,
              total_values_without_dups,
              total_indices_without_dups,
              dense_shape,
          )
  
          # Test that the result is semantically equal to both the concatenated
          # IndexedSlices, as well as when the duplicate indices are summed up.
          if batch_reduce:
              total_mirrored_with_dups = [total_mirrored_with_dups]
              total_mirrored_without_dups = [
                  total_mirrored_without_dups
              ]
  
          self._assert_mirrored_equal(
              total_mirrored_with_dups, result, sess
          )
          self._assert_mirrored_equal(
              total_mirrored_without_dups, result, sess
          )
  
imports: import itertools
  import os
  import threading
  import time
  from absl.testing import parameterized
  import numpy
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.distribute import cluster_resolver
  from tensorflow.python.distribute import collective_all_reduce_strategy
  from tensorflow.python.distribute import collective_util
  from tensorflow.python.distribute import combinations
  from tensorflow.python.distribute import cross_device_ops
  from tensorflow.python.distribute import cross_device_utils
  from tensorflow.python.distribute import device_util
  from tensorflow.python.distribute import distribute_utils
  from tensorflow.python.distribute import multi_worker_test_base
  from tensorflow.python.distribute import multi_worker_util
  from tensorflow.python.distribute import reduce_util
  from tensorflow.python.distribute import strategy_combinations
  from tensorflow.python.distribute import values
  from tensorflow.python.eager import context
  from tensorflow.python.eager import test
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import indexed_slices
  from tensorflow.python.framework import kernels
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import collective_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variables
label_desc: Use image node_id 4 for calling the CrossDeviceOpsTestBase obj's underlying member method code with example usage: obj._testIndexedSlicesAllReduce(devices, cross_device_ops_instance, reduce_op, batch_reduce) without return types