o
    Hhq
                     @   sl   d dl mZ d dlZd dlmZ ddlmZmZ ddlm	Z	 dd Z
ejd	d
 Zdd ZG dd dZdS )    )partialN)Future   )	functions	rpc_async)UNSET_RPC_TIMEOUTc                 C      t |  ||i |S Ngetattrlocal_valuerref	func_nameargskwargs r   T/var/www/vscode/kcb/lib/python3.10/site-packages/torch/distributed/rpc/rref_proxy.py_local_invoke   s   r   c                 C   r   r	   r
   r   r   r   r   _local_invoke_async_execution   s   r   c                    sl   fddj dd}tkr|  |S t  fdd}fdd || S )	Nc                    s`   |   }t}t|tjjpt|tjj}|s"t|}t|dr"t	}
 | fdS )N_wrapped_async_rpc_function)r   timeout)valuer   
issubclasstorchjitScriptModule_Cr   hasattrr   owner)rref_fut	rref_type_invoke_funcbypass_typefunc)r   r   r   rpc_apir   r   r   r   _rref_type_cont   s   


z$_invoke_rpc.<locals>._rref_type_contF)r   blockingc              
      sF   z
|    W d S  ty" } z| W Y d }~d S d }~ww r	   )thenBaseExceptionset_exceptionfutex)_complete_opr&   resultr   r   _wrap_rref_type_cont5      z)_invoke_rpc.<locals>._wrap_rref_type_contc              
      sF   z
  |   W d S  ty" } z | W Y d }~d S d }~ww r	   )
set_resultr   r)   r*   r+   )r/   r   r   r.   ;   r1   z!_invoke_rpc.<locals>._complete_op)	_get_typer   waitr   r(   )r   r%   r   r   r   r   r    r0   r   )	r.   r&   r   r   r   r/   r%   r   r   r   _invoke_rpc   s   
r5   c                   @   s    e Zd ZefddZdd ZdS )	RRefProxyc                 C   s   || _ || _|| _d S r	   )r   r%   rpc_timeout)selfr   r%   r   r   r   r   __init__H   s   
zRRefProxy.__init__c                 C   s   t t| j| j|| jS r	   )r   r5   r   r%   r7   )r8   r   r   r   r   __getattr__M   s   zRRefProxy.__getattr__N)__name__
__module____qualname__r   r9   r:   r   r   r   r   r6   G   s    r6   )	functoolsr   r   torch.futuresr    r   r   	constantsr   r   async_executionr   r5   r6   r   r   r   r   <module>   s   
3