o
    ˜à·i+  ã                
   @   sÌ   d dl mZ d dlZd dlZddlmZ dejdejfdd„Z		ddejd
edejfdd„Z			ddejd
edejfdd„Z
		ddejded
edejdB fdd„Z	 ddeeejeB f dB defdd„ZdS )é    )ÚAnyNé   )Úget_tp_groupÚinput_Úreturnc                 C   s   t ƒ  | ¡S )z8All-reduce the input tensor across model parallel group.)r   Ú
all_reduce)r   © r   úW/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm/distributed/communication_op.pyÚ tensor_model_parallel_all_reduce   s   r
   éÿÿÿÿÚdimc                 C   ó   t ƒ  | |¡S )z8All-gather the input tensor across model parallel group.)r   Ú
all_gather©r   r   r   r   r	   Ú tensor_model_parallel_all_gather   ó   r   c                 C   r   )z<Reduce-Scatter the input tensor across model parallel group.)r   Úreduce_scatterr   r   r   r	   Ú$tensor_model_parallel_reduce_scatter   r   r   Údstc                 C   s   t ƒ  | ||¡S )z4Gather the input tensor across model parallel group.)r   Úgather)r   r   r   r   r   r	   Útensor_model_parallel_gather   s   r   Útensor_dictÚsrcc                 C   s   t j ¡ s| S tƒ  | |¡S )N)ÚtorchÚdistributedÚis_initializedr   Úbroadcast_tensor_dict)r   r   r   r   r	   r   &   s   
r   )r   )r   r   )Nr   )Útypingr   r   Útorch.distributedÚparallel_stater   ÚTensorr
   Úintr   r   r   Údictr   r   r   r   r	   Ú<module>   sJ   ÿÿÿ
þÿÿÿ
þÿÿÿÿ
þÿÿÿ