
    Αi7                       S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	J
r
JrJr  S SKJr  S SKJr  S SKJrJr  S SKJr  \	(       a  S S	KJr  \" S
SS9r " S S\\   5      r\" S/ SQ5      rSrSrSrSqS qS r S r!S r"S r#S r$   S"         S#S jjr%SS\4           S$S jjr&SS\4           S%S jjr'S r(S r)S&S jr*S'S jr+S(S  jr,S)S! jr-g)*    )annotationsN)
namedtuple)TYPE_CHECKINGAnyProtocolTypeVar)core)Node)
PythonFunc
_serialize)logger)Callable_RetTT)	covariantc                      \ rS rSrSS jrSrg)_FutureWrapper"   c                    g N )selfs    Z/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/rpc/rpc.pywait_FutureWrapper.wait#   s        r   N)returnr   )__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r   "   s    $r   r   
WorkerInfo)namerankipportiic                    U q g r   _barrier_store)stores    r   _set_barrier_storer,   2   s    Nr   c                     B g r   r)   r   r   r   _del_barrier_storer.   7   s    r   c                    [         R                  " [        XX#5      5      n[        R	                  [        U5      U5        g r   )pickledumpsr"   r*   setstr)r#   r$   r%   r&   	self_infos        r   _set_self_infor5   <   s+    ZB=>Is4y),r   c                ,   / n[        5       n[        U 5       Hx  n[        R                  " [        R                  [        U5      5      5      nUR                  U;  d   S5       eUR                  UR                  5        UR                  U5        Mz     U$ )Nz:The Worker name must be unique, but name `{}` is repeated.)
r2   ranger0   loadsr*   getr3   r#   addappend)
world_size	all_infossr$   infos        r   _exchange_all_service_infosr@   A   s~    IAj!||N..s4y9:yy! 	
H	
! 	
dii " r   c                 d    [        5       n U R                  5       nU R                  5       nU SU 3$ )N:)r
   get_host_ipget_free_port)noder%   	free_ports      r   _gen_endpointrG   N   s6    6D				B""$IT9+r   c                   Uc  [        [        R                  S   5      OUnUc  [        [        R                  S   5      OUn[        R                  " SS5      nUc
  [	        5       n[
        R                  " SU SU 35        Ub  UO[        R                  S   nUR                  S5      u  pV[        U5      n[        [        R                  " S	S
5      5      n[        R                  " UUUS:H  UUS9n[        U5        UR                  S5      u  p[        U
5      n
[        XX5        [        U5      n/ nU HU  n[        R                  " UR                  UR                  UR                   UR"                  5      nUR%                  U5        MW     [        R&                  " X5        [        R(                  " 5         [+        X5        [        R,                  " 5         [
        R                  " SU S35        g)a  
init rpc. Warning: All RPC API should only be used internally within a secure network environment and
must not be accessible via the public internet.

Args:
    name (str): worker name.
    rank (int, optional): worker id, default is None.
    world_size (int, optional): number of workers, default is None.
    master_endpoint (str, optional): id address of master, other nodes communicate with the master to
        get the information of all worker nodes, default is None.

Returns:
    None.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc

        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...             master_endpoint="127.0.0.1:8001")

        >>> rpc.shutdown()

NPADDLE_TRAINER_IDPADDLE_TRAINERS_NUMPADDLE_WORKER_ENDPOINTTrainer z: worker endpoint: PADDLE_MASTER_ENDPOINTrB   FLAGS_stop_check_timeout900r   )timeoutz: Init RPC done!)intosenvirongetenvrG   r   r?   splitr	   TCPStorer,   r5   r@   r"   r#   r$   r%   r&   r;   init_and_set_agent_instancerpc_start_worker_barrier_never_timeoutrpc_start_client)r#   r$   r<   master_endpointworker_endpointmaster_addrmaster_portstop_check_timeoutr+   r%   r&   r=   c_infos	node_infor?   s                  r   init_rpcrb   U   s   @ 48<3rzz-./TD  	BJJ,-. 
 ii 8$?O'/
KK(4& 3O3DEF & 	ZZ01 
  /44S9Kk"KRYY'A5IJMM	"E u$$S)HBt9D4r(+J7IG	NNINNILL)..
 	t	 
 	$$T34,
KK(4& 012r   c                <    [        XX#U5      nUR                  5       $ )a  
Make a blocking RPC call to run function ``fn`` on worker ``to``. Warning: All RPC API should
only be used internally within a secure network environment and must not be accessible via
the public internet.

Args:
    to (str): name of the destination worker.
    fn (fn): a callable function, such as Python callables.
    args (tuple, optional): the argument tuple for the ``fn`` invocation, default is None.
    kwargs (dict, optional): is a dictionary of keyword arguments for the ``fn``
                   invocation, default is None.
    timeout (int, 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 less than or equal to 0
                               indicates an infinite timeout, i.e. a timeout
                               error will never be raised. The default value is -1.

Returns:
    Returns the result of running ``fn`` with ``args`` and ``kwargs``.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc

        >>> def add(a, b):
        ...     return a + b

        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...         master_endpoint="127.0.0.1:8002")

        >>> ret = rpc.rpc_sync("worker0", add, args=(2, 3))
        >>> rpc.shutdown()

)_invoke_rpcr   )tofnargskwargsrP   futs         r   rpc_syncrj      s    X bdG
4C88:r   c                    [        XX#U5      $ )a_  
Make a non-blocking RPC call to run function ``fn`` on worker ``to``. Warning: All RPC API should
only be used internally within a secure network environment and must not be accessible via the public internet.

Args:
    to (str): name of the destination worker.
    fn (fn): a callable function, such as Python callables.
    args (tuple, optional): the argument tuple for the ``fn`` invocation, default is None.
    kwargs (dict, optional): is a dictionary of keyword arguments for the ``fn``
                   invocation, default is None.
    timeout (int, 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 less than or equal to 0
                               indicates an infinite timeout, i.e. a timeout
                               error will never be raised. The default value is -1.

Returns:
    Returns a :class:`FutureWrapper` object that can be waited
    on. When completed, the return value of ``fn`` on ``args`` and
    ``kwargs`` can be got by `fut.wait()`.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc

        >>> def add(a, b):
        ...     return a + b

        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...         master_endpoint="127.0.0.1:8003")

        >>> fut = rpc.rpc_async("worker0", add, args=(2, 3))
        >>> print(fut.wait())
        5

        >>> rpc.shutdown()

)rd   )re   rf   rg   rh   rP   s        r   	rpc_asyncrl      s    ` rtW55r   c                    U(       a  UOSnU(       a  UO0 n[        [        XU5      5      nUS-  nUS::  a  [        OUn[        R                  " XU5      nU$ )Nr   i  r   )r   r   _MAX_RPC_TIMEOUT_MSr	   
invoke_rpc)re   rf   rg   rh   rP   
serial_obj
timeout_msfutures           r   rd   rd     sQ    4RDV2FJr89J4J(2a$ZJ__RZ8FMr   c                  ^ ^ [         R                  " [        S9mUS:  a  g S[        [        5      -   S-   n[        S-  qT S:H  nU U4S jnU(       aR  [        SU5       Vs/ s H  oR[        U5      -   PM     nn[        R                  U[        S5      -   S5        U" U5        g U[        S5      -   /nU" U5        [        R                  U[        T 5      -   S5        g s  snf )N)days   zBarrier//   r   c                N  > [         R                   " 5       n[        U 5      S:  a  [         R                  " S5        [         R                   " 5       U-
  n[        R                  " US9T:  a  [        SU  ST S35      e[        [        S U 5      5      n [        U 5      S:  a  M  g g )Nr   g?)secondszKeys z are not ready since rank z is waiting them.c                D    [        [        R                  U 5      5      S:g  $ )Nrw   )rQ   r*   r9   )keys    r   <lambda>C_barrier_never_timeout.<locals>._check_keys_ready.<locals>.<lambda>$  s    3~'9'9#'>#?1#Dr   )timelensleepdatetime	timedeltaRuntimeErrorlistfilter)	wait_keys
start_timeelapse_timeglobal_rankrP   s      r   _check_keys_ready1_barrier_never_timeout.<locals>._check_keys_ready  s    YY[
)nq JJsO))+
2K!!+6@"I;&@M^_  DiPI )nq r   )r   r   _BARRIER_TIMEOUT_MAX_DAYSr3   _barrier_countr7   r*   r:   )r   global_world_sizebarrier_prefix	is_masterr   r$   r   rP   s   `      @r   rY   rY     s      &?@G1  #n"55;NaNq I  49<M3N
3N4SY&3N 	 
 	>CF2A6)$#c!f,-	)$>C,<<a@
s   !Cc                     [        5       n U R                  n[        [        5       5      n[	        X5        [
        R                  " 5         [        5         [        R                  " SU S35        g)a  
Perform a shutdown of the RPC agent, stop the worker and destroy the agent.
This will block until all local and remote RPC processes reach this method
and wait for all outstanding work to complete. Warning: All RPC API should
only be used internally within a secure network environment and must not be
accessible via the public internet.

Returns:
    None.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc

        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...             master_endpoint="127.0.0.1:8004")

        >>> rpc.shutdown()

rL   z: rpc shutdown!N)
get_current_worker_infor$   r   get_all_worker_infosrY   r	   rpc_stop_workerr.   r   r?   )r?   r$   r<   s      r   shutdownr   5  sR    . #$D99D)+,J4,
KK(4&01r   c                .    [         R                  " U 5      $ )a  
Get worker information by worker name. Warning: All RPC API should
only be used internally within a secure network environment and must
not be accessible via the public internet.

Args:
    name (str): name of the worker.

Returns:
    class `WorkerInfo` with attribute `name`, `rank`, `ip` and `port`.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc
        >>> import os

        >>> os.environ["PADDLE_WORKER_ENDPOINT"] = "127.0.0.1:9002"
        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...             master_endpoint="127.0.0.1:8005")

        >>> print(rpc.get_worker_info("worker0"))
        {name: worker0, rank: 0, ip: 127.0.0.1, port: 9002}

        >>> rpc.shutdown()

)r	   rpc_get_worker_info)r#   s    r   get_worker_infor   V  s    : ##D))r   c                 ,    [         R                  " 5       $ )a  
Get all worker information. Warning: All RPC API should only be used
internally within a secure network environment and must not be
accessible via the public internet.

Returns:
    List[WorkerInfo].

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc
        >>> import os

        >>> os.environ["PADDLE_WORKER_ENDPOINT"] = "127.0.0.1:9003"
        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...         master_endpoint="127.0.0.1:8006")

        >>> print(rpc.get_all_worker_infos())
        [{name: worker0, rank: 0, ip: 127.0.0.1, port: 9003}]

        >>> rpc.shutdown()

)r	   rpc_get_all_worker_infosr   r   r   r   r   v  s    4 ((**r   c                 ,    [         R                  " 5       $ )a  
Get current worker information. Warning: All RPC API should only be used internally
within a secure network environment and must not be accessible via the public internet.

Returns:
    class `WorkerInfo` with attribute `name`, `rank`, `ip` and `port`.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> import paddle.distributed.rpc as rpc
        >>> import os

        >>> os.environ["PADDLE_WORKER_ENDPOINT"] = "127.0.0.1:9004"
        >>> rpc.init_rpc("worker0", rank=0, world_size=1,
        ...             master_endpoint="127.0.0.1:8007")

        >>> print(rpc.get_current_worker_info())
        {name: worker0, rank: 0, ip: 127.0.0.1, port: 9004}

        >>> rpc.shutdown()

)r	   rpc_get_current_worker_infor   r   r   r   r     s    2 ++--r   )NNN)
r#   r3   r$   
int | Noner<   r   r[   z
str | Noner   None)re   r3   rf   Callable[..., _RetT]rg   tuple[Any, ...] | Nonerh   dict[str, Any] | NonerP   rQ   r   r   )re   r3   rf   r   rg   r   rh   r   rP   rQ   r   z_FutureWrapper[_RetT])r   r   )r#   r3   r   r"   )r   zlist[WorkerInfo])r   r"   ).
__future__r   r   rR   r0   r~   collectionsr   typingr   r   r   r   paddle.baser	   !paddle.distributed.launch.contextr
   paddle.distributed.rpc.internalr   r   %paddle.distributed.utils.launch_utilsr   collections.abcr   r   r   r"   _DEFAULT_RPC_TIMEOUTrn   r   r*   r   r,   r.   r5   r@   rG   rb   rj   rl   rd   rY   r   r   r   r   r   r   r   <module>r      s   #  	   " 8 8  2 B 8(Gt,E%% % &DE
   $  

-

 !"&	I3
I3
I3 I3  	I3
 
I3^ $($('--- !- "	-
 - -f $($('060606 !06 "	06
 06 06f$AN2B*@+:.r   