Ë
    P/æjì%  ã                   óÞ  — U d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlZd dlmZ dgZ e j                   e«      Zd a ej(                  «       Zdefd„Z e«       r"ej0                  j3                  «       s ed«      ‚ e«       ràd dlZd dlmc mZ d d	lm Z  d d
l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZEmFZF ddlD­ ddlEmGZG ddlHmIZI ddlJmKZK eee eLeLf   ddf   eMd<   eg d¢z  ZeeDj                  z   eEj                  z   Z	 	 	 	 dd„ZNd„ ZOeGj                   dddddfd„ZQeDj¤                  d„ «       ZSyy)é    N)Ú	timedelta)Ú	GeneratorÚTuple)ÚurlparseÚis_availableÚreturnc                  ó6   — t        t        j                  d«      S )NÚ	_rpc_init)ÚhasattrÚtorchÚ_C© ó    úa/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/torch/distributed/rpc/__init__.pyr   r      s   € Ü”5—8‘8˜[Ó)Ð)r   z*Failed to initialize torch.distributed.rpc)ÚStore)!Ú_cleanup_python_rpc_handlerÚ_DEFAULT_INIT_METHODÚ_DEFAULT_NUM_WORKER_THREADSÚ_DEFAULT_RPC_TIMEOUT_SECÚ)_delete_all_user_and_unforked_owner_rrefsÚ_destroy_rref_contextÚ_disable_jit_rref_pickleÚ'_disable_server_process_global_profilerÚ_enable_jit_rref_pickleÚ&_enable_server_process_global_profilerÚ_get_current_rpc_agentÚ_invoke_remote_builtinÚ_invoke_remote_python_udfÚ_invoke_remote_torchscriptÚ_invoke_rpc_builtinÚ_invoke_rpc_python_udfÚ_invoke_rpc_torchscriptÚ_is_current_rpc_agent_setÚ_reset_current_rpc_agentÚ_rref_context_get_debug_infoÚ_set_and_start_rpc_agentÚ_set_profiler_node_idÚ_set_rpc_timeoutÚ _TensorPipeRpcBackendOptionsBaseÚ_UNSET_RPC_TIMEOUTÚenable_gil_profilingÚget_rpc_timeoutÚPyRRefÚRemoteProfilerManagerÚRpcAgentÚRpcBackendOptionsÚTensorPipeAgentÚ
WorkerInfoé   )ÚapiÚbackend_registryÚ	functions)Ú*)ÚBackendType)ÚTensorPipeRpcBackendOptions)Ú_server_process_global_profileÚrendezvous_iterator)Úinit_rpcr8   r9   éÿÿÿÿc           	      óÞ  — t         j                  j                  d«       |�%t        |t        j
                  «      st        d«      ‚|�t        |t        «      st        d«      ‚|€r|�pt
        D ].  }t        |t        t	        j                  |«      «      «      sŒ,|} n t        d|› �«      ‚|t
        j                  k7  rt        j                  dd|i«       |€t
        j                  }|€t	        j                  |«      }|st        j                  ||«      }n5t        j                  |j                   ||¬«      at%        t"        «      \  }}}|j'                  t)        |j*                  ¬	«      «       t,        5  t        j.                  t1        d
t2        › �«      |«      }t2        dz  addd«       t5        j6                  |«       t9        |«       t;        ||| |||«       y# 1 sw Y   Œ:xY w)ak  
        Initializes RPC primitives such as the local RPC agent
        and distributed autograd, which immediately makes the current
        process ready to send and receive RPCs.

        Args:
            name (str): a globally unique name of this node. (e.g.,
                ``Trainer3``, ``ParameterServer2``, ``Master``, ``Worker1``)
                Name can only contain number, alphabet, underscore, colon,
                and/or dash, and must be shorter than 128 characters.
            backend (BackendType, optional): The type of RPC backend
                implementation. Supported values is
                ``BackendType.TENSORPIPE`` (the default).
                See :ref:`rpc-backends` for more information.
            rank (int): a globally unique id/rank of this node.
            world_size (int): The number of workers in the group.
            rpc_backend_options (RpcBackendOptions, optional): The options
                passed to the RpcAgent constructor. It must be an agent-specific
                subclass of :class:`~torch.distributed.rpc.RpcBackendOptions`
                and contains agent-specific initialization configurations. By
                default, for all agents, it sets the default timeout to 60
                seconds and performs the rendezvous with an underlying process
                group initialized using ``init_method = "env://"``,
                meaning that environment variables ``MASTER_ADDR`` and
                ``MASTER_PORT`` need to be set properly. See
                :ref:`rpc-backends` for more information and find which options
                are available.
        ztorch.distributed.init_rpcNz0Argument backend must be a member of BackendTypezEArgument rpc_backend_options must be an instance of RpcBackendOptionsz$Could not infer backend for options zéRPC was initialized with no explicit backend but with options corresponding to %(backend)s, hence that backend will be used instead of the default BackendType.TENSORPIPE. To silence this warning pass `backend=%(backend)s` explicitly.Úbackend)ÚrankÚ
