class_docstr: Layout of a tensor.
  
  Attributes:
      device_mesh: the device mesh to store the tensor distributed.
      sharding_spec: the sharding specification to describe how the tensor is sharded.
      global_shape: the entire shape of the global tensor.
class_docstr_tok: ["Layout","of","a","tensor",".","Attributes",":","device_mesh",":","the","device","mesh","to","store","the","tensor","distributed",".","sharding_spec",":","the","sharding","specification","to","describe","how","the","tensor","is","sharded",".","global_shape",":","the","entire","shape","of","the","global","tensor","."]
code: def _sanity_check(self):
      sharding_spec = self.sharding_spec
  
      # make sure all axes in logical device mesh only be used once
      if self.device_mesh.logical_mesh_id is not None:
          dim_check_list = list(
              range(self.device_mesh.logical_mesh_id.dim())
          )
          for (
              dim,
              shard_list,
          ) in sharding_spec.dim_partition_dict.items():
              for element in shard_list:
                  if element in dim_check_list:
                      dim_check_list.remove(element)
                  else:
                      raise DuplicatedShardingDimensionError(
                          f"find an invalid sharding axis {element} in dim_partition_dict in tensor dimension {dim}."
                      )
  
      # make sure that the sharding for a dimension is divisible by the number of devices
      for dim, shard_list in sharding_spec.dim_partition_dict.items():
          tensor_dim_size = self.global_shape[dim]
          num_devices = 1
  
          for element in shard_list:
              num_devices *= self.device_mesh.shape[element]
  
          if tensor_dim_size % num_devices != 0:
              raise ShardingNotDivisibleError(
                  f"The size of dimension at index {dim} is {tensor_dim_size}, it cannot be sharded over {num_devices} devices."
              )
  
file_path: colossalai/colossalai/tensor/d_tensor/layout.py
imports: import operator
  from functools import reduce
  import torch
  from colossalai.device.device_mesh import DeviceMesh
  from .misc import DuplicatedShardingDimensionError, ShardingNotDivisibleError
  from .sharding_spec import ShardingSpec
label_desc: Use image node_id 4 for calling the Layout obj's underlying member method code with example usage: obj._sanity_check() without return types