
    ȅi%                        % 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                   1r3\!\RD                  RF                     \$S'   \R<                  R                   \R>                  R                   \RV                  R                   1r4\!\RD                  RF                     \$S'   \!Rk                  \3\ 5      r6 " S S	5      r7g)
    )AnyN)_resolve_process_groupFakeWorkProcessGroupWork)tree_map_onlynon_functional_collectivesfunctional_collectivessync_opsc            
       x   \ 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                  \%RL                  R                  1r'\R
                  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                  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r,\R                  R                  \R0                  R                  \R
                  R                  \R2                  R                  \R4                  R                  \RD                  R                  \RD                  R                  1r-\RH                  R                  \RH                  R                  \%RL                  R                  1r.\R@                  R                  \RF                  R                  1r/\0S\1S\24S j5       r3\0S\44S j5       r5\0S\24S j5       r6\0S\74S j5       r8Sr9g	)
CollectiveOpJ   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/james-whalen/.local/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                 h   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      $ [        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	TypeErrorcollective_ops)funcargss     r   get_process_groupCollectiveOp.get_process_group   s     <(((%%d1g..<(((%%d1g..<((()$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       -   $ [%        SU  S[&         35      e)zdCompute the communication tensor size, except for `wait_tensor`, `barrier`, and `monitored_barrier`.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_RESr*   r+   )r,   resr-   kwargss       r   get_comm_tensor_size!CollectiveOp.get_comm_tensor_size   s    <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,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,   r@   s     r   get_workCollectiveOp.get_work   sW    <??">>#&&\***>>#a&))%v^N3CDEEr    N):__name__
__module____qualname____firstlineno__r6   
broadcast_r8   
allreduce_reduce_sendrecv_recv_any_source_barrierr%   
allgather__allgather_base_reduce_scatter_r7   gather_scatter_r9   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_dtensorshard_dim_alltoallr)   rF   rE   r2   r3   r4   r5   r?   r>   staticmethodr   intr   r   r.   rB   r   rG   __static_attributes__rI   r   r   r   r   J   s    			

%%	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 			

%%##
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> Ft F Fr   r   )8typingr   r   torch._C._distributed_c10dr   r   r   r   torch.utils._pytreer   opsr6   r<   r`   re   rN   r8   rO   rP   rQ   rR   rS   rU   rW   r7   rV   rX   rY   r9   r;   rT   monitored_barrier_r	   set_ops
OpOverload__annotations__rZ   r[   r_   rb   reduce_scatter_tensor_outrd   wait_tensorr\   r]   r^   r=   ra   rc   rf   r
   r   unionr+   r   rI   r   r   <module>rv      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 , 	LL##  (((#ejj##
$  13MNuF uFr   