
    9i                        % S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	  SSK
r
SSKJrJrJrJrJr  SSKJr  0 r\\S	4   \S
'   / SQr " S S	\5      rS\S\SS4S jrS\S\S\S\S\
R6                  S\S\4S jrS\S\S\S\S\
R6                  S\S\4S jr\" S\5        \" S\5        S\S\S\	\\
R6                  4   S\S\4
S jrS\4S jr \S\S\S   4S  j5       r!g)!z
This is an experimental new API for PyTorch Distributed. This is actively in development and subject to change or deletion entirely.

This is intended as a proving ground for more flexible and object oriented distributed APIs.
    )	Generator)contextmanager)	timedelta)ProtocolUnionN)_current_process_group_set_process_groupProcessGroupReduceOpStore)
rendezvousProcessGroupFactory	_BACKENDS)r
   r   r   register_backend	new_groupcurrent_process_groupprocess_groupc                   R    \ rS rSrSrS\S\S\S\S\R                  S\
S	\4S
 jrSrg)r   $   z%Protocol for process group factories.storerank
world_sizetimeoutdevicekwargsreturnc                     g )N )selfr   r   r   r   r   r   s          X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributed/_dist2.py__call__ProcessGroupFactory.__call__'   s         r   N)__name__
__module____qualname____firstlineno____doc__r   intr   torchr   objectr
   r!   __static_attributes__r   r#   r    r   r   $   sR    /  	
    
r#   namefuncr   c                 H    U [         ;   a  [        SU  S35      eU[         U '   g)z
Register a new process group backend.

Args:
    name: The name of the backend.
    func: The function to create the process group.
Backend z already registeredN)r   
ValueError)r-   r.   s     r    r   r   2   s*     y8D6)<=>>IdOr#   r   r   r   r   r   r   c                 r   SSK Jn  [        U5      S:X  d   S5       eU" XX#5      nUR                  5         [	        XU5      nUR                  [        R                  R                  5        UR                  U[        R                  R                  U5        UR                  [        R                  " S5      [        R                  R                  U5        [        R                  R                  5       (       a?  UR                  [        R                  " S5      [        R                  R                  U5        U$ )Nr   )ProcessGroupGlooz'Gloo backend received unexpected kwargscpucuda)torch.distributedr3   len_set_sequence_number_for_groupr
   _set_default_backendBackendTypeGLOO_register_backendr*   r   r5   is_available)	r   r   r   r   r   r   r3   backend_classpgs	            r    _gloo_factoryr@   @   s     3v;!FFF$U*FM002	e:	.BL4499: !9!9!>!>NU\55::M zz  
LL ,":":"?"?	
 Ir#   c                    SSK Jn  UR                  5       nX7l        UR	                  5        H/  u  p[        Xx5      (       d  [        SU 35      e[        XxU	5        M1     U" XX'5      n
U
R                  5         U
R                  U5        [        XU5      nUR                  [        R                  R                  5        UR                  U[        R                  R                  U
5        U$ )Nr   )ProcessGroupNCCLzUnknown option )r6   rB   Options_timeoutitemshasattrKeyErrorsetattrr8   eager_connect_single_devicer
   r9   r:   NCCLr<   )r   r   r   r   r   r   rB   optskvr>   r?   s               r    _nccl_factoryrN   ^   s     3##%DMt_QC011 
 %U*CM002--f5	e:	.BL4499:!9!9!>!>NIr#   glooncclbackendc                     U [         ;  a  [        SU  S35      e[        R                  " U5      n[	        [        [        S5      5      5      u  pEnUR                  U5        [         U    " XEXaU40 UD6$ )a  
Create a new process group with the given backend and options. This group is
independent and will not be globally registered and thus not usable via the
standard torch.distributed.* APIs.

Args:
    backend: The backend to use for the process group.
    timeout: The timeout for collective operations.
    device: The device to use for the process group.
    **kwargs: All remaining arguments are passed to the backend constructor.
              See the backend specific documentation for details.

Returns:
    A new process group.
r0   z not registeredzenv://)r   r1   r*   r   nextiterr   set_timeout)rQ   r   r   r   r   r   r   s          r    r   r   ~   sn    * i8G9O<==\\&!F"4
8(<#=>E	gWe:Q&QQr#   c                      [        5       $ )z^
Get the current process group. Thread local method.

Returns:
    The current process group.
)r   r   r#   r    r   r      s     "##r#   r?   )NNNc              #   v   #    [        5       n[        U 5         Sv   [        U5        g! [        U5        f = f7f)zc
Context manager for process groups. Thread local method.

Args:
    pg: The process group to use.
N)r   r	   )r?   prev_pgs     r    r   r      s0      $%Gr$7#7#s   9) 969)"r(   collections.abcr   
contextlibr   datetimer   typingr   r   r*   torch._C._distributed_c10dr   r	   r
   r   r   torch.distributed.rendezvousr   r   dictstr__annotations____all__r   r   r)   r   r+   r@   rN   r   r   r   r   r#   r    <module>rc      s   & %  "   4 /1	4**+ 0( 3 &9 d 
  	
 LL  <
  	
 LL  8  '  'RRR #u||#$R 	R
 R@$| $ $l $y1A'B $ $r#   