code: def check_keep_sharding_status(
      input_dim_partition_dict: Dict[int, List[int]],
      reshape_mapping_dict: Dict[Tuple[int], Tuple[int]],
  ) -> bool:
      """
      This method is used to check whether the reshape operation could implement without converting
      the input to fully replicated status.
  
      Rule:
          For a sharded dimension of input tensor, if it is not the minimum element of the input tuple,
          the function will return false.
          To illustrate this issue, there are two cases to analyze:
          1. no sharded dims in the input tuple: we could do the reshape operation safely just as the normal
          operation without distributed tensor.
          2. sharded dims in the input tuple: the sharded dim must be the minimum element, then during shape
          consistency process, torch.cat will be implemented on the sharded dim, and everything after the sharded
          dim get recovered.
  
      Examples:
          # the second dimension of the input has been sharded.
          input_dim_partition_dict = {1: [1]}
          origin_shape = torch.Size([8, 4, 2])
          tgt_shape = torch.Size([2, 4, 8])
          reshape_mapping_dict = detect_reshape_mapping(origin_shape, tgt_shape)
          # {(2, 1): (2,), (0,): (1, 0)}
          # the sharded dim of input is 1, which is the minimum element of the tuple (2, 1),
          # so we do not have to convert the input to fully replicated status.
          print(check_keep_sharding_status(input_dim_partition_dict, reshape_mapping_dict))
  
      Output:
          True
      """
      sharded_dims = list(input_dim_partition_dict.keys())
      for input_dims in reshape_mapping_dict.keys():
          # if input_dims has no element, we could just skip this iteration.
          if len(input_dims) == 0:
              continue
          min_element = min(input_dims)
          for dim in input_dims:
              if dim in sharded_dims and dim is not min_element:
                  return False
      return True
  
file_path: ColossalAI/colossalai/auto_parallel/tensor_shard/utils/reshape.py
imports: from enum import Enum
  from typing import Dict, List, Tuple
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: check_keep_sharding_status(input_dim_partition_dict, reshape_mapping_dict) and returns: True, False