
    uki	                     N   d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
  G d d      Zes"  e	ej                  j                        e      Z G d d	      Zes"  e	ej                  j                        e      Zej                  j                  Z eej                  d
      rd Zyy)z6`jax.experimental.transfer`: DCN cross slice transfer.    N)AnyTYPE_CHECKING)
xla_client)use_cpp_classuse_cpp_methodc                   >    e Zd ZdZ e       d        ZdededefdZy)TransferConnectionz,Represents a connection to exactly one peer.c                     t               NNotImplementedError)selfuuidbackendxs_flats       T/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/experimental/transfer.py
_pull_flatzTransferConnection._pull_flat       

    r   xsreturnc                     t         j                  j                  |      \  }}|s|S t        t	        |d   j
                  j                              j                  }|j                  | j                  |||            S )zFetches a pytree of arrays from a remote device.

    Args:
       uuid: identifier for the request
       xs: A pytree of ShapeDtypeStruct.
    Returns:
       A pytree of arrays.
    r   )
jaxtreeflattennextitersharding
device_setclient	unflattenr   )r   r   r   r   r   r   s         r   pullzTransferConnection.pull   se     HH$$R(MGTi4
++6678??G>>$//$ABBr   N)	__name__
__module____qualname____doc__r   r   intr   r"    r   r   r	   r	      s8    4   Cs C C Cr   r	   c                       e Zd Z e       defd       Z e       deej                     fd       Z	 e       dede
fd       Zdededefd	Zy
)TransferServerr   c                     t               )z>Returns the address that this server can be connected to with.r   )r   s    r   addresszTransferServer.address2        
r   argsc                     t               r   r   )r   r   r.   s      r   _await_pull_flatzTransferServer._await_pull_flat7   r   r   r,   c                     t               )z(Creates a connection to a remote server.r   )r   r,   s     r   connectzTransferServer.connect;   r-   r   r   arraysc                 h    | j                  |t        j                  j                  |      d          y)z>Schedules a pytree of arrays to be fetched by a remote device.r   N)r0   r   r   r   )r   r   r3   s      r   
await_pullzTransferServer.await_pull@   s&    $ 0 0 8 ;<r   N)r#   r$   r%   r   strr,   listr   Arrayr0   r	   r2   r'   r   r5   r(   r   r   r*   r*   0   s     s      cii      S  %7    =S =# =# =r   r*   _make_error_arrayc                     t        t        | j                  j                              j                  }t
        j                  j                  || t        |            S r   )	r   r   r   r   r    _xc_xlar9   r6   )avalmessager   s      r   make_error_arrayr?   K   s>    4001299G88%%gtS\BBr   )r&   r   typingr   r   jax._src.libr   r;   jax._src.utilr   r   r	   r<   r*   start_transfer_serverhasattrr?   r(   r   r   <module>rE      s    = 
 % * 7C C. A}SXX%@%@ABTU= =* 9=!8!89.I.66 
388()C *r   