o
    hY
                     @   st   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 dlm	Z	 dd	 Z
ejd
d Zdd ZG dd dZdS )    )partial   )	functions)	rpc_asyncN)UNSET_RPC_TIMEOUT)Futurec                 C      t |  ||i |S Ngetattrlocal_valuerref	func_nameargskwargs r   V/var/www/html/ai/venv/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                    st   	fddj 	dd}tkr|  |S t  fdd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_cont2      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.   8   r1   z!_invoke_rpc.<locals>._complete_opc                    s    | S r	   r   )r,   )r0   r   r   <lambda>>   s    z_invoke_rpc.<locals>.<lambda>)	_get_typer   waitr   r(   )r   r%   r   r   r   r   r    r   )
r.   r&   r0   r   r   r   r/   r%   r   r   r   _invoke_rpc   s   r6   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__D   s   
zRRefProxy.__init__c                 C   s   t t| j| j|| jS r	   )r   r6   r   r%   r8   )r9   r   r   r   r   __getattr__I   s   zRRefProxy.__getattr__N)__name__
__module____qualname__r   r:   r;   r   r   r   r   r7   C   s    r7   )	functoolsr    r   r   r   	constantsr   torch.futuresr   r   async_executionr   r6   r7   r   r   r   r   <module>   s    
2