docstr: Replicate (broadcast) a torch.Tensor on a mesh dimension (use
  the first coordinate on the mesh dimension as source of truth)
docstr_tok: ["Replicate","(","broadcast",")","a","torch.Tensor","on","a","mesh","dimension","(","use","the","first","coordinate","on","the","mesh","dimension","as","source","of","truth",")"]
code: def _replicate_tensor(
      self, tensor: torch.Tensor, mesh: DeviceMesh, mesh_dim: int
  ) -> torch.Tensor:
      """
      Replicate (broadcast) a torch.Tensor on a mesh dimension (use
      the first coordinate on the mesh dimension as source of truth)
      """
      my_coordinate = mesh.get_coordinate()
      if my_coordinate is None:
          # if rank is not part of mesh, we simply return an empty tensor
          return tensor.new_empty(0, requires_grad=tensor.requires_grad)
  
      tensor = tensor.contiguous()
      mesh_broadcast(tensor, mesh, mesh_dim=mesh_dim)
      return tensor
  
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 5 for calling the Replicate obj's underlying member method code with example usage: obj._replicate_tensor(tensor, mesh, mesh_dim) and returns: tensor, tensor