code: def _testAllReduce(self, num_workers, num_gpus, shape, build_f):
      # Use local CPU as device for all inputs.
      num_devices = num_workers * num_gpus
      dev_list = [
          "/replica:0/task:0/device:CPU:0" for _ in range(num_devices)
      ]
      with self.cached_session():
          input_tensors = self._buildInitialVars(shape, dev_list)
          un_op = lambda x: math_ops.div(
              x,
              constant_op.constant(
                  num_devices, dtype=types_pb2.DT_FLOAT
              ),
          )
          simple_sum = math_ops.add_n(input_tensors)
          simple_sum.op.run()
          output_tensors = build_f(input_tensors, un_op)
          sum_reduced = math_ops.add_n(output_tensors)
          sum_reduced.op.run()
          self.assertAllClose(sum_reduced, self.evaluate(simple_sum))
  
imports: import time
  import numpy
  from tensorflow.core.framework import types_pb2
  from tensorflow.python.distribute.v1 import all_reduce
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import state_ops
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 7 for calling the AllReduceTest obj's underlying member method code with example usage: obj._testAllReduce(num_workers, num_gpus, shape, build_f) without return types