
    &Vji&                        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                                        s ed           e            r ee
j        j        d	          Z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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA er
d dl#mBZBmCZCmDZD ddlEmFZFmGZGmHZH ddlFT ddlGmIZI ddlJmKZK ddlLmMZM eeNe"eOeOf         ddf         ePd<   eg dz  ZeeFj        z   eGj        z   Z	 	 	 	 ddZQd ZReIjS        dddddfdZTeFjU        d             ZVdS dS )    N)	Generator)	timedelta)urlparseis_availablereturnc                  6    t          t          j        d          S )N	_rpc_init)hasattrtorch_C     X/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/distributed/rpc/__init__.pyr   r      s    58[)))r   z*Failed to initialize torch.distributed.rpc _TensorPipeRpcBackendOptionsBase)Store)_cleanup_python_rpc_handler_DEFAULT_INIT_METHOD_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_UNSET_RPC_TIMEOUTenable_gil_profilingget_rpc_timeoutPyRRefRemoteProfilerManagerRpcAgentRpcBackendOptions
WorkerInfo)_DEFAULT_NUM_WORKER_THREADSr   TensorPipeAgent   )apibackend_registry	functions)*)BackendType)TensorPipeRpcBackendOptions)_server_process_global_profilerendezvous_iterator)init_rpcr7   r8   c           	      *   t           j                            d           |)t          |t          j                  st          d          |$t          |t                    st          d          |~||t
          D ]5}t          |t          t	          j	        |                              r|} n6t          d|           |t
          j
        k    rt                              dd|i           |t
          j
        }|t	          j	        |          }|st          j        ||          }n4t          j        |j        ||          at%          t"                    \  }}}|                    t)          |j        	                     t,          5  t          j        t1          d
t2                     |          }t2          dz  addd           n# 1 swxY w Y   t5          j        |           t9          |           t;          ||| |||           dS )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 zRPC 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;   \   s   F 	$$%ABBBz%1(
 (
 NOOO*:!24
 4
* W  
 ?2>%0  !'(F-    	 0GE	  P;NPP   +000E (   ?!,G&"2"P# #
  	4 34GNNEE #'/#/dz# # # 233KE1a),?,KLLLMMM   	 	$S)F})F)F%G%GOOEQM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	D!!!d###'5$jBUVVVVVs   5GGGc                 B   | t           j        |t          j        |t          |t
          j        |t
          j        t          d           f|t          i}|	                                D ]:\  }}t          ||          s%t          d| d| dt          |                     ;d S )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4:#'")4::6!2
 *//11 	 	MCc8,, "YYYhYYdSViiYY  	 	r   c                     t          | |||||           t                      rt          d          t          j        | |||||          }t          j        |           d S )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~     	7E4zCVWWW$&& 	=;<<< %1! 3
 
 
	 	Y'''''r   c                      t                      } |                     t          j                                                               |                     t          j                               | S )N)r$   updater3   r   get_debug_inforV   _get_debug_info)infos    r   rn   rn      sT    +--C.00??AABBBM133444r   )Nr<   NN)Wloggingos	threadingwarningscollections.abcr   datetimer   urllib.parser   r   torch.distributeddistributedrK   __all__	getLogger__name__rI   rU   LockrR   boolr   r   r	   rb   r
   _distributed_rpc_is_tensorpipe_availabler_   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/   r0   r   r1    r3   r4   r5   r7   optionsr8   server_process_global_profilerr9   tupleint__annotations__r;   rf   rH   rX   _require_initializedrn   r   r   r   <module>r      s0    				      % % % % % %       ! ! ! ! ! !              
 
	8	$	$ #Y^%% *d * * * * <>> E%(,,.. E
,C
D
DD <>> a&w!#E    NNN666666666000000                                                               B   
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 3222222222------444444NNNNNN"5S#94#EFFFFIIIIG#&6&>>G  uW uW uW uWn  " & ( ( ( (2 	    {a ar   