code: def _test_distrib_all_reduce_group(device):
      if idist.get_world_size() > 1 and idist.backend() is not None:
          ranks = [0, 1]
          rank = idist.get_rank()
          t = torch.tensor([rank], device=device)
          bnd = idist.backend()
  
          group = idist.new_group(ranks)
          if bnd in ("horovod"):
              with pytest.raises(
                  NotImplementedError,
                  match=r"all_reduce with group for horovod is not implemented",
              ):
                  res = idist.all_reduce(t, group=group)
          else:
              res = idist.all_reduce(t, group=group)
              assert res == torch.tensor([sum(ranks)], device=device)
  
          t = torch.tensor([rank], device=device)
          if bnd in ("horovod"):
              with pytest.raises(
                  NotImplementedError,
                  match=r"all_reduce with group for horovod is not implemented",
              ):
                  res = idist.all_reduce(t, group=ranks)
          else:
              res = idist.all_reduce(t, group=ranks)
              assert res == torch.tensor([sum(ranks)], device=device)
  
          ranks = "abc"
  
          if bnd in ("nccl", "gloo", "mpi"):
              with pytest.raises(
                  ValueError,
                  match=r"Argument group should be list of int or ProcessGroup",
              ):
                  res = idist.all_reduce(t, group="abc")
          elif bnd in ("xla-tpu"):
              with pytest.raises(
                  ValueError,
                  match=r"Argument group should be list of int",
              ):
                  res = idist.all_reduce(t, group="abc")
          elif bnd in ("horovod"):
              with pytest.raises(
                  NotImplementedError,
                  match=r"all_reduce with group for horovod is not implemented",
              ):
                  res = idist.all_reduce(t, group="abc")
  
file_path: ignite/tests/ignite/distributed/utils/__init__.py
imports: import pytest
  import torch
  import torch.distributed
  import ignite.distributed
  from ignite.distributed.utils import sync
  from ignite.engine import Engine, Events
label_desc: Use image node_id 6 for calling a global function with example usage: _test_distrib_all_reduce_group(device) without return types