Ë
    g^(hî%  ã                   óÚ  — 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 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
j.                  j1                  «       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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZE ddlC­ ddlDmFZF ddlGmHZH ddlImJZJ eeKeeLeLf   ddf   eMd<   eg d¢z  ZeeCj                  z   eDj                  z   Z	 	 	 	 dd„ZNd„ ZOeFj                   dddddfd„ZQeCj¤                  d„ «       ZSyy)é    N)Ú	Generator)Ú	timedelta)ÚurlparseÚis_availableÚreturnc                  ó6   — t        t        j                  d«      S )NÚ	_rpc_init)ÚhasattrÚtorchÚ_C© ó    ú\/var/www/skyplay_api_hub/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_rpcr7   r8   éÿÿÿÿ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_r2   )r   r   Ú_log_api_usage_onceÚ
isinstancer4   r7   Ú	TypeErrorr/   Ú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?   r@   Ú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 )r4   r7   rK   r   rT   ÚnumbersÚIntegralrF   r/   ÚitemsrD   ÚRuntimeError)	r>   r\   rY   r?   r@   rZ   Útype_mappingÚargÚarg_types	            r   Ú_validate_rpc_argsrf   Ë   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\   rY   r?   r@   rZ   )rf   r"   rb   r4   Úinit_backendr3   Ú_init_rpc_states)r>   r\   rY   r?   r@   rZ   Ú	rpc_agents          r   rX   rX   Û   s]   € ô 	˜7 E¨4°°zÐCVÔWä$Ô&ÜÐ;Ó<Ð<ô %×1Ñ1ØØØØØ!Ø 3ô
ˆ	ô 	×Ñ˜YÕ'r   c                  óÂ   — t        «       } | j                  t        j                  «       j	                  «       «       | j                  t        j                  «       «       | S )N)r$   Úupdater3   r   Úget_debug_inforV   Ú_get_debug_info)Úinfos    r   rn   rn   ô   sB   € ä+Ó-ˆØ�‰”C×.Ñ.Ó0×?Ñ?ÓAÔBØ�‰”M×1Ñ1Ó3Ô4Øˆr   )Nr<   NN)TÚloggingÚosÚ	threadingÚwarningsÚcollections.abcr   Údatetimer   Úurllib.parser   r   Útorch.distributedÚdistributedrK   Ú__all__Ú	getLoggerÚ__name__rI   rU   ÚLockrR   Úboolr   r   r	   rb   r_   Útorch.distributed.autogradÚautogradrV   Ú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.   r/   r0   r1   Ú r3   r4   r5   r7   Úoptionsr8   Úserver_process_global_profilerr9   ÚtupleÚintÚ__annotations__r;   rf   rH   rX   Ú_require_initializedrn   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   