code: def test_reducescatter_torch_numpy(
      ray_start_distributed_2_nodes, backend
  ):
      world_size = 8
      shape = [10, 10]
      actors, _ = create_collective_workers(world_size, backend=backend)
  
      # tensor is pytorch, list is numpy
      for i, a in enumerate(actors):
          t = torch.ones(shape, dtype=torch.float32) * (i + 1)
          ray.wait([a.set_buffer.remote(t)])
          list_buffer = [
              np.ones(shape, dtype=np.float32)
              for _ in range(world_size)
          ]
          ray.wait([a.set_list_buffer.remote(list_buffer)])
      results = ray.get([a.do_reducescatter.remote() for a in actors])
      for i in range(world_size):
          assert (
              results[i]
              == torch.ones(shape, dtype=torch.float32) * world_size
          ).all()
  
      # tensor is numpy, list is pytorch
      for i, a in enumerate(actors):
          t = np.ones(shape, dtype=np.float32) * (i + 1)
          ray.wait([a.set_buffer.remote(t)])
          list_buffer = [
              torch.ones(shape, dtype=torch.float32)
              for _ in range(world_size)
          ]
          ray.wait([a.set_list_buffer.remote(list_buffer)])
      results = ray.get([a.do_reducescatter.remote() for a in actors])
      for i in range(world_size):
          assert (
              results[i]
              == np.ones(shape, dtype=np.float32) * world_size
          ).all()
  
      # some tensors in the list are pytorch, some are numpy
      for i, a in enumerate(actors):
          if i % 2 == 0:
              t = torch.ones(shape, dtype=torch.float32) * (i + 1)
          else:
              t = np.ones(shape, dtype=np.float32) * (i + 1)
          ray.wait([a.set_buffer.remote(t)])
          list_buffer = []
          for j in range(world_size):
              if j % 2 == 0:
                  list_buffer.append(
                      torch.ones(shape, dtype=torch.float32)
                  )
              else:
                  list_buffer.append(np.ones(shape, dtype=np.float32))
          ray.wait([a.set_list_buffer.remote(list_buffer)])
      results = ray.get([a.do_reducescatter.remote() for a in actors])
      for i in range(world_size):
          if i % 2 == 0:
              assert (
                  results[i]
                  == torch.ones(shape, dtype=torch.float32) * world_size
              ).all()
          else:
              assert (
                  results[i]
                  == np.ones(shape, dtype=np.float32) * world_size
              ).all()
  
      # mixed case
      for i, a in enumerate(actors):
          if i % 2 == 0:
              t = torch.ones(shape, dtype=torch.float32) * (i + 1)
          else:
              t = np.ones(shape, dtype=np.float32) * (i + 1)
          ray.wait([a.set_buffer.remote(t)])
          list_buffer = []
          for j in range(world_size):
              if j % 2 == 0:
                  list_buffer.append(np.ones(shape, dtype=np.float32))
              else:
                  list_buffer.append(
                      torch.ones(shape, dtype=torch.float32)
                  )
          ray.wait([a.set_list_buffer.remote(list_buffer)])
      results = ray.get([a.do_reducescatter.remote() for a in actors])
      for i in range(world_size):
          if i % 2 == 0:
              assert (
                  results[i]
                  == torch.ones(shape, dtype=torch.float32) * world_size
              ).all()
          else:
              assert (
                  results[i]
                  == np.ones(shape, dtype=np.float32) * world_size
              ).all()
  
file_path: ray/python/ray/util/collective/tests/distributed_cpu_tests/test_distributed_reducescatter.py
imports: import pytest
  import ray
  import numpy
  import torch
  from ray.util.collective.types import Backend
  from ray.util.collective.tests.cpu_util import create_collective_workers, init_tensors_for_gather_scatter
label_desc: Use image node_id 3 for calling a global function with example usage: test_reducescatter_torch_numpy(ray_start_distributed_2_nodes, backend) without return types