
    9ib                     (    d dl Z  G d d          ZdS )    Nc                       e Zd ZdZdeej        z  fdZed             Z	dedz  fdZ
dedz  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       R/var/www/icac/venv/lib/python3.11/site-packages/torch/distributed/remote_device.py__init__z_remote_device.__init__   s    Nm N N N 	 !
8<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_deviceJ   s>    	L   4 	 	 	55	s    
&&returnNc                     | 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_nameS   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.rankW   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__b   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__r   sI    %00 
!33 *-*
ek)	
r!   c                 ~    t          | j                  t          | j                  z  t          | j                  z  S r.   )hashr   r   r   r&   s    r   __hash__z_remote_device.__hash__y   s1    D%&&dl););;d4:>N>NNNr!   )__name__
__module____qualname____doc__r   r   r   r    staticmethodr   r'   r   r   r,   r0   r3    r!   r   r   r      s         "0.cEL&8 0. 0. 0. 0.d   \!S4Z ! ! ! !cDj        5 5 5 
 
 
O O O O Or!   r   )r   r   r9   r!   r   <module>r:      sV    tO tO tO tO tO tO tO tO tO tOr!   