o
    ÔÙ¾ij  ã                
   @   s¾   d dl mZmZmZ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deej	 fdd„Z	 ddeeeeej	ef f  defdd„ZdS )é    )ÚAnyÚDictÚOptionalÚUnionNé   )Úget_tp_groupÚinput_Úreturnc                 C   s   t ƒ  | ¡S )z8All-reduce the input tensor across model parallel group.)r   Ú
all_reduce)r   © r   ú[/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/distributed/communication_op.pyÚ tensor_model_parallel_all_reduce   s   r   éÿÿÿÿÚdimc                 C   s   t ƒ  | |¡S )z8All-gather the input tensor across model parallel group.)r   Ú
all_gather)r   r   r   r   r   Ú tensor_model_parallel_all_gather   s   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   r   r   r   Útorch.distributedÚparallel_stater   ÚTensorr   Úintr   r   r   r   r   r   r   Ú<module>   s:   ÿÿÿ
þÿÿÿÿ
þÿÿÿ