/usr/local/lib64/python3.6/site-packages/torch/distributed/rpc/__pycache__
NameSizeModeActions
api.cpython-36.pyc264700644editdlrm
backend_registry.cpython-36.pyc80290644editdlrm
constants.cpython-36.pyc6650644editdlrm
functions.cpython-36.pyc73980644editdlrm
internal.cpython-36.pyc79480644editdlrm
options.cpython-36.pyc69430644editdlrm
rref_proxy.cpython-36.pyc15850644editdlrm
server_process_global_profiler.cpython-36.pyc78390644editdlrm
__init__.cpython-36.pyc64090644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributed/rpc/__pycache__/internal.cpython-36.pyc (7948B)
3 Eg4)@sddlZddlZddlZddlZddlZddlZddlZddlmZddl Z ddl j Z ddl mZejaejZejZGdddeZGdddZeZdd Zd d Zd d ZddZddZddZejddddgZejdddgZ dS)N)Enum)_get_current_rpc_agentc@seZdZdZdZdZdZdS) RPCExecModesyncasyncZ async_jitremoteN)__name__ __module__ __qualname__ZSYNCASYNCZ ASYNC_JITZREMOTEr r J/usr/local/lib64/python3.6/site-packages/torch/distributed/rpc/internal.pyrsrc@steZdZdZddZddZeddZdd Zed d Z d d Z ddZ eddZ ddZ ddZddZdS)_InternalRPCPicklera  This class provides serialize() and deserialize() interfaces to serialize data to be "binary string + tensor table" format So for RPC python UDF function and args, non tensor data will be serialized into regular binary string, tensor data will be put into thread local tensor tables, this serialization format is consistent with builtin operator and args using JIT pickler. This format will make tensor handling in C++ much easier, e.g. attach tensor to distributed autograd graph in C++ cCs$tjj|_|j|jtj<i|_dS)N)copyregdispatch_tablecopy_dispatch_table_tensor_reducertorchZTensor_class_reducer_dict)selfr r r __init__(s z_InternalRPCPickler.__init__cCs||jkr||j|<dS)N)r)rZ obj_classreducerr r r _register_reducer/s z%_InternalRPCPickler._register_reducercCs tj|S)N)_thread_local_tensor_tables recv_tables)cls tensor_indexr r r _tensor_receiver4sz$_InternalRPCPickler._tensor_receivercCs&tjj|ttjd}tj|ffS)N)r send_tablesappendlenrr)rZtensorrr r r r9s z#_InternalRPCPickler._tensor_reducercCstjjj|S)N)distrpcPyRRefZ _deserialize)rrref_fork_datar r r _py_rref_receiver?sz%_InternalRPCPickler._py_rref_receivercCs|j}tj|ffS)N) _serializerr')rZpy_rrefr&r r r _py_rref_reducerCsz$_InternalRPCPickler._py_rref_reducercCs |j|S)N)r))rZrrefr r r _rref_reducerGsz!_InternalRPCPickler._rref_reducercCstj|}tjj|}|S)z Given a serialized representation of a ScriptModule created with torch.jit.save, loads and returns the ScriptModule. )ioBytesIOrjitload)rZscript_module_serializedfmr r r _script_module_receiverJs  z+_InternalRPCPickler._script_module_receivercCs&tj}tjj||tj|jffS)z, Serializes a ScriptModule. )r+r,rr-saverr1getvalue)rZ script_moduler/r r r _script_module_reducerTsz*_InternalRPCPickler._script_module_reducercCstj}t|}|j|_|j|jtjj<|j |jtjj <t |t j jrT|j|j|j<x"|jjD]}|j||j|<q`Wttdrtj}nd}gt_|j|tj}|dk r|t_nt`|j|fS)ze Serialize non tensor data into binary string, tensor data into tensor table r N)r+r,_picklerrrr)r#r$r%r*ZRRef isinstancerr-Z ScriptModuler4 __class__rkeyshasattrrr dumpr3)robjr/p class_nameZold_send_tablesZtensorsr r r serialize\s&   z_InternalRPCPickler.serializecCsttdrtj}nd}|t_yttj|}|j}Wn6tk rl}zt|d}t|}WYdd}~XnX|dk r~|t_nt`|S)zJ Deserialize binary string + tensor table to original obj rNz Default RPC pickler does not serialize function code. Ensure that UDFs are defined on both caller and callee modules.) r9rr _unpicklerr+r,r.AttributeErrorstr)r binary_data tensor_tableZold_recv_tablesZ unpicklerrete except_strr r r deserializes  z_InternalRPCPickler.deserializeN)rr r __doc__rr classmethodrrr'r)r*r1r4r>rGr r r r rs    5rcCs tj|S)N)_internal_rpc_picklerr>)r;r r r r>sr>cCs tj||S)N)rJrG)rBrCr r r rGsrGcCsy"t|tr||j|j|j}Wnbtk r}zFdtjdt|dt j }t |t j dt|t|}WYdd}~XnX|S)z This function is exclusively called from C++. See ``torch/csrc/distributed/rpc/python_rpc_handler.cpp``. Runs a Python UDF and returns its return value. Wraps any exception in ``RemoteException`` if the function raises. zOn z:  )fileN)r6r@funcargskwargs ExceptionrZget_worker_inforepr traceback format_excprintsysstderrRemoteExceptiontype)Z python_udfresultrErFr r r _run_functions $ rZcCs&t|tr"|j|jjdjddS)Nzutf-8Zunicode_escape)r6rWexception_typemsgencodedecode)rYr r r _handle_exceptions r_cCsdj|j|||d}|S)a Builds the key that RPC calls are profiled with using the autograd profiler. This will be the name of the corresponding Event recorded in the profiler. Args: exec_type (RPCExecMode): Type of RPC/RRef call func_name (str): Name of function being profiled. current_worker_name (str): Name of current worker. dst_worker_name (str): Name of the destination worker. Returns: String representing profiling key z {dst_worker}))Zrpc_type func_nameZcurrent_workerZ dst_worker)formatvalue) exec_typer`current_worker_nameZdst_worker_name profile_keyr r r _build_rpc_profiling_keys rfcCsDtjjstddj|jt|||}tjj}tjj|||S)ar This function should be called from RPC/RRef functions to create a RecordFunction object for profiling. This function also runs the before callbacks that start the profiling, though the user is responsible for running the appropriate callbacks when the function to be profiled finishes. Args: exec_type (RPCExecMode): Type of RPC/RRef call func_name (str): Name of function being profiled. current_worker_name (str): Name of current worker. dest_worker_name (str): Name of the destination worker. Returns: An instance of `torch.autograd._RecordFunction`. z$Autograd profiler should be enabled.zrpc_{}#{}({} -> {})) rZautogradZ_profiler_enabledAssertionErrorrarbrAZ_RecordFunctionZ_run_before_callbacks)rcr`rdZdest_worker_namererfr r r _start_record_functions  ri PythonUDFrMrNrOrWr\r[)! collectionsrr+picklerU threadingrRenumrrZtorch.distributedZ distributedr#Ztorch._C._distributed_rpcrlocalrPicklerr5 Unpicklerr?rrrJr>rGrZr_rfri namedtuplerjrWr r r r s2