code: def check_comm(rank, world_size, port):
      disable_existing_loggers()
      launch(
          config={},
          rank=rank,
          world_size=world_size,
          host="localhost",
          port=port,
          backend="nccl",
      )
  
      physical_mesh_id = torch.arange(0, 4)
      assert rank == dist.get_rank()
  
      mesh_shape = (2, 2)
      # [[0, 1,
      #  [2, 3]]
      device_mesh = DeviceMesh(
          physical_mesh_id, mesh_shape, init_process_group=True
      )
      # test all gather
      check_all_gather(device_mesh, rank)
  
      # test shard
      check_shard(device_mesh, rank)
  
      # test all to all
      check_all_to_all(device_mesh, rank)
  
      # test all reduce
      check_all_reduce_fwd(device_mesh, rank)
      check_all_reduce_bwd(device_mesh, rank)
  
      # test all reduce in 1D flatten device mesh
      check_all_reduce_in_flatten_device_mesh(device_mesh, rank)
  
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 7 for calling a global function with example usage: check_comm(rank, world_size, port) without return types