U
    "A·fœ  ã                   @   sÔ   d dl mZmZ d dlZd dlm  mZ dd„ Zdd„ Z	dd„ Z
d	d
„ Zdd„ Zejeeee edœdd„Zeej eeee edœdd„Zejeee  eee  eee edœdd„Zejejdœdd„ZdS )é    )ÚListÚOptionalNc                 C   s   t  ||¡}tjj | ||¡S ©N)Úc10dÚ$_resolve_group_name_by_ranks_and_tagÚtorchÚopsÚ_c10d_functionalÚ	broadcast)ÚinputÚsrcÚtagÚranksÚ
group_sizeÚ
group_name© r   úR/tmp/pip-unpacked-wheel-ak3y1t3j/torch/distributed/_functional_collectives_impl.pyÚ
_broadcast   s    ýr   c                 C   s   t  ||¡}tjj | ||¡S r   )r   r   r   r   r	   Z
all_reduce©r   Ú	reduce_opr   r   r   r   r   r   r   Ú_all_reduce   s    ýr   c                 C   s   t  ||¡}tjj | ||¡S r   )r   r   r   r   r	   Zall_reduce_coalesced©Úinputsr   r   r   r   r   r   r   r   Ú_all_reduce_coalesced   s    ýr   c                 C   s   t  ||¡}tjj | ||¡S r   )r   r   r   r   r	   Zall_gather_into_tensor©r   r   r   r   r   r   r   r   Ú_all_gather_into_tensor(   s    ýr   c                 C   s   t  ||¡}tjj | ||¡S r   )r   r   r   r   r	   Z all_gather_into_tensor_coalescedr   r   r   r   Ú!_all_gather_into_tensor_coalesced1   s    ýr   )r   r   r   r   r   c                 C   s    t  ||¡}tjj | |||¡S r   )r   r   r   r   r	   Zreduce_scatter_tensorr   r   r   r   Ú_reduce_scatter_tensor:   s    ür   )r   r   r   r   r   c                 C   s    t  ||¡}tjj | |||¡S r   )r   r   r   r   r	   Zreduce_scatter_tensor_coalescedr   r   r   r   Ú _reduce_scatter_tensor_coalescedJ   s    ür   )r   Úoutput_split_sizesÚinput_split_sizesr   r   r   c                 C   s`   |d ks|d kr@|d kr |d ks(t dƒ‚| jd | g| }|}t ||¡}tjj | |||¡S )Nz^output_split_sizes and input_split_sizes must either be specified together or both set to Noner   )ÚAssertionErrorÚshaper   r   r   r   r	   Zall_to_all_single)r   r   r    r   r   r   r   r   r   r   Ú_all_to_all_singleZ   s    ÿür#   )ÚtensorÚreturnc                 C   s   t jj | ¡S r   )r   r   r	   Zwait_tensor)r$   r   r   r   Ú_wait_tensors   s    r&   )Útypingr   r   r   Z"torch.distributed.distributed_c10dZdistributedZdistributed_c10dr   r   r   r   r   r   ZTensorÚstrÚintr   r   r#   r&   r   r   r   r   Ú<module>   s6   				
ûû

ú