
    [Th'              	          % S SK JrJr  S SKrS SKrS SKrS SKJ	r	  S SK
Jr  S SKJrJr  S SKJrJrJr  SS	KJr  0 q\\\S
\	\\\\4      4   4   \S'   SS/rS rS\S\\\4   4S jrS\\\4   S\4S jrS\S\S\\   4S jr S%S\S\S\4S jjr!S r"S r#S\4S jr$S\4S jr% S&S\4S jjr&\4S\S\4S  jjr'\4S\S\4S! jjr(\" S"\'5        \" S#\(5        \" S$\$5        g! \ a  r\" S5      \eSrCff = f)'    )urlparse
urlunparsezEurllib cannot be found, urlparse from python2 is no longer supported.N)Iterator)	timedelta)CallableOptional)	FileStoreStoreTCPStore   )default_pg_timeout._rendezvous_handlersregister_rendezvous_handler
rendezvousc                 H    U [         ;   a  [        SU  S35      eU[         U '   g)a  
Register a new rendezvous handler.

Before we can run collective algorithms, participating processes
need to find each other and exchange information to be able to
communicate. We call this process rendezvous.

The outcome of the rendezvous process is a triplet containing a
shared key/value store, the rank of the process, and the total
number of participating processes.

If none of the bundled rendezvous methods apply to your execution
environment you can opt to register your own rendezvous handler.
Pick a unique name and use the URL scheme to identify it when
calling the `rendezvous()` function.

Args:
    scheme (str): URL scheme to identify your rendezvous handler.
    handler (function): Handler that is invoked when the
        `rendezvous()` function is called with a URL that uses
        the corresponding scheme. It must be a generator function
        that yields the triplet.
zRendezvous handler for z:// already registeredN)r   RuntimeError)schemehandlers     T/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributed/rendezvous.pyr   r      s.    2 %%4VH<RSTT#*     queryreturnc                     S [        S U R                  S5      5       5        Vs0 s H  nUS   US   _M     sn$ s  snf )Nc              3   B   #    U  H  oR                  S 5      v   M     g7f)=N)split).0pairs     r   	<genexpr>!_query_to_dict.<locals>.<genexpr>=   s     P1OZZ__1Os   &r   r   )filterr   )r   r   s     r   _query_to_dictr#   :   sL     Qekk#>N1OPPD 	QaP  s   ;
query_dictc                     [         R                  S:X  a3  U R                  S[        R                  R                  SS5      5      S:H  $ U R                  S[        R                  R                  SS5      5      S:H  $ )Nwin32	use_libuv	USE_LIBUV01)sysplatformgetosenviron)r$   s    r   _get_use_libuv_from_query_dictr0   A   s[     ||w~~k2::>>+s+KLPSSS>>+rzz~~k3'GHCOOr   urlrankworld_size_optc                    [        U 5      nUce  SnUR                  S:X  aR  [        [        R                  R                  SU5      5      n[        [        R                  R                  SU5      5      nOUnUS:w  d	  US:w  d  Uc  [        UR                  5      nSU;  a  SU;  d   SU  S35       eUS:w  a  [        U5      US'   US:w  d  Uc  [        U5      US'   UR                  S	R                  UR                  5        VVs/ s H  u  pxU S
U 3PM     snn5       S9n[        U5      n UR                  [        ;  a  [        SUR                   S35      e[        UR                     " U 40 UD6$ s  snnf )NenvRANK
WORLD_SIZEr2   
world_sizez	The url: z7 has node-specific arguments(rank, world_size) already.r!   r   )r   zNo rendezvous handler for z://)r   r   intr.   r/   r-   r#   r   str_replacejoinitemsr   r   r   )	r1   r2   r3   kwargsresultr9   r$   kvs	            r   _rendezvous_helperrC   J   so   c]F
==E!rzz~~fd34DRZZ^^L*EFJ#
rzZ2%)?#FLL1
Z'L
,J 	
uST	
J 2:!$TJv~5'*:J|$XXj6F6F6HI6Hda!AaSz6HIJK ! 
  }}007cJKK.s=f== Js   E5r9   c                 :   [        U [        [        45      (       d  [        S[	        U 5       SU  35      e[        U[
        R                  5      (       d  [        SU 35      e[        U[
        R                  5      (       d  [        SU 35      e[        XU40 UD6$ )Nz`url` must be a string. z: z`rank` must be an integer. z!`world_size` must be an integer. )
isinstancer;   bytesr   typenumbersIntegralrC   )r1   r2   r9   r?   s       r   r   r   g   s    cC<((5d3i[3%HIIdG,,--8?@@j'"2"233>zlKLLc>v>>r   c                 N    [        [        U R                  US 5      5      u  n  nU$ N)nextrC   init_method)backend_optionsr2   store_s       r   _create_store_from_optionsrQ   t   s'    )/*E*EtTRSKE1aLr   c                     [        SU -   5      $ )Nz+Error initializing torch.distributed using )
ValueErrormsgs    r   _rendezvous_errorrV   y   s    CcIJJr   c              +     #    S n[        U 5      nUR                  n[        R                  S:X  a^  SS KnUR
                  UR                  -   nUR                  R                  U5      nU(       a  [        R                  R                  U5      nU(       d  U" S5      e[        UR                  5      nSU;  a  U" S5      eSU;  a  U" S5      e[        US   5      n[        US   5      n	[        XI5      n
XU	4v   [        S	5      e7f)
Nc                     [        SU -   5      $ )Nzfile:// rendezvous: rV   rT   s    r   _error(_file_rendezvous_handler.<locals>._error~   s     !7#!=>>r   r&   r   zpath missingr2   rank parameter missingr9   world size parameter missingz3Unable to perform rerendezvous using file:// method)r   pathr+   r,   urllib.requestnetlocrequesturl2pathnamer.   normpathr#   r   r:   r	   r   )r1   r?   rZ   r@   r^   urllib	full_pathr$   r2   r9   rO   s              r   _file_rendezvous_handlerrf   }   s     ? c]F;;D
||wMMFKK/	~~**9577##D)D^$$-JZ-..:%344z&!"DZ-.Jd'E

## L
MMs   DDc                  Z    [         R                  R                  SS 5      [        S5      :H  $ )NTORCHELASTIC_USE_AGENT_STORET)r.   r/   r-   r;    r   r   _torchelastic_use_agent_storerj      s!    ::>>8$?3t9LLr   c           
          SUs=::  a  S:  d  O  [        SU S35      e[        5       (       a  [        U UUSUS9$ US:H  n[        U UUUUSUS9$ )	aH  
Smartly creates a c10d Store object on ``rank`` based on whether we need to re-use agent store.

The TCPStore server is assumed to be hosted
on ``hostname:port``.

By default, the TCPStore server uses the asynchronous implementation
``LibUVStoreDaemon`` which utilizes libuv.

If ``torchelastic_use_agent_store()`` is ``True``, then it is assumed that
the agent leader (node rank 0) hosts the TCPStore server (for which the
endpoint is specified by the given ``hostname:port``). Hence
ALL ranks will create and return a TCPStore client (e.g. ``start_daemon=False``).

If ``torchelastic_use_agent_store()`` is ``False``, then rank 0 will host
the TCPStore (with multi-tenancy) and it is assumed that rank 0's hostname
and port are correctly passed via ``hostname`` and ``port``. All
non-zero ranks will create and return a TCPStore client.
r   i   z-port must have value from 0 to 65535 but was .F)	host_nameportr9   	is_mastertimeoutT)rm   rn   r9   ro   rp   multi_tenantr'   )rS   rj   r   )hostnamern   r2   r9   rp   r'   start_daemons          r   _create_c10d_storert      sx    . uHaPQQ$&&!
 	
 qy!"
 	
r   rp   c              +     #    S n[        U 5      nUR                  (       d  U" S5      e[        UR                  5      nSU;  a  U" S5      eSU;  a  U" S5      e[	        US   5      n[	        US   5      n[        U5      nUR                  c   e[        UR                  UR                  XgX5      n	XU4v   [        S5      e7f)Nc                     [        SU -   5      $ )Nztcp:// rendezvous: rY   rT   s    r   rZ   '_tcp_rendezvous_handler.<locals>._error        !6!<==r   zport number missingr2   r\   r9   r]   z3Unable to perform re-rendezvous using tcp:// method)	r   rn   r#   r   r:   r0   rr   rt   r   )
r1   rp   r?   rZ   r@   r$   r2   r9   r'   rO   s
             r   _tcp_rendezvous_handlerry      s     > c]F;;*++-JZ-..:%344z&!"DZ-.J.z:I??&&&dE 

## L
MMs   CCc              +     ^^#    S mU4S jmS[         S[         4U4S jjn[        U 5      n[        UR                  5      nSU;   a  [	        US   5      nO[	        U" S5      5      nSU;   a  [	        US   5      nO[	        U" S	5      5      nU" S
5      n[	        U" S5      5      n	[        U5      n
[        XXgX5      nXU4v   [        S5      e7f)Nc                     [        SU -   5      $ )Nzenv:// rendezvous: rY   rT   s    r   rZ   '_env_rendezvous_handler.<locals>._error   rx   r   c                    > T" SU  S35      $ )Nzenvironment variable z expected, but not setri   )varrZ   s    r   
_env_error+_env_rendezvous_handler.<locals>._env_error   s    -cU2HIJJr   env_varr   c                 f   > [         R                  R                  U S 5      nU(       d  T" U 5      eU$ rK   )r.   r/   r-   )r   env_valr   s     r   _get_env_or_raise2_env_rendezvous_handler.<locals>._get_env_or_raise   s*    **..$/W%%Nr   r2   r7   r9   r8   MASTER_ADDRMASTER_PORTz3Unable to perform re-rendezvous using env:// method)r;   r   r#   r   r:   r0   rt   r   )r1   rp   r?   r   r@   r$   r2   r9   master_addrmaster_portr'   rO   r   rZ   s               @@r   _env_rendezvous_handlerr      s     >K3 3  c]F-J :f%&$V,-z!L12
*<89
#M2K'67K.z:I$GE 

## L
MMs   CCtcpr6   file)r5   r5   )T))urllib.parser   r   ImportErrorerH   r.   r+   collections.abcr   datetimer   typingr   r   torch.distributedr	   r
   r   	constantsr   r   dictr;   tupler:   __annotations____all__r   r#   boolr0   rC   r   rQ   rV   rf   rj   rt   ry   r   ri   r   r   <module>r      s  1  	 
 $  % 8 8 ) TV d3huUC_7M.N)N OOP U(,
7+@# $sCx. PtCH~ P$ P>C >s >HSM >:
?C 
?s 
?S 
?
KN# N@Mt M
 :>-

-
b $6N	N N@ $6-N	-N -N` E#: ; E#: ; F$< =}  
Os   C$ $C8*	C33C8