code: def _simple_reduce(
      per_replica_value, reduce_to_device, accumulation_fn, reduce_op
  ):
      # pylint: disable=g-missing-docstring
      all_values = per_replica_value.values
      if not all_values:
          raise ValueError("`per_replica_value` must be non-empty")
      count = len(all_values)
  
      if count == 1 and all_values[0].device == reduce_to_device:
          return all_values[0]
  
      with ops.device(reduce_to_device):
          with context.device_policy(context.DEVICE_PLACEMENT_SILENT):
              reduced = cross_device_utils.aggregate_tensors_or_indexed_slices(
                  all_values, accumulation_fn
              )
              if reduce_op == reduce_util.ReduceOp.MEAN:
                  reduced = cross_device_utils.divide_by_n_tensors_or_indexed_slices(
                      reduced, count
                  )
              elif reduce_op != reduce_util.ReduceOp.SUM:
                  raise ValueError(
                      "`reduce_op` must be Reduce.SUM or Reduce.MEAN."
                  )
      return reduced
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import enum
  import six
  from tensorflow.python.client import device_lib
  from tensorflow.python.distribute import cross_device_utils
  from tensorflow.python.distribute import device_util
  from tensorflow.python.distribute import reduce_util
  from tensorflow.python.distribute import values
  from tensorflow.python.eager import context
  from tensorflow.python.framework import kernels
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.util.tf_export import tf_export
  from tensorflow.tools.docs import doc_controls
  import tensorflow
  from tensorflow.python.distribute.cross_device_ops import CollectiveAllReduce
  import tensorflow.python.distribute.cross_device_ops
  from byteps.tensorflow.ops import broadcast, _push_pull
  from byteps.tensorflow import local_rank, size
label_desc: Use image node_id 6 for calling a global function with example usage: _simple_reduce(per_replica_value, reduce_to_device, accumulation_fn, reduce_op) and returns: reduced, all_values