class_docstr: Tests for ops in horovod.tensorflow using multiple process sets.
class_docstr_tok: ["Tests","for","ops","in","horovod.tensorflow","using","multiple","process","sets","."]
docstr: Test on CPU that the reducescatter correctly sums or averages and scatters 1D, 2D, 3D tensors
  if restricted to non-global process sets.
code: def test_horovod_reducescatter_cpu_process_sets(self):
      """Test on CPU that the reducescatter correctly sums or averages and scatters 1D, 2D, 3D tensors
      if restricted to non-global process sets."""
      if hvd.ccl_built():
          self.skipTest(
              "Reducescatter is not supported yet with oneCCL operations."
          )
      if _is_mac and hvd.gloo_built() and not hvd.mpi_built():
          self.skipTest("ReducescatterGloo is not supported on macOS")
      rank = hvd.rank()
  
      if rank in self.even_ranks:
          this_set = self.even_set
      else:
          this_set = self.odd_set
      process_set_size = this_set.size()
      process_set_rank = this_set.rank()
  
      dtypes = self.filter_supported_types(
          [tf.int32, tf.int64, tf.float16, tf.float32, tf.float64]
      )
      dims = [1, 2, 3]
      for red_op, dtype, dim in itertools.product(
          [hvd.Sum, hvd.Average], dtypes, dims
      ):
          with tf.device("/cpu:0"):
              even_rank_tensor = self.random_uniform(
                  [process_set_size * 4] * dim, -100, 100, dtype=dtype
              )
              odd_rank_tensor = self.random_uniform(
                  [process_set_size * 4] * dim, -100, 100, dtype=dtype
              )
              if rank in self.even_ranks:
                  tensor = even_rank_tensor
              else:
                  tensor = odd_rank_tensor
              reduced = hvd.reducescatter(
                  tensor, op=red_op, process_set=this_set
              )
          if red_op == hvd.Sum:
              expected = tf.cast(
                  tensor[
                      process_set_rank * 4 : (process_set_rank + 1) * 4
                  ]
                  * process_set_size,
                  reduced.dtype,
              )
          elif red_op == hvd.Average:
              expected = tf.cast(
                  tensor[
                      process_set_rank * 4 : (process_set_rank + 1) * 4
                  ],
                  reduced.dtype,
              )
          max_difference = tf.reduce_max(tf.abs(reduced - expected))
  
          # Threshold for floating point equality depends on number of
          # ranks, since we're comparing against precise multiplication.
          if dtype == tf.float16:
              threshold = 0.5
          elif dtype in [tf.int32, tf.int64]:
              threshold = 0
          elif process_set_size < 10:
              threshold = 1e-4
          elif process_set_size < 15:
              threshold = 5e-4
          else:
              break
  
          diff = self.evaluate(max_difference)
          self.assertTrue(
              diff <= threshold,
              "hvd.reducescatter produces incorrect results",
          )
  
imports: from packaging import version
  import itertools
  import numpy
  import platform
  import tensorflow
  from horovod.tensorflow.util import _executing_eagerly
  import horovod.tensorflow
  from base_test_tensorflow import *
  from horovod.runner.common.util.env import get_env_rank_and_size
  from tensorflow.python.framework.test_util import run_all_in_graph_and_eager_modes
label_desc: Use image node_id 28 for calling the TensorFlowProcessSetsTests obj's underlying member method code with example usage: obj.test_horovod_reducescatter_cpu_process_sets() without return types