code: def check_all_gather(device_mesh, rank):
      # tensor to comm
      if rank in (0, 2):
          sharded_tensor_to_comm = torch.ones(2, 2).cuda()
      else:
          sharded_tensor_to_comm = torch.zeros(2, 2).cuda()
  
      # tensor to check
      tensor_to_check = torch.cat(
          (torch.ones(2, 2), torch.zeros(2, 2)), 1
      ).cuda()
  
      # test all gather
      dim_partition_dict = {1: [1]}
  
      # DistSpec:
      #     shard_sequence: R,S1
      #     device_mesh_shape: (2, 2)
      sharding_spec = ShardingSpec(
          device_mesh,
          tensor_to_check.shape,
          dim_partition_dict=dim_partition_dict,
      )
  
      # CommSpec:(comm_pattern:allgather, gather_dim:1, logical_process_axis:1)
      comm_spec = CommSpec(
          CollectiveCommPattern.GATHER_FWD_SPLIT_BWD,
          sharding_spec,
          gather_dim=1,
          logical_process_axis=1,
      )
      sharded_tensor_to_comm = (
          sharded_tensor_to_comm
      ) = comm_spec.covert_spec_to_action(sharded_tensor_to_comm)
  
      assert sharded_tensor_to_comm.equal(tensor_to_check)
  
file_path: ColossalAI/tests/test_tensor/test_comm_spec_apply.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.shape_consistency import CollectiveCommPattern, CommSpec
  from colossalai.tensor.sharding_spec import ShardingSpec
  from colossalai.testing import rerun_if_address_is_in_use, spawn
label_desc: Use image node_id 1 for calling a global function with example usage: check_all_gather(device_mesh, rank) without return types