o
    ?߱iU                     @   sZ   d dl mZ d dlmZ ddeej defddZddeej defddZdd
dZ	dS )    )OptionalNgroupreturnc                 C   "   d}t  rt  rt | }|S )zgGet the rank (GPU device) of the worker.

    Returns:
        rank (int): The rank of the worker.
    r   )distis_availableis_initializedget_rank)r   rank r   X/data/cameron/vidgen/cosmos-predict2.5/cosmos_predict2/_src/reason1/utils/distributed.pyr	         
r	   c                 C   r   )zGet world size. How many GPUs are available in this job.

    Returns:
        world_size (int): The total number of GPUs available in this job.
       )r   r   r   get_world_size)r   
world_sizer   r   r   r   !   r   r   Fc                 C   s(   t  }|dk r	| S tj| |||d d S )N   )srcr   async_op)r   r   	broadcast)tensorr   r   r   r   r   r   r   r   -   s   r   )N)NF)
typingr   torch.distributeddistributedr   ProcessGroupintr	   r   r   r   r   r   r   <module>   s
   