o
    Hh%                     @   s  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 eZd ae ZdefddZe rNe
j sNede r	d dlZd dlm  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lCT ddlDmFZF ddlGmHZH ddlImJZJ eeKeeLeLf ddf eMd< eg d7 ZeeCj eDj Z				dddZNdd ZOeFjPdddddfddZQeCjRdd ZSdS dS )    N)	Generator)	timedelta)urlparseis_availablereturnc                   C   s   t tjdS )N	_rpc_init)hasattrtorch_C r   r   R/var/www/vscode/kcb/lib/python3.10/site-packages/torch/distributed/rpc/__init__.pyr      s   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_rpcr4   r5   c                 C   sn  t jd |durt|tjstd|dur!t|ts!td|du rP|durPtD ]}t|tt	|r;|} nq+td| |tj
krPtdd|i |du rWtj
}|du r`t	|}|sit||}ntj|j||datt\}}}|t|jd	 t ttd
t |}td7 aW d   n1 sw   Y  t| t| 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_r/   )r	   r
   _log_api_usage_once
isinstancer1   r4   	TypeErrorr,   typeconstruct_rpc_backend_options
TENSORPIPEloggerwarningdist_create_store_from_options
rendezvousinit_methodr7   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_r   r   r   r8   T   sh   #




r8   c           	      C   sj   | t j|tj|t|tj|tjtd f|ti}|	 D ]\}}t
||s2td| d| dt| qd S )Nz	Argument z must be of type z but got type )r1   r4   rG   r   rP   numbersIntegralrB   r,   itemsr@   RuntimeError)	r:   rX   rU   r;   r<   rV   type_mappingargarg_typer   r   r   _validate_rpc_args   s   	
ra   c                 C   sD   t | ||||| t rtdtj| |||||d}t| d S )NzRPC is already initialized)rX   rU   r;   r<   rV   )ra   r   r]   r1   init_backendr0   _init_rpc_states)r:   rX   rU   r;   r<   rV   	rpc_agentr   r   r   rT      s   	rT   c                  C   s*   t  } | t   | t  | S )N)r!   updater0   r   get_debug_inforR   _get_debug_info)infor   r   r   rg      s   rg   )Nr9   NN)Tloggingos	threadingwarningscollections.abcr   datetimer   urllib.parser   r	   torch.distributeddistributedrG   __all__	getLogger__name__rE   rQ   LockrN   boolr   r
   r   r]   rZ   torch.distributed.autogradautogradrR   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,   r-   r.    r0   r1   r2   r4   optionsr5   server_process_global_profilerr6   tupleint__annotations__r8   ra   rD   rT   _require_initializedrg   r   r   r   r   <module>   s\   

$
w
 