code: def check_AB():
      data_parallel_rank = (
          0
          if not gpc.is_initialized(ParallelMode.DATA)
          else gpc.get_local_rank(ParallelMode.DATA)
      )
      pipeline_parallel_rank = (
          0
          if not gpc.is_initialized(ParallelMode.PIPELINE)
          else gpc.get_local_rank(ParallelMode.PIPELINE)
      )
      pipeline_parallel_size = (
          1
          if not gpc.is_initialized(ParallelMode.PIPELINE)
          else gpc.get_world_size(ParallelMode.PIPELINE)
      )
      tensor_parallel_size = gpc.get_world_size(ParallelMode.TENSOR)
  
      dtype = torch.float
      j = gpc.get_local_rank(ParallelMode.PARALLEL_2D_ROW)
      i = gpc.get_local_rank(ParallelMode.PARALLEL_2D_COL)
  
      A_shape = (BATCH_SIZE, SEQ_LENGTH, HIDDEN_SIZE)
      A_master = torch.randn(
          A_shape, dtype=dtype, device=get_current_device()
      )
      torch.distributed.broadcast(A_master, src=0)
      A = torch.chunk(A_master, DEPTH, dim=0)[i]
      A = torch.chunk(A, DEPTH, dim=-1)[j]
      A = A.clone()
      A.requires_grad = True
  
      B_shape = (HIDDEN_SIZE, 4 * HIDDEN_SIZE)
      B_master = torch.randn(
          B_shape, dtype=dtype, device=get_current_device()
      )
      torch.distributed.broadcast(B_master, src=0)
      B = torch.chunk(B_master, DEPTH, dim=0)[i]
      B = torch.chunk(B, DEPTH, dim=-1)[j]
      B = B.clone()
      B.requires_grad = True
  
      out_shape = (
          BATCH_SIZE // DEPTH,
          SEQ_LENGTH,
          4 * HIDDEN_SIZE // DEPTH,
      )
  
      out = Matmul_AB_2D.apply(
          A,
          B,
          DEPTH,
          out_shape,
          i,
          j,
          ParallelMode.PARALLEL_2D_ROW,
          ParallelMode.PARALLEL_2D_COL,
          data_parallel_rank,
          pipeline_parallel_rank,
          pipeline_parallel_size,
          tensor_parallel_size,
      )
  
      (BATCH_SIZE, SEQ_LENGTH, 4 * HIDDEN_SIZE)
      A_master = A_master.clone()
      A_master.requires_grad = True
      B_master = B_master.clone()
      B_master.requires_grad = True
      C_master = torch.matmul(A_master, B_master)
      C = torch.chunk(C_master, DEPTH, dim=0)[i]
      C = torch.chunk(C, DEPTH, dim=-1)[j]
      # check forward correctness
      check_equal(out, C)
      print_rank_0("AB forward: pass")
  
      grad_shape = C_master.shape
      grad_master = torch.randn(
          grad_shape, dtype=dtype, device=get_current_device()
      )
      torch.distributed.broadcast(grad_master, src=0)
      grad = torch.chunk(grad_master, DEPTH, dim=0)[i]
      grad = torch.chunk(grad, DEPTH, dim=-1)[j]
  
      out.backward(grad)
  
      C_master.backward(grad_master)
      A_grad = A_master.grad
      A_grad = torch.chunk(A_grad, DEPTH, dim=0)[i]
      A_grad = torch.chunk(A_grad, DEPTH, dim=-1)[j]
      # check backward correctness
      check_equal(A_grad, A.grad)
  
      B_grad = B_master.grad
      B_grad = torch.chunk(B_grad, DEPTH, dim=0)[i]
      B_grad = torch.chunk(B_grad, DEPTH, dim=-1)[j]
      # check backward correctness
      check_equal(B_grad, B.grad)
      print_rank_0("AB backward: pass")
  
file_path: ColossalAI/tests/test_legacy/test_layers/test_2d/checks_2d/check_operation_2d.py
imports: import torch
  from colossalai.legacy.context.parallel_mode import ParallelMode
  from colossalai.legacy.core import global_context
  from colossalai.legacy.nn.layer.parallel_2d._operation import Matmul_AB_2D, Matmul_ABT_2D, Matmul_ATB_2D
  from colossalai.legacy.utils import print_rank_0
  from colossalai.utils import get_current_device
  from .common import BATCH_SIZE, DEPTH, HIDDEN_SIZE, SEQ_LENGTH, check_equal
label_desc: Use image node_id 1 for calling a global function with example usage: check_AB() without return types