
    Vh		                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ 	 d dl	m
Z eeeedf   f   Zd	ed
eddfdZdeddfdZy# e$ r d ZY )w xY w)    N)Union)_mesh_resources)
DeviceMesh)	Placement)is_compilingc                       y)NF r	       X/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributed/tensor/parallel/_utils.pyis_torchdynamo_compilingr      s    r
   .	func_name	extra_msgreturnc                 \    t               s"t        j                  |  d| t        d       yy)z
    Inject common validation logics for `_prepare_input` funcs via this decorator.

    Include verifying that input needs to be either a :class:`Tensor` or :class:`DTensor`
    and only 1D :class:`DeviceMesh` is passed in.
    z) is deprecated and will be removed soon.    )
stacklevelN)r   warningswarnFutureWarning)r   r   s     r   _deprecate_warningsr      s0     $%kB9+N	
 &r
   device_meshc                     | j                   dkD  rt        d| j                    d      t        j                  |       }|r>|| k7  r8t        j                  |       }||j                   dz
  k7  rt        d| dd      yyy)a  
    Check whether TP mesh dimension is valid or not.

    Args:
        device_mesh (:class:`DeviceMesh`):
            The `device_mesh` where we perform
            Tensor Parallelism on.

    Return:
        `True` if the mesh dimension
        is valid, `False` otherwise.
       z8Tensor Parallel only accepts a 1D DeviceMesh, but found zMD!If you have a 2-D or N-D device_mesh, consider passing in device_mesh["tp"]zFound TP device_mesh on the z dimension of its parent mesh.zeCurrently we only support intranode TP and TP needs to be the innermost dimension on its parent mesh.N)ndim
ValueErrorr   get_root_meshget_root_mesh_dimRuntimeError)r   	root_meshtp_mesh_dim_in_roots      r   _validate_tp_mesh_dimr!   %   s     !F{GWGWFX YZ Z
 	

  --k:I Y+--??L)..1"44./B.CCabw  5 .yr
   )r   typingr   torch.distributed.device_meshr   torch.distributed.tensorr   (torch.distributed.tensor.placement_typesr   torch._dynamo.external_utilsr   r   	ExceptiontupleLayoutsTypestrr   r!   r	   r
   r   <module>r+      s{      9 / >U IuY^445
3 
3 
4 
 	3  s   A AA