/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__/api.cpython-36.pyc (26470B)
3 Eg@ @s$UddlZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z ddl Z ddl mZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(ej)e*Z+dZ,e$a-ej.d d Z/d d Z0Gd dde1Z2e3a4e e 4ej5Z6iZ7ee8e9f7ej:e2Z;ej:;ddZej?Z@ej.ddZAe0de(fddZBe0ddZCe0ddZDe0dCddZEdd ZFe0dDd!d"ZGd#d$ZHdEd%d&ZIe(dfd'd(ZJe d)ZKeeKZLyGd*d+d+eeeKZMWnBeNk rNGd,d-d-ejOeLjOZPGd.d+d+eeLePd/ZMYnXd0d1ZQxrejReD]d\ZSZTeSjUd2reSd3krqdeVeTd4dZWeWdk stXd5eWjYd6d7ZWeQeSeWZZe[eMeSeZqdWe0dde(fd8d9Z\dde(fd:d;Z]e0dde(fdd?Z_d@dAZ`dS)FN)DictGenericTypeVarSetAny)Future)PyRRefRemoteProfilerManager WorkerInfoget_rpc_timeout_cleanup_python_rpc_handler)_delete_all_user_and_unforked_owner_rrefs_destroy_rref_context_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_set_and_start_rpc_agent) PythonUDF RPCExecMode_internal_rpc_pickler_build_rpc_profiling_key)DEFAULT_SHUTDOWN_TIMEOUTUNSET_RPC_TIMEOUTTc cs|az dVWdtaXdS)zX rpc_pickler: (.internal._InternalRPCPickler) Overrides the default RPC pickler N)_default_picklerr)Z rpc_picklerr!E/usr/local/lib64/python3.6/site-packages/torch/distributed/rpc/api.py_use_rpc_pickler8s r#cstjfdd}|S)Ncststd||S)NzHRPC has not been initialized. Call torch.distributed.rpc.init_rpc first.)r RuntimeError)argskwargs)funcr!r"wrapperFsz%_require_initialized..wrapper) functoolswraps)r'r(r!)r'r"_require_initializedEs r+c@seZdZddZdS)AllGatherStatescCsi|_tj|_dS)N)gathered_objects threadingEventproceed_signal)selfr!r!r"__init__Ss zAllGatherStates.__init__N)__name__ __module__ __qualname__r2r!r!r!r"r,Rsr,cCs(|j}dd|Dats$t|dS)NcSsh|] }|jqSr!)name).0Z worker_infor!r!r" nsz#_init_rpc_states..)Zget_worker_infos_ALL_WORKER_NAMESrr)ZagentZ worker_infosr!r!r"_init_rpc_statesksr:c Cs~tp|s$t}||ks$t|dt|}||jksJt|d|d||j|<|t|jjkrp|jjWdQRXdS)Nz is not expected by leader.z reported intent sequence id z twice. )_all_gather_dict_lockr9AssertionError!_all_gather_sequence_id_to_statesr-setkeysr0) sequence_id worker_nameobj worker_namesstatesr!r!r"_gather_to_leaderus    rEc CsFtt|}WdQRX|jj s2tdj|||_|jjdS)Nz0Termination signal sequence id {} got set twice.)r;r=r0is_setr<formatr-r>)r@Z objects_maprDr!r!r"_broadcast_to_followerss  rHccs2gt_z dVWdztjjtjWdt`XXdS)aO A context manager that collects all futures returned by ``rpc_async`` and waits them on the context manager's exit; relieving the user of needing to explicitly call wait. Example:: >>> # On worker 0: >>> import torch >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> with rpc._wait_all(): >>> fut_1 = rpc.rpc_async(dst, torch.add, (torch.ones(2, 2), 1)) >>> fut_2 = rpc.rpc_async(dst, torch.add, (torch.ones(2, 2), 1)) >>> #fut_1 and fut_2 are waited on N)_thread_local_var future_listtorchfuturesZwait_allr!r!r!r" _wait_alls  rMcCs|stdk stdt}t|d}tjj}t8djt|}tj |d}|dt|<|t |}WdQRX||k}|t krt }|rt ||||nt|t ||||f|dtt|} WdQRX| jj|rt} x0||hD]"} t| t|| jf|d} | | | <qWg} xV| jD]J\} } y | jWn2tk rh}z| j| |fWYdd}~XnXq"W| rtddd | Dd |d d | ddttj|} WdQRX| jS) a This is similar to torch.distributed.all_gather(), but is using RPC. It picks the worker with the smallest name (alphabetic order) as the leader. Then all followers send their data ``obj`` to the leader. After the leader has received all, it will broadcast the results back to all followers. This function blocks until all workers have received the gathered results. Nz=`_ALL_WORKER_NAMES` is not initialized for `def _all_gather`.rr)r%timeoutz Followers cSsg|] }|dqS)rr!)r7er!r!r" sz_all_gather..z timed out in _all_gather after z.2fz! seconds. The first exception is )r9r<sortedrget_worker_infor6r;join_all_gather_sequence_idgetstrrr rErpc_syncr=r0waitdict rpc_asyncrHr-itemsr$appendpop)rBrCrOZ leader_nameZ self_nameZ concat_namesZ sequence_numr@Z is_leaderrDZ#worker_name_to_response_future_dictZ follower_namefuterrorsexr!r!r" _all_gathersZ          &,rbcCsJytdt|Wn2tk rD}ztjd|WYdd}~XnXdS)a& Synchronizes local and remote RPC processes. This will block until all local and remote RPC processes specified under worker_names reach this method to wait for all outstanding work to complete. Args: worker_names (List[str]): The set of workers to synchronize. Nz&Failed to complete barrier, got error )rbr>r$loggererror)rCrar!r!r"_barriers recCsLytdtdWn6tk rF}ztjd||WYdd}~XnXdS)ag Block until all local and remote RPC processes reach this method and wait for all outstanding work to complete. Every RPC process must call this method before exit to perform a graceful shutdown. This should be used to terminate the RPC framework, and there is no guarantee that the RPC framework will work after this method returns. N)rOz;Failed to respond to 'Shutdown Proceed' in time, got error )rbrr$rcrd)rar!r!r"_wait_all_workers s  rfc Cs8|r.ztttjddWdtXntdS)a Perform a shutdown of the RPC agent, and then destroy the RPC agent. This stops the local agent from accepting outstanding requests, and shuts down the RPC framework by terminating all RPC threads. If ``graceful=True``, this will block until all local and remote RPC processes reach this method and wait for all outstanding work to complete. Otherwise, if ``graceful=False``, this is a local shutdown, and it does not wait for other RPC processes to reach this method. .. warning:: For :class:`~torch.futures.Future` objects returned by :meth:`~torch.distributed.rpc.rpc_async`, ``future.wait()`` should not be called after ``shutdown()``. Args: graceful (bool): Whether to do a graceful shutdown or not. If True, this will 1) wait until there is no pending system messages for ``UserRRefs`` and delete them; 2) block until all local and remote RPC processes have reached this method and wait for all outstanding work to complete. Example:: Make sure that ``MASTER_ADDR`` and ``MASTER_PORT`` are set properly on both workers. Refer to :meth:`~torch.distributed.init_process_group` API for more details. For example, >>> export MASTER_ADDR=localhost >>> export MASTER_PORT=5678 Then run the following code in two different processes: >>> # On worker 0: >>> import torch >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> # do some work >>> result = rpc.rpc_sync("worker1", torch.add, args=(torch.ones(1), 1)) >>> # ready to shutdown >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> # wait for worker 0 to finish work, and then shutdown. >>> rpc.shutdown() T)shutdownN)rfr rrT_finalize_shutdown)Zgracefulr!r!r"rgs1 rgc Cs*z ttWdtjttXdS)N)r_ignore_rref_leakrrgr rr!r!r!r"rhYs   rhcCs"|dk rtj|StjSdS)aI Get :class:`~torch.distributed.rpc.WorkerInfo` of a given worker name. Use this :class:`~torch.distributed.rpc.WorkerInfo` to avoid passing an expensive string on every invocation. Args: worker_name (str): the string name of a worker. If ``None``, return the the id of the current worker. (default ``None``) Returns: :class:`~torch.distributed.rpc.WorkerInfo` instance for the given ``worker_name`` or :class:`~torch.distributed.rpc.WorkerInfo` of the current worker if ``worker_name`` is ``None``. N)rrS)rAr!r!r"rSms rScCs<t|tr|St|ts"t|tr*t|Stdj|dS)Nz"Cannot get WorkerInfo from name {}) isinstancer rWintrS ValueErrorrG)tor!r!r"_to_worker_infos  rncCs0t|j}|r|Stt}|j||SdS)N)typeZ local_valuer set_result)rrefblockingZ rref_typefuturer!r!r"_rref_typeof_on_owners    rtcCs*t|jt|f|d}|r"|jS|SdS)N)r%rO)r[ownerrtrY)rqrOrrr_r!r!r"_rref_typeof_on_usersrvTc@s eZdZdS)RRefN)r3r4r5r!r!r!r"rxsrxc@s eZdZdS)RRefMetaN)r3r4r5r!r!r!r"rysryc@s eZdZdS)rxN)r3r4r5r!r!r!r"rxs) metaclasscsfdd}||_|S)Ncsttt|||S)N)getattrsuperrx)r1r%r&) method_namer!r"methodszmethod_factory..method)__doc__)r} docstringr~r!)r}r"method_factorys r___str__rz4RRef user-facing methods should all have docstrings.ztorch.distributed.rpc.PyRRefztorch.distributed.rpc.RRefc Cs2tjjj|}t|}tjj}t|||tj |}|} |r@|nf}|rL|ni}t |d} | rv|j } t | tjj rv| }|dk rt|||f||} nVt |tjj rt|jtjj||| f||} n&tjt|||\} }t|| ||| } |r$tjjst| dk s t| j| j}| j|WdQRX| S)a4 Make a remote call to run ``func`` on worker ``to`` and return an :class:`~torch.distributed.rpc.RRef` to the result value immediately. Worker ``to`` will be the owner of the returned :class:`~torch.distributed.rpc.RRef`, and the worker calling ``remote`` is a user. The owner manages the global reference count of its :class:`~torch.distributed.rpc.RRef`, and the owner :class:`~torch.distributed.rpc.RRef` is only destructed when globally there are no living references to it. Args: to (str or WorkerInfo or int): name/rank/``WorkerInfo`` of the destination worker. func (callable): a callable function, such as Python callables, builtin operators (e.g. :meth:`~torch.add`) and annotated TorchScript functions. args (tuple): the argument tuple for the ``func`` invocation. kwargs (dict): is a dictionary of keyword arguments for the ``func`` invocation. timeout (float, optional): timeout in seconds for this remote call. If the creation of this :class:`~torch.distributed.rpc.RRef` on worker ``to`` is not successfully processed on this worker within this timeout, then the next time there is an attempt to use the RRef (such as ``to_here()``), a timeout will be raised indicating this failure. A value of 0 indicates an infinite timeout, i.e. a timeout error will never be raised. If not provided, the default value set during initialization or with ``_set_rpc_timeout`` is used. Returns: A user :class:`~torch.distributed.rpc.RRef` instance to the result value. Use the blocking API :meth:`torch.distributed.rpc.RRef.to_here` to retrieve the result value locally. .. warning :: The ``remote`` API does not copy storages of argument tensors until sending them over the wire, which could be done by a different thread depending on the RPC backend type. The caller should make sure that the contents of those tensors stay intact until the returned RRef is confirmed by the owner, which can be checked using the :meth:`torch.distributed.rpc.RRef.confirmed_by_owner` API. .. warning :: Errors such as timeouts for the ``remote`` API are handled on a best-effort basis. This means that when remote calls initiated by ``remote`` fail, such as with a timeout error, we take a best-effort approach to error handling. This means that errors are handled and set on the resulting RRef on an asynchronous basis. If the RRef has not been used by the application before this handling (such as ``to_here`` or fork call), then future uses of the ``RRef`` will appropriately raise errors. However, it is possible that the user application will use the ``RRef`` before the errors are handled. In this case, errors may not be raised as they have not yet been handled. Example:: Make sure that ``MASTER_ADDR`` and ``MASTER_PORT`` are set properly on both workers. Refer to :meth:`~torch.distributed.init_process_group` API for more details. For example, >>> export MASTER_ADDR=localhost >>> export MASTER_PORT=5678 Then run the following code in two different processes: >>> # On worker 0: >>> import torch >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> rref1 = rpc.remote("worker1", torch.add, args=(torch.ones(2), 3)) >>> rref2 = rpc.remote("worker1", torch.add, args=(torch.ones(2), 1)) >>> x = rref1.to_here() + rref2.to_here() >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() Below is an example of running a TorchScript function using RPC. >>> # On both workers: >>> @torch.jit.script >>> def my_script_add(t1, t2): >>> return torch.add(t1, t2) >>> # On worker 0: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> rref = rpc.remote("worker1", my_script_add, args=(torch.ones(2), 3)) >>> rref.to_here() >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() _wrapped_async_rpc_functionN)rKjit _builtins _find_builtinrnautograd_profiler_enabled_enable_rpc_profilerrZREMOTEhasattrrrjScriptFunctionrrr6 _jit_internal_qualified_namer serializerrr<_call_end_callbacks_on_futureZ _get_futureZ_set_profiling_future)rmr'r%r&rOqualified_namedst_worker_infoshould_profile ctx_managerrf is_async_execwrappedrqpickled_python_udftensorsr_r!r!r"remotesHf     rcCs0t|stdtjjj|}t|}tjj}t |||||} | } |rN|nf}|rZ|ni}t |d} | r|j } t | tjj r| }|dk rt|||f||} nRt |tjj rt|jtjj||||| } n&tjt|||\}}t||||| } |r"tjjs t| dk st| j| } WdQRX| S)Nzfunction should be callable.r)callable TypeErrorrKrrrrnrrrrrrjrrrr6rrr rrrr<r)rmr'rpc_typer%r&Z rpc_timeoutrrrrrrrr_rrr!r!r" _invoke_rpczsT     rcCst||tj|||}|jS)a Make a blocking RPC call to run function ``func`` on worker ``to``. RPC messages are sent and received in parallel to execution of Python code. This method is thread-safe. Args: to (str or WorkerInfo or int): name/rank/``WorkerInfo`` of the destination worker. func (callable): a callable function, such as Python callables, builtin operators (e.g. :meth:`~torch.add`) and annotated TorchScript functions. args (tuple): the argument tuple for the ``func`` invocation. kwargs (dict): is a dictionary of keyword arguments for the ``func`` invocation. timeout (float, optional): timeout in seconds to use for this RPC. If the RPC does not complete in this amount of time, an exception indicating it has timed out will be raised. A value of 0 indicates an infinite timeout, i.e. a timeout error will never be raised. If not provided, the default value set during initialization or with ``_set_rpc_timeout`` is used. Returns: Returns the result of running ``func`` with ``args`` and ``kwargs``. Example:: Make sure that ``MASTER_ADDR`` and ``MASTER_PORT`` are set properly on both workers. Refer to :meth:`~torch.distributed.init_process_group` API for more details. For example, >>> export MASTER_ADDR=localhost >>> export MASTER_PORT=5678 Then run the following code in two different processes: >>> # On worker 0: >>> import torch >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> ret = rpc.rpc_sync("worker1", torch.add, args=(torch.ones(2), 3)) >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() Below is an example of running a TorchScript function using RPC. >>> # On both workers: >>> @torch.jit.script >>> def my_script_add(t1, t2): >>> return torch.add(t1, t2) >>> # On worker 0: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> ret = rpc.rpc_sync("worker1", my_script_add, args=(torch.ones(2), 3)) >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() )rrZSYNCrY)rmr'r%r&rOr_r!r!r"rXsDrXcCs.t||tj|||}ttdr*tjj||S)a Make a non-blocking RPC call to run function ``func`` on worker ``to``. RPC messages are sent and received in parallel to execution of Python code. This method is thread-safe. This method will immediately return a :class:`~torch.futures.Future` that can be awaited on. Args: to (str or WorkerInfo or int): name/rank/``WorkerInfo`` of the destination worker. func (callable): a callable function, such as Python callables, builtin operators (e.g. :meth:`~torch.add`) and annotated TorchScript functions. args (tuple): the argument tuple for the ``func`` invocation. kwargs (dict): is a dictionary of keyword arguments for the ``func`` invocation. timeout (float, optional): timeout in seconds to use for this RPC. If the RPC does not complete in this amount of time, an exception indicating it has timed out will be raised. A value of 0 indicates an infinite timeout, i.e. a timeout error will never be raised. If not provided, the default value set during initialization or with ``_set_rpc_timeout`` is used. Returns: Returns a :class:`~torch.futures.Future` object that can be waited on. When completed, the return value of ``func`` on ``args`` and ``kwargs`` can be retrieved from the :class:`~torch.futures.Future` object. .. warning :: Using GPU tensors as arguments or return values of ``func`` is not supported since we don't support sending GPU tensors over the wire. You need to explicitly copy GPU tensors to CPU before using them as arguments or return values of ``func``. .. warning :: The ``rpc_async`` API does not copy storages of argument tensors until sending them over the wire, which could be done by a different thread depending on the RPC backend type. The caller should make sure that the contents of those tensors stay intact until the returned :class:`~torch.futures.Future` completes. Example:: Make sure that ``MASTER_ADDR`` and ``MASTER_PORT`` are set properly on both workers. Refer to :meth:`~torch.distributed.init_process_group` API for more details. For example, >>> export MASTER_ADDR=localhost >>> export MASTER_PORT=5678 Then run the following code in two different processes: >>> # On worker 0: >>> import torch >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> fut1 = rpc.rpc_async("worker1", torch.add, args=(torch.ones(2), 3)) >>> fut2 = rpc.rpc_async("worker1", min, args=(1, 2)) >>> result = fut1.wait() + fut2.wait() >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() Below is an example of running a TorchScript function using RPC. >>> # On both workers: >>> @torch.jit.script >>> def my_script_add(t1, t2): >>> return torch.add(t1, t2) >>> # On worker 0: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker0", rank=0, world_size=2) >>> fut = rpc.rpc_async("worker1", my_script_add, args=(torch.ones(2), 3)) >>> ret = fut.wait() >>> rpc.shutdown() >>> # On worker 1: >>> import torch.distributed.rpc as rpc >>> rpc.init_rpc("worker1", rank=1, world_size=2) >>> rpc.shutdown() rJ)rrASYNCrrIrJr])rmr'r%r&rOr_r!r!r"r[sX  r[cCsjtj}|rf|dkr6t|tjjr.tjj|n|j}n|}t ||t j |j }t j |tjjj|}|S)N) contextlibsuppressrjrKrrrrr5rrSr6r Zset_current_profiling_keyrZprofilerZrecord_function)rrr'rrr func_nameZrpc_profiling_keyr!r!r"r^s r)N)T)N)T)a collectionsrr)inspectloggingr.typingrrrrrrKZ torch.futuresrZtorch._C._distributed_rpcrr r r r r rrrrrrrrrrrZinternalrrrr constantsrr getLoggerr3rcrir contextmanagerr#r+objectr,r>r9RLockr;rUrWrk defaultdictr=r:rErHlocalrIrMrbrerfrgrhrSrnrtrvrwZGenericWithOneTypeVarrxr __class__ryr getmembersr}r~ startswithr{rr<replaceZ new_methodsetattrrrrXr[rr!r!r!r"s L     K   ;      >G]