
    shS.                     n	   % S SK r 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\" 5       r\\   \S'   S\4S jrS1S jr0 S	S
 _SS _SS _SS _SS _SS _SS _SS _SS _SS _SS _SS  _S!S" _S#S$ _S%S& _S'S( _r\R2                  " 5       (       dI  \R4                  R7                  S)S*5      r\R;                  5        H  u  rr\RA                  \\S+5        M     \RB                  RD                  \RF                  RD                  \RH                  RD                  \RJ                  RD                  \RL                  RD                  \RN                  RD                  \RP                  RD                  \RR                  RD                  \RT                  RD                  \RV                  RD                  \RX                  RD                  \RZ                  RD                  \R\                  RD                  \R^                  RD                  \R`                  RD                  \Rb                  RD                  1r2\\Rf                  Rh                     \S,'   \Rj                  RD                  \Rl                  RD                  \Rn                  RD                  \Rp                  RD                  \Rr                  RD                  \Rr                  RD                  \Rt                  RD                  \Rv                  RD                  \Rx                  RD                  \Rz                  RD                  \R|                  RD                  \R~                  RD                  \Rn                  RD                  \R                  RD                  \Rp                  RD                  \RB                  RD                  \R                  RD                  1rB\\Rf                  Rh                     \S-'   \R`                  RD                  \Rb                  RD                  \Rt                  RD                  1rC\\Rf                  Rh                     \S.'   \R                  \B\25      rE " S/ S05      rFg)2    N)Any)_resolve_process_groupFakeWorkProcessGroupWork)tree_map_onlyused_idsreturnc                  x     [         R                  " SS5      n U [        ;  a  [        R                  U 5        U $ M:  )N   i ʚ;)randomrandintr	   add)new_ids    }/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/distributed/_tools/fake_collectives.pygenerate_unique_idr      s3    
5)!LL M	     c                 t    [        5       n[        5       Ul        UR                  5       nU(       a  U S   U4$ U$ )Nr   )r   r   seq_idboxed)argsreturn_first_argworkfakework_script_objs       r   create_fakeworkr       s7    :D$&DK**,-=DG()VCVVr   
broadcast_c                      [        U 5      $ Nr   r   s    r   <lambda>r!   0   	     5r   
allreduce_c                      [        U 5      $ r   r   r    s    r   r!   r!   1   r"   r   
allgather_c                      [        U 5      $ r   r   r    s    r   r!   r!   2   r"   r   _allgather_base_c                      [        U 5      $ r   r   r    s    r   r!   r!   3   s	    od&;r   reduce_scatter_c                      [        U 5      $ r   r   r    s    r   r!   r!   4   s	    _T%:r   _reduce_scatter_base_c                      [        U 5      $ r   r   r    s    r   r!   r!   5   s	    ?4+@r   reduce_c                      [        U SS9$ NF)r   r   r    s    r   r!   r!   6       _TEJr   gather_c                      [        U SS9$ r/   r   r    s    r   r!   r!   7   r0   r   scatter_c                      [        U 5      $ r   r   r    s    r   r!   r!   8   s	    od3r   	alltoall_c                      [        U 5      $ r   r   r    s    r   r!   r!   9   s	    t4r   alltoall_base_c                      [        U SS9$ r/   r   r    s    r   r!   r!   :   s    OD5$Qr   barrierc                      [        U SS9$ r/   r   r    s    r   r!   r!   ;   r0   r   monitored_barrier_c                      g r    r    s    r   r!   r!   <   s    r   sendc                      [        U SS9$ r/   r   r    s    r   r!   r!   =   s    /$Gr   recv_c                      [        U SS9$ r/   r   r    s    r   r!   r!   >   s    ?4%Hr   recv_any_source_c                      [        U SS9$ r/   r   r    s    r   r!   r!   ?   s    odU&Sr   c10dIMPLMeta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	)
CollectiveOp~   argr
   c                 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 r   )untyped_storagenbytes)rO   total_memorys    r   	sum_bytes+CollectiveOp.sum_tensors.<locals>.sum_bytes   s    A--/6688Lr   )torchTensorr   )rM   rT   rS   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`.r         Func  not found in )
rK   PG_ARG_1r   unboxPG_ARG_2PG_ARG_3r   PG_ARG_4	TypeErrorcollective_ops)funcr   s     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                  :X  a!  US   R                  5       R                  5       $ U [        R                  R                  :X  a8  [        [         R                  US   5      [         R                  US   5      5      $ U [        R                  R                  :X  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 )rK   COMM_TENSOR_ARG_0rX   COMM_TENSOR_ARG_1COMM_TENSOR_ARG_RESrQ   rR   "COMM_TENSOR_SINGLE_UNTYPED_STORAGErD   r+   defaultr5   maxr7   _c10d_functionalall_gather_into_tensor_outCOMM_TENSOR_RES_SUMCOMM_TENSOR_ARG_0_AND_RESrd   re   )rf   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^   )rK   WKr   r`   WK_ARG_1rd   re   )rf   ru   s     r   get_workCollectiveOp.get_work-  sW    <??">>#&&\***>>#a&))%v^N3CDEEr   r=   N):__name__
__module____qualname____firstlineno__rD   r   ro   r#   r-   r>   r@   rB   r9   r_   r%   r'   r)   r+   r1   r3   r5   r7   ra   rq   	broadcast
all_reduceall_reduce_all_reduce_coalescedall_reduce_coalesced_all_gather_into_tensorrr   _c10d_functional_autograd all_gather_into_tensor_coalescedrb   reduce_scatter_tensorreduce_scatter_tensor_coalescedall_to_all_single_dtensorshard_dim_alltoallrc   r{   rz   rk   rl   rm   rn   rt   rs   staticmethodr   intrX   r   rg   rw   r   r|   __static_attributes__r=   r   r   rK   rK   ~   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   rK   )T)Gr   typingr   rV   torch._C._distributed_c10dr   r   r   r   torch.utils._pytreer   distributedbatch_isend_irecvopsrD   rq   r   r   setr	   r   __annotations__r   r   _META_FUNCTIONS_running_with_deploylibraryLibrarylib_implitemsop	meta_funcimplr   ro   r#   r-   r>   r@   rB   r%   r)   r+   r'   r1   r3   r5   r7   r9   r;   rG   _ops
OpOverloadr   r   r   r   r   wait_tensorr   r   r   rr   r   r   r   rH   rI   unionre   rK   r=   r   r   <module>r      s4       .    # #yy~~99-- !II?? 99U#c( C W55 5 ;	
 : @ J J 3 4 Q J , G H  S!& !!##}}$$VV4H(..0Ib)V, 1 	OOOOLLIIJJ!!OO  &&!!LLMMNNLL##!: C

 5 56 & &&''++33**22&&..//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   