class_docstr: Sharding spec describes how to shard a tensor with dim_size dimensions. The sharding sequence looks like
  [R, R, S0, S1], which means
  
  Argument:
      dim_partition_dict(Dict[int, List[int]], optional): The key is the dimension of tensor to be sharded,
          and the value of the key describe which logical axis will be sharded in that dimension.
      sharding_sequence(List[DimSpec], optional): A straight view of ShardingSpec looks like [R, R, S0, S1].
class_docstr_tok: ["Sharding","spec","describes","how","to","shard","a","tensor","with","dim_size","dimensions",".","The","sharding","sequence","looks","like","[","R",",","R",",","S0",",","S1","]",",","which","means","Argument",":","dim_partition_dict","(","Dict","[","int",",","List","[","int","]","]",",","optional",")",":","The","key","is","the","dimension","of","tensor","to","be","sharded",",","and","the","value","of","the","key","describe","which","logical","axis","will","be","sharded","in","that","dimension",".","sharding_sequence","(","List","[","DimSpec","]",",","optional",")",":","A","straight","view","of","ShardingSpec","looks","like","[","R",",","R",",","S0",",","S1","]","."]
docstr: This function is a naive version of difference computation. It just simply accumulates difference every dimension between the
  pair of sharding sequence.
  
  Example:
      dim_partition_dict = {0: [0, 1]}
      # DistSpec:
      #     shard_sequence: S01,R,R
      #     device_mesh_shape: (4, 4)
      sharding_spec = ShardingSpec(device_mesh, entire_shape, dim_partition_dict)
      dim_partition_dict_to_compare = {0: [0], 1: [1]}
      # DistSpec:
      #     shard_sequence: S0,S1,R
      #     device_mesh_shape: (4, 4)
      sharding_spec_to_compare = ShardingSpec(device_mesh, entire_shape, dim_partition_dict_to_compare)
      print(sharding_spec.sharding_sequence_difference(sharding_spec_to_compare))
  
  Output:
      25
  
  Argument:
      other(ShardingSpec): The ShardingSpec to compared with.
  
  Return:
      difference(int): Difference between two ShardingSpec.
docstr_tok: ["This","function","is","a","naive","version","of","difference","computation",".","It","just","simply","accumulates","difference","every","dimension","between","the","pair","of","sharding","sequence",".","Example",":","dim_partition_dict","=","{","0",":","[","0",",","1","]","}","#","DistSpec",":","#","shard_sequence",":","S01",",","R",",","R","#","device_mesh_shape",":","(","4",",","4",")","sharding_spec","=","ShardingSpec","(","device_mesh",",","entire_shape",",","dim_partition_dict",")","dim_partition_dict_to_compare","=","{","0",":","[","0","]",",","1",":","[","1","]","}","#","DistSpec",":","#","shard_sequence",":","S0",",","S1",",","R","#","device_mesh_shape",":","(","4",",","4",")","sharding_spec_to_compare","=","ShardingSpec","(","device_mesh",",","entire_shape",",","dim_partition_dict_to_compare",")","print","(","sharding_spec.sharding_sequence_difference","(","sharding_spec_to_compare",")",")","Output",":","25","Argument",":","other","(","ShardingSpec",")",":","The","ShardingSpec","to","compared","with",".","Return",":","difference","(","int",")",":","Difference","between","two","ShardingSpec","."]
code: def spec_diff(self, other):
      """
      This function is a naive version of difference computation. It just simply accumulates difference every dimension between the
      pair of sharding sequence.
  
      Example:
          dim_partition_dict = {0: [0, 1]}
          # DistSpec:
          #     shard_sequence: S01,R,R
          #     device_mesh_shape: (4, 4)
          sharding_spec = ShardingSpec(device_mesh, entire_shape, dim_partition_dict)
          dim_partition_dict_to_compare = {0: [0], 1: [1]}
          # DistSpec:
          #     shard_sequence: S0,S1,R
          #     device_mesh_shape: (4, 4)
          sharding_spec_to_compare = ShardingSpec(device_mesh, entire_shape, dim_partition_dict_to_compare)
          print(sharding_spec.sharding_sequence_difference(sharding_spec_to_compare))
  
      Output:
          25
  
      Argument:
          other(ShardingSpec): The ShardingSpec to compared with.
  
      Return:
          difference(int): Difference between two ShardingSpec.
      """
      assert len(self.sharding_sequence) == len(
          other.sharding_sequence
      ), f"Cannot compare difference for two sharding specs with different length."
      difference = 0
      for orig_dim_spec, other_dim_spec in zip(
          self.sharding_sequence, other.sharding_sequence
      ):
          difference += orig_dim_spec.dim_diff(other_dim_spec)
      return difference
  
file_path: colossalai/colossalai/tensor/d_tensor/sharding_spec.py
imports: from copy import deepcopy
  from typing import Dict, List
  from ..utils import merge_same_dim_mesh_list
  from .misc import ShardingOutOfIndexError
label_desc: Use image node_id 6 for calling the ShardingSpec obj's underlying member method code with example usage: obj.spec_diff(other) and returns: difference