code: def check_two_all_gather_S01R(device_mesh, rank):
      tensor_width = 8
      tensor_to_check = (
          torch.arange(int(tensor_width * tensor_width))
          .reshape((tensor_width, tensor_width))
          .cuda()
      )
  
      rank_stride = tensor_width // 8
      tensor_to_comm = (
          tensor_to_check[rank : rank + rank_stride, :]
          .contiguous()
          .cuda()
      )
  
      dim_partition_dict = {0: [0, 1]}
  
      # DistSpec:
      #     shard_sequence: S01, R
      #     device_mesh_shape: (2, 4)
      sharding_spec = ShardingSpec(
          device_mesh,
          tensor_to_check.shape,
          dim_partition_dict=dim_partition_dict,
      )
  
      # CommSpec:(comm_pattern:allgather, gather_dim:0, logical_process_axis:0)
      comm_spec = CommSpec(
          CollectiveCommPattern.GATHER_FWD_SPLIT_BWD,
          sharding_spec,
          gather_dim=0,
          logical_process_axis=1,
      )
  
      tensor_to_comm = comm_spec.covert_spec_to_action(tensor_to_comm)
  
      dim_partition_dict = {0: [0]}
  
      # DistSpec:
      #     shard_sequence: S1, R
      #     device_mesh_shape: (2, 4)
      sharding_spec = ShardingSpec(
          device_mesh,
          tensor_to_check.shape,
          dim_partition_dict=dim_partition_dict,
      )
  
      # CommSpec:(comm_pattern:allgather, gather_dim:0, logical_process_axis:1)
      comm_spec = CommSpec(
          CollectiveCommPattern.GATHER_FWD_SPLIT_BWD,
          sharding_spec,
          gather_dim=0,
          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_mix_gather.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.tensor.utils import mix_gather_simulator
  from colossalai.testing import rerun_if_address_is_in_use, spawn
label_desc: Use image node_id 6 for calling a global function with example usage: check_two_all_gather_S01R(device_mesh, rank) without return types