o
    1 i*                     @   s   d dl Z d dlmZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ er4d dlZdadadaded	d
fddZddded	efddZd	efddZd	eeef fddZdS )    N)closing)TYPE_CHECKINGTuple)CollectiveTensorTransport)NixlTensorTransport)TensorTransportManager)Backendtensor_transportreturnr   c                 C   sf   | t jkrtdu rt atS | t jkrtdu rt| atS | t jkr,tdu r*t| atS t	d|  )a   Get the tensor transport manager for the given tensor transport protocol.

    Args:
        tensor_transport: The tensor transport protocol to use for the GPU object.

    Returns:
        TensorTransportManager: The tensor transport manager for the given tensor transport protocol.
    N'Unsupported tensor transport protocol: )
r   NIXL_nixl_tensor_transport_managerr   
TORCH_GLOO_gloo_tensor_transport_managerr   NCCL_nccl_tensor_transport_manager
ValueError)r	    r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/experimental/collective/util.pyget_tensor_transport_manager   s   


r   deviceztorch.devicec                 C   sT   |t jkr| jdkp| jdkS |t jkr| jdkS |t jkr#| jdkS td| )z*Check if the device matches the transport.cudacpur   )r   r   typer   r   r   )r   r	   r   r   r   device_match_transport4   s   




r   c                  C   s`   t ttjtj} | d | tjtjd |  d W  d    S 1 s)w   Y  d S )N) r      )	r   socketAF_INETSOCK_STREAMbind
setsockopt
SOL_SOCKETSO_REUSEADDRgetsockname)sr   r   r   find_free_port@   s
   

$r&   c                  C   s   t j } t }| |fS )z4Returns the IP address and a free port on this node.)rayutilZget_node_ip_addressr&   )addrportr   r   r   get_address_and_portG   s   
r+   )r   
contextlibr   typingr   r   r'   Z7ray.experimental.collective.collective_tensor_transportr   Z1ray.experimental.collective.nixl_tensor_transportr   Z4ray.experimental.collective.tensor_transport_managerr   Zray.util.collective.typesr   Ztorchr   r   r   r   boolr   intr&   strr+   r   r   r   r   <module>   s*    
