
    -`i                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ 	 d dlmc mZ dZn# e$ r dZY nw xY w ee          Z G d	 d
          ZdS )    N)ProcessGroup)SYMM_MEM_ALL_REDUCE_MAX_SIZES)init_logger)vllm_is_batch_invariant)current_platformTFc            
           e Zd Zg dddgdZ	 	 ddedeez  ej        z  de	dz  d	edz  fd
Z
dej        fdZdddej        dej        dz  dej        dz  fdZdS )SymmMemCommunicator)         r   r   )z9.0z10.0Ngroupdeviceforce_multimemmax_size_overridec                    d| _         t          sd S t          j                    st                              d           d S t          |t                    rt          j	        d|           }n)t          |t                    rt          j	        |          }t          j                            |           t          j        | _        || _	        || _        t!          j        | j                  | _        t          j                    }|t                              d           d S |                                | _        | j        t,          vr"t                              d| j                   d S | j        t,          | j                 vr"t                              d| j                   d S |(|| _        t                              d| j                   n"t,          | j                 | j                 | _        	 t3          j        | j        | j        j        z  | j	        | j                  | _        t3          j        | j        | j        j                  }n@# t>          $ r3}t                               d	t          |                     Y d }~d S d }~ww xY w|j!        d
k    rt                              d           d S || _"        d| _         tG                      r	d| _         d S d S )NTz7SymmMemCommunicator: symmetric memory is not available.zcuda:zQSymmMemCommunicator: device capability is unknown, communicator is not available.zWSymmMemCommunicator: Device capability %s not supported, communicator is not available.zPSymmMemCommunicator: World size %d not supported, communicator is not available.z6SymmMemCommunicator: Using override max_size: %s bytes)r   dtypezSymmMemCommunicator: symmetric memory initialization failed: %s Communicator is not available. To suppress this warning set VLLM_ALLREDUCE_USE_SYMM_MEM=0r   zMSymmMemCommunicator: symmetric memory multicast operations are not supported.F)$disabledsymm_mem_availabler   is_cudaloggerwarning
isinstanceinttorchr   strcuda
set_devicebfloat16r   r   distget_world_size
world_sizeget_device_capabilityas_version_strdevice_capabilityr   max_sizeinfotorch_symm_mememptyitemsizebuffer
rendezvous
group_nameRuntimeErrorwarning_oncemulticast_ptrr   r   )selfr   r   r   r   
capabilityhandlees           /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/distributed/device_communicators/symm_mem.py__init__zSymmMemCommunicator.__init__!   s    ! 	F')) 	NNTUUUFfc"" 	*\"2&"2"233FF$$ 	*\&))F
f%%%^

-dj99%;==
NN1   F!+!:!:!<!<!)FFFNN1&  
 F?"?@V"WWWNN1  
 F(-DMKKH   
 :$:PQDM	(.!44{j  DK
 $.t{DJ<QRRFF 	 	 	0 A	   FFFFF	 1$$NN:   F,"$$ 	! DMMM	! 	!s   4AI 
J(J		Jinpc                     | j         rdS |j        | j        k    rdS |                                |                                z  }|dz  dk    rdS || j        k     S )NFr
   r   )r   r   numelelement_sizer%   )r0   r6   inp_sizes      r4   should_use_symm_memz'SymmMemCommunicator.should_use_symm_memu   sd    = 	59
""599;;!1!1!3!33a<15$-''    )outr=   returnc                   |                      |          sd S |t          j        |          }| j        d |                                                             |                    d                     d}| j        | j        }n| j        | j	        | j
                 v }|rPt          j        j                            | j        d |                                         d| j        j                   nOt          j        j                            | j        d |                                         d| j        j                   |                    | j        d |                                                             |j                             |S )NFsum)r;   r   
empty_liker*   r8   copy_viewr   r!   _WORLD_SIZES_MULTIMEMr$   opssymm_memmultimem_all_reduce_r   r,   two_shot_all_reduce_shape)r0   r6   r=   use_multimems       r4   
all_reducezSymmMemCommunicator.all_reduce   s`    '',, 	4;"3''CMciikkM"(("666 *.LL 4#=d>T#UU   	I33MciikkM*E4:3H    I33MciikkM*E4:3H   			$+m		m,11#)<<===
r<   )NN)__name__
__module____qualname__rE   r   r   r   r   r   boolr5   Tensorr;   rL    r<   r4   r	   r	      s        yyA  '+(,R! R!R! c	EL(R!
 tR! :R! R! R! R!h(u| ( ( ( ( @D  <).)<		     r<   r	   )r   torch.distributeddistributedr   r   6vllm.distributed.device_communicators.all_reduce_utilsr   vllm.loggerr   *vllm.model_executor.layers.batch_invariantr   vllm.platformsr   #torch.distributed._symmetric_memory_symmetric_memoryr'   r   ImportErrorrM   r   r	   rR   r<   r4   <module>r\      s5                * * * * * *      $ # # # # #      , + + + + +@@@@@@@@@    
X		A A A A A A A A A As   6 A A 