
    i                        U d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
Z
ddlmZmZmZmZmZ ddlmZ i Zeed	f   ed
<   g dZ G d d	e      ZdededdfdZdedededede
j6                  dedefdZdedededede
j6                  dedefdZ ede        ede       dedede	ee
j6                  f   dedef
dZdefdZ ededed   fd        Z!y)!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                   H    e Zd ZdZdededededej                  de	de
fd	Zy
)r   z%Protocol for process group factories.storerank
world_sizetimeoutdevicekwargsreturnc                      y )N )selfr   r   r   r   r   r   s          R/var/www/html/engine/venv/lib/python3.12/site-packages/torch/distributed/_dist2.py__call__zProcessGroupFactory.__call__'   s         N)__name__
__module____qualname____doc__r   intr   torchr   objectr
   r    r   r!   r   r   r   $   sR    /  	
    
r!   namefuncr   c                 D    | t         v rt        d|  d      |t         | <   y)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                 h   ddl m} t        |      dk(  sJ d        || |||      }|j                          t	        | ||      }|j                  t        j                  j                         |j                  |t        j                  j                  |       |j                  t        j                  d      t        j                  j                  |       t        j                  j                         r>|j                  t        j                  d      t        j                  j                  |       |S )Nr   )ProcessGroupGlooz'Gloo backend received unexpected kwargscpucuda)torch.distributedr/   len_set_sequence_number_for_groupr
   _set_default_backendBackendTypeGLOO_register_backendr'   r   r1   is_available)	r   r   r   r   r   r   r/   backend_classpgs	            r   _gloo_factoryr<   @   s     3v;!FFF$UD*gFM002	eT:	.BL4499: !9!9!>!>NU\55::M zz 
LL ,":":"?"?	
 Ir!   c                    ddl m} |j                         }||_        |j	                         D ],  \  }}	t        ||      st        d|       t        |||	       .  || |||      }
|
j                          |
j                  |       t        | ||      }|j                  t        j                  j                         |j                  |t        j                  j                  |
       |S )Nr   )ProcessGroupNCCLzUnknown option )r2   r>   Options_timeoutitemshasattrKeyErrorsetattrr4   eager_connect_single_devicer
   r5   r6   NCCLr8   )r   r   r   r   r   r   r>   optskvr:   r;   s               r   _nccl_factoryrJ   ^   s     3##%DDM 1tQ_QC011a
 %UD*dCM002--f5	eT:	.BL4499:!9!9!>!>NIr!   glooncclbackendc                     | t         vrt        d|  d      t        j                  |      }t	        t        t        d                  \  }}}|j                  |       t        |    |||||fi |S )aF  
    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.
    r,   z not registeredzenv://)r   r-   r'   r   nextiterr   set_timeout)rM   r   r   r   r   r   r   s          r   r   r   ~   st    * i8G9O<==\\&!F"4
8(<#=>E4	gWeT:wQ&QQr!   c                      t               S )zn
    Get the current process group. Thread local method.

    Returns:
        The current process group.
    )r   r   r!   r   r   r      s     "##r!   r;   )NNNc              #   v   K   t               }t        |        	 d t        |       y# t        |       w xY ww)zs
    Context manager for process groups. Thread local method.

    Args:
        pg: The process group to use.
    N)r   r	   )r;   prev_pgs     r   r   r      s1      $%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<   rJ   r   r   r   r   r!   r   <module>r_      s   & %  "   4 /1	4**+ 0( 3 &9 d 
  	
 LL  <
  	
 LL  8  '  'RRR #u||#$R 	R
 R@$| $ $l $y1A'B $ $r!   