code: def check_all_reduce_fwd(process_groups_dict, rank):
      # tensor to comm
      tensor_to_comm = torch.ones(2, 2).cuda() * rank
  
      # reduce through logical process axis 0
      # tensor to check
      if rank in (0, 2):
          # tensor([[2., 2.],
          #         [2., 2.]])
          tensor_to_check = torch.tensor(
              [[2, 2], [2, 2]], dtype=tensor_to_comm.dtype
          ).cuda()
      if rank in (1, 3):
          # tensor([[4., 4.],
          #         [4., 4.]])
          tensor_to_check = torch.tensor(
              [[4, 4], [4, 4]], dtype=tensor_to_comm.dtype
          ).cuda()
  
      comm_spec = CommSpec(
          CollectiveCommPattern.ALLREDUCE_FWD_IDENTITY_BWD,
          process_groups_dict,
          logical_process_axis=0,
      )
      tensor_to_comm = comm_spec.covert_spec_to_action(tensor_to_comm)
  
      assert tensor_to_comm.equal(tensor_to_check)
  
file_path: ColossalAI/tests/test_tensor/test_dtensor/test_comm_spec.py
imports: import pytest
  import torch
  import torch.distributed
  from colossalai.device.device_mesh import DeviceMesh
  from colossalai.initialize import launch
  from colossalai.logging import disable_existing_loggers
  from colossalai.tensor.d_tensor.comm_spec import CollectiveCommPattern, CommSpec
  from colossalai.testing import rerun_if_address_is_in_use, spawn
label_desc: Use image node_id 4 for calling a global function with example usage: check_all_reduce_fwd(process_groups_dict, rank) without return types