L i0ddlmZmZddlZGddZy))OptionalUnionNceZdZdZdeeejffdZe dZ de efdZ de e fdZdejfdZd Zd Zd Zy ) _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. "/", 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:/", where 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. and are optional and formats like "cpu" and "cuda:1", just represent local devices. remote_devicectd|d}d|_d|_d|_t|tj r||_nt|t r}|jd}t|dk(r|\|_|_net|dk(r5tj|dr |d|_n4|d|_d|_n"t|tdt||j|js t|t j |j|_|j|jjd }t|dk(rA|dd k(r.|djrt|d|_d|_yt|t|dkDr t|yy) NzCould not parse remote_device: zU. The valid format is '/' or 'rank:/' or ''/rcpuz Invalid type for remote_device: :rank) _worker_name_rank_device isinstancetorchdevicestrsplitlenr_is_valid_local_device ValueError TypeErrortypeisdigitint)selfr PARSE_ERRORfieldss e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributed/remote_device.py__init__z_remote_device.__init__s-m_=N N ! @D mU\\ 2(DL  s +"((-F6{a28/!4<V!!88C#)!9DL(.q D%#(DL -->tM?R>STU U    (1B1B[) )||DLL1     (&&,,S1F6{a!9&6!9+<+<+>!$VAYDJ(,D%$[11Vq --! )cN tj|y#t$rYywxYw)NTF)rr Exception)rs r!rz%_remote_device._is_valid_local_deviceHs(  LL   s  $$returnc|jS)zlReturn the name of remote worker representing the remote device and ``None`` if no worker name is available.)rrs r! worker_namez_remote_device.worker_nameQs   r#c|jS)z Returns the rank of remote worker representing the remote device. Returns ``None`` if no rank is available. )rr(s r!rz_remote_device.rankUs zzr#c|jS)z-Return the local device on the remote worker.)rr(s r!rz_remote_device.device\s ||r#c\|jd|j|jd|jS|jd|jd|jSt|jS|j |jS|j |jSt d)Nr zrank:zInvalid state!)rrrr RuntimeErrorr(s r!__repr__z_remote_device.__repr__`s << #  ,++,Adll^<<'tzzl!DLL>::4<<((  ,++,-'**&"#344r#ct|txrO|j|jk(xr4|j|jk(xr|j|jk(SN)rrrrr)rothers r!__eq__z_remote_device.__eq__psT%0   !3!3 3 *  - * ekk) r#ct|jt|jz t|jz Sr0)hashrrrr(s r!__hash__z_remote_device.__hash__ws/D%%&dll);;d4::>NNNr#N)__name__ __module__ __qualname____doc__rrrrr" staticmethodrrr)rrr.r2r5r#r!rrsv"-.eC,=&>-.^!Xc]!hsm 5  Or#r)typingrrrrr;r#r!r=s" qOqOr#