
    3jC'                     j   % S SK Jr  S SKrS SKJrJrJrJr  S SKJ	r	  \R                  R                  r\R                  R                  r\R                  R                  r\R                  R                  r\R                  R                   \R"                  R                   \R$                  R                   \R&                  R                   \R(                  R                   \R*                  R                   \R,                  R                   \R.                  R                   \R0                  R                   \R2                  R                   \R4                  R                   \R6                  R                   \R8                  R                   \R:                  R                   \R<                  R                   \R>                  R                   1r \!\RD                  RF                     \$S'   \RJ                  R                   \RL                  R                   \RN                  R                   \RP                  R                   \RR                  R                   \RT                  R                   \RT                  R                   \RV                  R                   \RX                  R                   \RZ                  R                   \R\                  R                   \R^                  R                   \R`                  R                   \RN                  R                   \Rb                  R                   \RP                  R                   \R                  R                   \Rd                  R                   \Rf                  R                   \Rh                  R                   \Rj                  R                   1r6\!\RD                  RF                     \$S'   \R<                  R                   \R>                  R                   \RV                  R                   1r7\!\RD                  RF                     \$S'   \!Rq                  \6\ 5      r9 " S S	5      r:g)
    )AnyN)_resolve_process_groupFakeWorkProcessGroupWork)tree_map_onlynon_functional_collectivesfunctional_collectivessync_opsc            
       N   \ rS rSr\R
                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  1r\R                  R                  \R                  R                  \R                   R                  \R"                  R                  \R$                  R                  \R&                  R                  \R(                  R                  \R*                  R                  1r\R0                  R                  \R
                  R                  \R2                  R                  \R4                  R                  \R6                  R                  \R8                  R                  \R:                  R                  \R<                  R                  \R:                  R                  \R@                  R                  1
r!\RD                  R                  \RF                  R                  \RD                  R                  \RH                  R                  \RH                  R                  \RJ                  R                  \RL                  R                  \'RP                  R                  1r)\RT                  R                  1r+\R
                  R                  \R                  R                  \R                  R                  \R                   R                  \R"                  R                  \R                  R                  \R&                  R                  \R(                  R                  \RJ                  R                  \RL                  R                  1
r,\R                  R                  \R                  R                  \R                  R                  \R                  R                  \R$                  R                  \R*                  R                  \R                  R                  1r-\R                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  \R$                  R                  \R                  R                  \R
                  R                  \R6                  R                  \R8                  R                  1
r.\R                   R                  \R&                  R                  1r/\R:                  R                  \R:                  R                  1r0\R                  R                  \R0                  R                  \R
                  R                  \R2                  R                  \R4                  R                  \RD                  R                  \RD                  R                  1r1\RH                  R                  \RH                  R                  \'RP                  R                  1r2\R@                  R                  \RF                  R                  1r3\4S\5S\64S j5       r7\4S\84S j5       r9\4S\64S j5       r:\4S\;4S j5       r<Sr=g	)
CollectiveOpM   argreturnc                 t   ^ SmS[         R                  SS4U4S jjn[        [         R                  X5        T$ )z?Calculate total memory consumed by the tensors in the argument.r   tr   Nc                 H   > TU R                  5       R                  5       -  mg )N)untyped_storagenbytes)r   total_memorys    c/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/distributed/_tools/fake_collectives.py	sum_bytes+CollectiveOp.sum_tensors.<locals>.sum_bytes   s    A--/6688L    )torchTensorr   )r   r   r   s     @r   sum_tensorsCollectiveOp.sum_tensors   s7     	9 	9$ 	9 	ellI3r   c                    U [         R                  ;   a  [        R                  " US   5      $ U [         R                  ;   a  [        R                  " US   5      $ U [         R
                  ;   a  [        US   5      $ U [         R                  ;   a  [        US   5      $ U [         R                  ;   a  [        US   5      $ [        SU  S[         35      e)zKRetrieve the process group for collective operations, except `wait_tensor`.            Func  not found in )r   PG_ARG_1r   unboxPG_ARG_2PG_ARG_3r   PG_ARG_4PG_ARG_5	TypeErrorcollective_ops)funcargss     r   get_process_groupCollectiveOp.get_process_group   s     <(((%%d1g..<(((%%d1g..<((()$q'22<((()$q'22<((()$q'22%v^N3CDEEr   c                    U [         R                  ;   a  [         R                  US   5      $ U [         R                  ;   a  [         R                  US   5      $ U [         R                  ;   a  UR                  5       R                  5       $ U [         R                  ;   a!  US   R                  5       R                  5       $ U [        R                  R                  L a!  US   R                  5       R                  5       $ U [        R                  R                  L a8  [        [         R                  US   5      [         R                  US   5      5      $ U [        R                  R                  L aJ  [        US   R                  5       R                  5       US   R                  5       R                  5       5      $ U [        R                  R                  :X  a!  US   R                  5       R                  5       $ U [         R                   ;   a  [         R                  U5      $ U [         R"                  ;   a@  US   R                  5       R                  5       UR                  5       R                  5       -   $ U [        R$                  R                  L a  [         R                  US   5      $ ['        SU  S[(         35      e)zdCompute the communication tensor size, except for `wait_tensor`, `barrier`, and `monitored_barrier`.r   r    r"   zUnknown function: z in )r   COMM_TENSOR_ARG_0r   COMM_TENSOR_ARG_1COMM_TENSOR_ARG_RESr   r   "COMM_TENSOR_SINGLE_UNTYPED_STORAGEc10d_reduce_scatter_base_default	alltoall_maxalltoall_base__c10d_functionalall_gather_into_tensor_outCOMM_TENSOR_RES_SUMCOMM_TENSOR_ARG_0_AND_RESbatch_p2p_opsr,   r-   )r.   resr/   kwargss       r   get_comm_tensor_size!CollectiveOp.get_comm_tensor_size   s8    <111++DG44<111++DG44<333&&(//11<BBB7**,33554--5557**,33554>>)))((a1<3K3KDQRG3T  4&&...Q'')002DG4K4K4M4T4T4V  #>>FFF8++-4466<333++C00<9997**,3358K8K8M8T8T8VVV#11999++DG44,TF$~6FGHHr   c                     U [         R                  ;   a  [        R                  " U5      $ U [         R                  ;   a  [        R                  " US   5      $ [        SU  S[         35      e)Nr    r$   r%   )r   WKr   r'   WK_ARG_1r,   r-   )r.   rC   s     r   get_workCollectiveOp.get_work  sW    <??">>#&&\***>>#a&))%v^N3CDEEr    N)>__name__
__module____qualname____firstlineno__r8   
broadcast_r:   
allreduce_reduce_sendrecv_recv_any_source_barrierr&   
allgather__allgather_base_reduce_scatter_r9   gather_scatter_r;   r=   r(   r>   	broadcast
all_reduceall_reduce_all_reduce_coalescedall_reduce_coalesced_all_gather_into_tensorr?   _c10d_functional_autograd all_gather_into_tensor_coalescedr)   reduce_scatter_tensorreduce_scatter_tensor_coalescedall_to_all_singleisendirecv_dtensorshard_dim_alltoallr*   rB   r+   rI   rH   r4   r5   r6   r7   rA   r@   staticmethodr   intr   r   r0   rE   r   rJ   __static_attributes__rL   r   r   r   r   M   sE    			

%%	H 	%%$$""**##H 	""**##++##++$$,,--55..66//7733;;!88@@99AAH 	..6688@@!77??**22!33;;&&&&##++	H 	&&..H
 	$$""**%%&&&&H 			

%%##
B 			

%%--55..66" 	$$ 	//77!88@@ 	%%""**##++##++$$,,..66!77??*& 	**22!33;;##++! 	99AA88@@
 	 	 	 	 F F F I I IB Ft F Fr   r   );typingr   r   torch._C._distributed_c10dr   r   r   r   torch.utils._pytreer   opsr8   r>   rc   rj   rQ   r:   rR   rS   rT   rU   rV   rX   rZ   r9   rY   r[   r\   r;   r=   rW   monitored_barrier_r	   set_ops
OpOverload__annotations__r]   r^   rb   re   reduce_scatter_tensor_outrg   wait_tensorr_   r`   ra   r?   rd   rf   rh   ri   rB   rk   r
   r   unionr-   r   rL   r   r   <module>r{      s      . yy~~99-- !II?? 99 	OOOOLLIIJJ!!OO  &&!!LLMMNNLL##!: C

 5 56 & &&''++33**22..66&&..//77  ((  (())11**22//7755==44<<44<<33;;''""""""**''+6 EJJ112 2 	LL##  (((#ejj##
$  13MNAF AFr   