world_size)ÚsecondsÚrpc_prefix_r3   )r   r   Ú_log_api_usage_onceÚ
isinstancer5   r8   Ú	TypeErrorr0   ÚtypeÚconstruct_rpc_backend_optionsÚ
TENSORPIPEÚloggerÚwarningÚdistÚ_create_store_from_optionsÚ
rendezvousÚinit_methodr;   ÚnextÚset_timeoutr   Úrpc_timeoutÚ_init_counter_lockÚPrefixStoreÚstrÚ_init_counterÚdist_autogradÚ_initr'   Ú_init_rpc_backend)Únamer?   r@   rA   Úrpc_backend_optionsÚcandidate_backendÚstoreÚ_s           r   r<   r<   T   sô  € ôF 	�‰×$Ñ$Ð%AÔBØÐ¤zØÔ%×1Ñ1ô(
ô ÐNÓOÐOàÐ*´:ØÔ!2ô4
ô ØWóð ð
 ˆ?Ð2Ð>Ü%0ò Ð!ÜØ'ÜÜ(×FÑFØ-óóõð 0�GÙðô  Ø:Ð;NÐ:OÐPóð ð œ+×0Ñ0Ò0Ü—‘ðEð  Ð(ôð ˆ?Ü!×,Ñ,ˆGàÐ&ä"2×"PÑ"PØó#Ðñ
 ô ×3Ñ3Ð4GÈÓN‰Eô #'§/¡/Ø#×/Ñ/°dÀzô#Ðô Ô2Ó3‰KˆE�1�aà×Ñœ)Ð,?×,KÑ,KÔLÔMô  ñ 	ä×$Ñ$¤S¨;´}°oÐ)FÓ%GÈÓOˆEÜ˜QÑˆM÷	ô 	×Ñ˜DÔ!ä˜dÔ#ä˜' 5¨$°°jÐBUÕV÷	ð 	ús   Å:0G#Ç#G,c                 ó8  — | t         j                  |t        j                  |t        |t
        j                  |t
        j                  t        d «      f|t        i}|j                  «       D ].  \  }}t        ||«      rŒt        d|› d|› dt        |«      › �«      ‚ y )Nz	Argument z must be of type z but got type )r5   r8   rL   r   rU   ÚnumbersÚIntegralrG   r0   ÚitemsrE   ÚRuntimeError)	r?   r]   rZ   r@   rA   r[   Útype_mappingÚargÚarg_types	            r   Ú_validate_rpc_argsrg   Ë   s™   € àÔ%×1Ñ1Ø”4—:‘:Ø”#Ø”'×"Ñ"àœ×)Ñ)¬4°«:Ð6ØÔ!2ð
ˆð *×/Ñ/Ó1ò 	‰MˆC�Ü˜c 8Õ,Ü"Ø ˜uÐ$5°h°Z¸~ÌdÐSVËiÈ[ÐYóð ñ	r   c                 ó®   — t        | |||||«       t        «       rt        d«      ‚t        j                  | |||||¬«      }t        j                  |«       y )NzRPC is already initialized)r]   rZ   r@   rA   r[   )rg   r#   rc   r5   Úinit_backendr4   Ú_init_rpc_states)r?   r]   rZ   r@   rA   r[   Ú	rpc_agents          r   rY   rY   Û   s]   € ô 	˜7 E¨4°°zÐCVÔWä$Ô&ÜÐ;Ó<Ð<ô %×1Ñ1ØØØØØ!Ø 3ô
ˆ	ô 	×Ñ˜YÕ'r   c                  óÂ   — t        «       } | j                  t        j                  «       j	                  «       «       | j                  t        j                  «       «       | S )N)r%   Úupdater4   r   Úget_debug_inforW   Ú_get_debug_info)Úinfos    r   ro   ro   ô   sB   € ä+Ó-ˆØ�‰”C×.Ñ.Ó0×?Ñ?ÓAÔBØ�‰”M×1Ñ1Ó3Ô4Øˆr   )Nr=   NN)TÚloggingÚosÚ	threadingÚwarningsÚdatetimer   Útypingr   r   Úurllib.parser   r   Útorch.distributedÚdistributedrL   Ú__all__Ú	getLoggerÚ__name__rJ   rV   ÚLockrS   Úboolr   r   r
   rc   r`   Útorch.distributed.autogradÚautogradrW   Útorch._C._distributed_c10dr   Útorch._C._distributed_rpcr   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   r1   r2   Ú r4   r5   r6   r8   Úoptionsr9   Úserver_process_global_profilerr:   ÚintÚ__annotations__r<   rg   rI   rY   Ú_require_initializedro   r   r   r   ú<module>r‰      ss  ðä Û 	Û Û Ý ß #Ý !ã Ý  ð Ð
€ð 
ˆ×	Ñ	˜8Ó	$€ð €Ø#�Y—^‘^Ó%Ð ð*�dó *ñ „>˜%Ÿ(™(×,Ñ,Ô.Ù
ÐCÓ
DÐDñ „>Ûç6Ð6Ý0÷"÷ "÷ "÷ "÷ "÷ "÷ "÷ "õ "÷H 3Ñ2ÜÝ-Ý4ÝNà" 5¨°°S¨Ñ#9¸4ÀÐ#EÑFÓFàÒIÑI€GØ˜Ÿ™Ñ#Ð&6×&>Ñ&>Ñ>€Gð ØØØ óuWònð" ×&Ñ&ØØØØØ ó(ð2 	×Ññó ñðk r   