
    Vh                     2    d dl mZ d dlZd dlmZ ddZd Zy)    )OptionalN)_pytreec           	         ddl m t        |      dk(  r)|t        |      dk(  rt        d| j                   d      dfd}t        j                  ||       t        j                  ||       st        d| j                   d	| d
| d      dfd}t        j                  ||       t        j                  ||       y)z6
    Common validation across all ops go in here.
    r   )ShardedTensorNz No input for 'z'!Fc                 $    t        |       rdy y )NT)
isinstance)er   has_distributed_tensors    X/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributed/_shard/common_op_utils.pyis_distributed_tensorz0_basic_validation.<locals>.is_distributed_tensor   s    a'%)" (    ztorch function 'z', with args: z and kwargs: z+ are called without any distributed tensor!c                 n    t        |       r(| j                  urt        d      | j                  y y )NzSAll distributed tensors should use the same ProcessGroup if used together in an op.)r   _process_groupRuntimeError)r	   r   cur_pgs    r   validate_pgz&_basic_validation.<locals>.validate_pg%   sE    a'!a&6&6f&D"C  %%F (r   )'torch.distributed._shard.sharded_tensorr   len
ValueError__name__pytree	tree_map_	TypeError)opargskwargsr   r   r   r   r
   s        @@@r   _basic_validationr      s     F
4yA~6>S[A-=?2;;-r:;; #*
 *D1
*F3!r{{m>$ @hIK
 	
 8<F& [$'
[&)r   c                 (      |       d fd	       }y )Nc                     |i }t         j                  j                         5   |i |cddd       S # 1 sw Y   yxY w)ac  
        Handles ``__torch_function__`` dispatch for the default tensor ops that
        behave the same as ``torch.Tensor`` such as ``torch.Tensor.shape`` or
        ``torch.Tensor.dtype``. We simply lower to the real op call with
        DisableTorchFunctionSubclass context like ``torch.Tensor.__torch_function__``
        to avoid recursions.
        N)torch_CDisableTorchFunctionSubclass)typesr   r   pgr   s       r   tensor_default_opz/_register_default_op.<locals>.tensor_default_op4   sA     >FXX224 	't&v&	' 	' 	's   6?) NNr&   )r   	decoratorr%   s   `  r   _register_default_opr(   3   s    r]' 'r   )r&   N)typingr   r    torch.utilsr   r   r   r(   r&   r   r   <module>r+      s      )(*V'r   