
    קg                     8    d dl mZmZ d dlZ G d d          ZdS )    )OptionalUnionNc                       e Zd ZdZdeeej        f         fdZe	d             Z
dee         fdZdee         fdZdej        fdZd	 Zd
 Zd ZdS )_remote_devicea@  
    Represents a device on a remote worker.

    Args:
        remote_device (str or torch.device): Represents a device on a remote worker.
            The string format should be one of the following:

                1. "<workername>/<device>", where the device field can be parsed as torch.device type.
                   E.g., "trainer0/cpu", "trainer0", "ps0/cuda:0".
                   In addition, the device field can be optional and the default value is "cpu".
                2. "rank:<rank>/<device>", where <rank> is the rank of the
                   process and device can be parsed as torch.device type.
                   E.g., "rank:0/cpu", "rank:0", "rank:0/cuda:0"
                3. <workername> and <rank> are optional and formats like "cpu"
                    and "cuda:1", just represent local devices.
    remote_devicec                    d| d}d | _         d | _        d | _        t          |t          j                  r|| _        nt          |t                    r|                    d          }t          |          dk    r|\  | _         | _        nt          |          dk    rCt          
                    |d                   r|d         | _        nC|d         | _         d| _        n.t          |          t          dt          |                     | j         | j         st          |          t	          j        | j                  | _        | j         | j                             d	          }t          |          dk    rX|d         d
k    r=|d                                         r#t          |d                   | _        d | _         d S t          |          t          |          dk    rt          |          d S d S )NzCould not parse remote_device: zU. The valid format is '<workername>/<device>' or 'rank:<rank>/<device>' or '<device>'/      r   cpuz Invalid type for remote_device: :rank)_worker_name_rank_device
isinstancetorchdevicestrsplitlenr   _is_valid_local_device
ValueError	TypeErrortypeisdigitint)selfr   PARSE_ERRORfieldss       [/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/distributed/remote_device.py__init__z_remote_device.__init__   s   Nm N N N 	 !
@DmU\22 	V(DLLs++ 	V"((--F6{{a28/!4<<V!!!88CC )#)!9DLL(.q	D%#(DLL ---TtM?R?RTTUUU (1B([))) |DL11 (&,,S11F6{{a!9&&6!9+<+<+>+>&!$VAYDJ(,D%%%$[111Vq --- )( !    c                 R    	 t          j        |            dS # t          $ r Y dS w xY w)NTF)r   r   	Exception)r   s    r!   r   z%_remote_device._is_valid_local_deviceH   s>    	L   4 	 	 	55	s    
&&returnc                     | j         S )zlReturn the name of remote worker representing the remote device and ``None`` if no worker name is available.)r   r   s    r!   worker_namez_remote_device.worker_nameQ   s      r#   c                     | j         S )z
        Returns the rank of remote worker representing the remote device.
        Returns ``None`` if no rank is available.
        )r   r(   s    r!   r   z_remote_device.rankU   s    
 zr#   c                     | j         S )z-Return the local device on the remote worker.)r   r(   s    r!   r   z_remote_device.device\   s
    |r#   c                     | j         E| j        | j         d| j          S | j        d| j         d| j          S t          | j                   S | j        | j         S | j        | j         S t	          d          )Nr	   zrank:zInvalid state!)r   r   r   r   RuntimeErrorr(   s    r!   __repr__z_remote_device.__repr__`   s    <# ,+<<dl<<<':tz::DL:::4<((( ,+--'*&"#3444r#   c                     t          |t                    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S N)r   r   r   r   r   )r   others     r!   __eq__z_remote_device.__eq__p   sI    %00 
!33 *-*
ek)	
r#   c                 ~    t          | j                  t          | j                  z  t          | j                  z  S r0   )hashr   r   r   r(   s    r!   __hash__z_remote_device.__hash__w   s1    D%&&dl););;d4:>N>NNNr#   N)__name__
__module____qualname____doc__r   r   r   r   r"   staticmethodr   r   r)   r   r   r.   r2   r5    r#   r!   r   r      s         "-.eC,=&> -. -. -. -.^   \!Xc] ! ! ! !hsm        5 5 5 
 
 
O O O O Or#   r   )typingr   r   r   r   r;   r#   r!   <module>r=      sl    " " " " " " " " qO qO qO qO qO qO qO qO qO qOr#   