code: def test_allreduce_multiple_group(
      ray_start_single_node, backend, num_groups=5
  ):
      world_size = 2
      actors, _ = create_collective_workers(world_size, backend=backend)
      for group_name in range(1, num_groups):
          ray.get(
              [
                  actor.init_group.remote(
                      world_size, i, backend, str(group_name)
                  )
                  for i, actor in enumerate(actors)
              ]
          )
      for i in range(num_groups):
          group_name = "default" if i == 0 else str(i)
          results = ray.get(
              [a.do_allreduce.remote(group_name) for a in actors]
          )
          assert (
              results[0]
              == np.ones((10,), dtype=np.float32)
              * (world_size ** (i + 1))
          ).all()
  
file_path: ray/python/ray/util/collective/tests/single_node_cpu_tests/test_allreduce.py
imports: import numpy
  import pytest
  import ray
  import torch
  from ray.util.collective.tests.cpu_util import create_collective_workers
  from ray.util.collective.types import Backend, ReduceOp
label_desc: Use image node_id 4 for calling a global function with example usage: test_allreduce_multiple_group(ray_start_single_node, backend, num_groups) without return types