docstr: dim_map is a property we derive from `placements` of
  the distributed tensor. It simply return a list of ints
  where dim_map[i] denotes the sharding mapping to the mesh
  dimension, and len(dim_map) == dist_tensor.ndim
  dim_map[i] = -1: means tensor dim i replicate on mesh
  dim_map[i] = j: means tensor dim i shard on mesh dim j
  
  For example, we have a dist tensor that have the shape of
  [18, 20, 30], and device_mesh([0, 1, 2, 3]), placements:
  [Shard(1)], the dim_map of this placement would be:
  [-1, 0, -1]. This representation is pretty helpful during
  sharding propagation where we could know exactly each
  tensor dimension is sharded or not.
  
  Note that if placements contains `_Partial`, we have to
  explicitly deal with it, so that when we create a DTensorSpec
  with dim_map, we could properly record the pending sums.
docstr_tok: ["dim_map","is","a","property","we","derive","from","`","placements","`","of","the","distributed","tensor",".","It","simply","return","a","list","of","ints","where","dim_map","[","i","]","denotes","the","sharding","mapping","to","the","mesh","dimension",",","and","len","(","dim_map",")","==","dist_tensor.ndim","dim_map","[","i","]","=","-1",":","means","tensor","dim","i","replicate","on","mesh","dim_map","[","i","]","=","j",":","means","tensor","dim","i","shard","on","mesh","dim","j","For","example",",","we","have","a","dist","tensor","that","have","the","shape","of","[","18",",","20",",","30","]",",","and","device_mesh","(","[","0",",","1",",","2",",","3","]",")",",","placements",":","[","Shard","(","1",")","]",",","the","dim_map","of","this","placement","would","be",":","[","-1",",","0",",","-1","]",".","This","representation","is","pretty","helpful","during","sharding","propagation","where","we","could","know","exactly","each","tensor","dimension","is","sharded","or","not",".","Note","that","if","placements","contains","`","_Partial","`",",","we","have","to","explicitly","deal","with","it",",","so","that","when","we","create","a","DTensorSpec","with","dim_map",",","we","could","properly","record","the","pending","sums","."]
code: def dim_map(self) -> List[int]:
      """
      dim_map is a property we derive from `placements` of
      the distributed tensor. It simply return a list of ints
      where dim_map[i] denotes the sharding mapping to the mesh
      dimension, and len(dim_map) == dist_tensor.ndim
      dim_map[i] = -1: means tensor dim i replicate on mesh
      dim_map[i] = j: means tensor dim i shard on mesh dim j
  
      For example, we have a dist tensor that have the shape of
      [18, 20, 30], and device_mesh([0, 1, 2, 3]), placements:
      [Shard(1)], the dim_map of this placement would be:
      [-1, 0, -1]. This representation is pretty helpful during
      sharding propagation where we could know exactly each
      tensor dimension is sharded or not.
  
      Note that if placements contains `_Partial`, we have to
      explicitly deal with it, so that when we create a DTensorSpec
      with dim_map, we could properly record the pending sums.
      """
      # dims mapping of dist tensor sharding
      # return size of tensor ndim, -1 represent replicate
      # and int >=0 represent shard on that device mesh dim
      r = [-1] * self.ndim
      for i, placement in enumerate(self.placements):
          if placement.is_shard():
              shard_dim = cast(Shard, placement).dim
              if r[shard_dim] > -1:
                  raise ValueError(
                      f"Tensor dim {shard_dim} is already sharded on mesh dim {r[shard_dim]},"
                      " DTensor operator implementation does not support things like hybrid"
                      " sharding strategies yet (i.e. [Shard(0), Shard(0)])"
                  )
              r[shard_dim] = i
      return r
  
imports: from dataclasses import dataclass
  from typing import Any, cast, List, NamedTuple, Optional, Tuple
  import torch
  import torch.distributed._functional_collectives
  import torch.distributed.distributed_c10d
  from torch.distributed._tensor._collective_utils import mesh_broadcast, mesh_scatter
  from torch.distributed.device_mesh import DeviceMesh
label_desc: Use image node_id 12 for calling the DTensorSpec obj's underlying member method code with example usage: obj.dim_map() and returns: r