code: def test_allreduce_multiple_group(
      ray_start_distributed_2_nodes_4_gpus, backend="nccl", num_groups=5
  ):
      world_size = 4
      actors, _ = create_collective_workers(world_size)
      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]
              == cp.ones((10,), dtype=cp.float32)
              * (world_size ** (i + 1))
          ).all()
  
file_path: ray/python/ray/util/collective/tests/distributed_gpu_tests/test_distributed_allreduce.py
imports: import pytest
  import ray
  from ray.util.collective.types import ReduceOp
  import cupy
  import torch
  from ray.util.collective.tests.util import create_collective_workers
label_desc: Use image node_id 4 for calling a global function with example usage: test_allreduce_multiple_group(ray_start_distributed_2_nodes_4_gpus, backend, num_groups) without return types