
    -`i~                     X   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZ d dlmZ d dlZd dlmZ d dlZd d	lmZ d d
lmZmZmZmZmZmZ d dlm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, erd dl-m.Z. e j/        Z/ e j0        e1j2        d          Z3 ej4                    Z5d Z6de1de1de7fdZ8 e%e9          Z:de1de;fdZ< G d d          Z= G d de=          Z> G d d          Z?e G d d                       Z@ G d! d"          ZAdS )#    N)contextmanager)	dataclassfield)shared_memory)PickleBuffer)Event)TYPE_CHECKINGAnycast)patch)ProcessGroup)IPV6SUB	SUBSCRIBEXPUBXPUB_VERBOSEContext)StatelessProcessGroupsched_yield)init_logger)current_platform)get_ipget_open_portget_open_zmq_ipc_pathis_valid_ipv6_address)SizedBufferbig	byteorderc                  H    t           5  	 ddd           dS # 1 swxY w Y   dS )a}  
    Full memory barrier for shared memory synchronization.

    Ensures all prior memory writes are visible to other processes before
    any subsequent reads. This is critical for lock-free producer-consumer
    patterns using shared memory.

    Implementation acquires and immediately releases a lock. Python's
    threading.Lock provides sequentially consistent memory barrier semantics
    across all major platforms (POSIX, Windows). This is a lightweight
    operation (~20ns) that guarantees:
    - All stores before the barrier are visible to other threads/processes
    - All loads after the barrier see the latest values
    N)_memory_fence_lock     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/distributed/device_communicators/shm_broadcast.pymemory_fencer%   5   sq    " 
                   s   valuesizereturnc                 0    |                      |d          S )Nr   r   )to_bytes)r&   r'   s     r$   to_bytes_bigr+   J   s    >>$%>000r#   	thresholdc                     d|  dS )Nz4No available shared memory broadcast block found in z seconds. This typically happens when some processes are hanging or doing some time-consuming work (e.g. compilation, weight/kv cache quantization).r"   )r,   s    r$   long_wait_time_msgr.   Q   s    	)	) 	) 	)r#   c                       e Zd Zd Zd ZdS )	SpinTimerc                     d S Nr"   selfs    r$   record_activityzSpinTimer.record_activity\   s    r#   c                 "    t                       d S r2   )r   r3   s    r$   spinzSpinTimer.spin_   s    r#   N)__name__
__module____qualname__r5   r7   r"   r#   r$   r0   r0   [   s2              r#   r0   c                   0    e Zd ZdZd
dedefdZd Zd Zd	S )SpinSleepTimera  
    In setups which have long inactivity periods it is desirable to reduce
    system power consumption when vllm does nothing. This would lead to more
    CPU thermal headroom when a request eventually comes, especially when
    multiple GPUs are connected as each GPU would otherwise pin one thread at
    100% CPU usage.

    The simplest solution is to reduce polling frequency when there is no
    activity for a certain period of time.
          @皙?busy_loop_swait_sleep_sc                 R    t          j                    | _        || _        || _        d S r2   )time	monotoniclast_activityr?   r@   )r4   r?   r@   s      r$   __init__zSpinSleepTimer.__init__o   s(    !^--&(r#   c                 6    t          j                    | _        d S r2   )rB   rC   rD   r3   s    r$   r5   zSpinSleepTimer.record_activityt   s    !^--r#   c                     t          j                    }|| j        | j        z   k    rt          j        | j                   d S t                       d S r2   )rB   rC   rD   r?   sleepr@   r   )r4   	curr_times     r$   r7   zSpinSleepTimer.spinw   sK    N$$	*T-====Jt()))))MMMMMr#   N)r=   r>   )r8   r9   r:   __doc__floatrE   r5   r7   r"   r#   r$   r<   r<   c   sc        	 	) )E )u ) ) ) )
. . .    r#   r<   c            
       z    e Zd Z	 ddededededz  fdZd Zd Zd	 Ze	d
efd            Z
e	d
efd            ZdS )ShmRingBufferNn_readermax_chunk_bytes
max_chunksnamec                    || _         d|z   | _        || _        || _        | j        | j        z   | j        z  | _        d| _        | j        | j        z  | _        |d| _        t          j	        d| j                  | _        | j        j
        | j        d         5 }t          j        |t          j                                      d           ddd           dS # 1 swxY w Y   dS d| _        t          dd	           5  	 t          j	        |
          | _        | j        j        | j        k    sJ n# t"          $ r Y nw xY wddd           dS # 1 swxY w Y   dS )an  
        A shared memory ring buffer implementation for broadcast communication.
        Essentially, it is a queue where only one will `enqueue` and multiple
        will `dequeue`. The max size of each item, together with the max number
        of items that can be stored in the buffer are known in advance.
        In this case, we don't need to synchronize the access to
         the buffer.

        Buffer memory layout:
                  data                                 metadata
                    |                                      |
                    | (current_idx)                        | (current_idx)
                    v                                      v
        +-------------------------------+----------------------------------------+
        | chunk0 | chunk1 | ... | chunk | metadata0 | metadata1 | ... | metadata |
        +-------------------------------+----------------------------------------+
        | max_chunks x max_chunk_bytes  | max_chunks x (1 + n_reader) bytes      |

        metadata memory layout: each byte is a flag, the first byte is the written
        flag, and the rest are reader flags. The flags are set to 0 by default.
        +--------------+--------------+--------------+-----+--------------+
        | written_flag | reader0_flag | reader1_flag | ... | readerN_flag |
        +--------------+--------------+--------------+-----+--------------+

        The state of metadata is as follows:

        (case 1) 0???...???: the block is not written yet, cannot read, can write
        (case 2) 1000...000: the block is just written, can read, cannot write
        (case 3) 1???...???: the block is written and read by some readers, can read if not read, cannot write
        (case 4) 1111...111: the block is written and read by all readers, cannot read, can write

        State transition for readers:

        When a reader finds a block that it can read (case 2 or 3), it can yield the block for caller to read.
        Only after the caller finishes reading the block, the reader can mark the block as read.
        Readers only mark the block as read (from 0 to 1), the writer marks the block as ready to read (from 1 to 0).

        State transition for writer:

        When the writer writes to a block (case 1 or 4), it first resets the written flag to 0, converting either case
        to case 1. Then it can yield the block for caller to write. After the caller finishes writing the block, the writer
        can reset the reader flags to 0, and mark the block as written (from 0 to 1).
        NOTE: the order is important here, first reset the reader flags (so that we are still in case 1), then mark the block as written. The state transition is atomic. If we do it in the reverse order, it will go through case 3 and then back to case 2, and readers might read the intermediate case 3, which is not correct.

        During creation, `name` is None and the buffer is created. We can pass the
        created object to other processes by pickling it. The other processes will
        get the name of the shared memory and open it, so that they can access the
        same shared memory buffer.
           r   NT)creater'   )dtypeFz)multiprocessing.resource_tracker.registerc                      d S r2   r"   )argskwargss     r$   <lambda>z(ShmRingBuffer.__init__.<locals>.<lambda>   s     r#   )rQ   )rN   metadata_sizerO   rP   total_bytes_of_bufferdata_offsetmetadata_offset
is_creatorr   SharedMemorybuftorch
frombufferuint8fill_r   r'   FileNotFoundError)r4   rN   rO   rP   rQ   metadata_buffers         r$   rE   zShmRingBuffer.__init__   s(   p !\.$ 4#55O&" #3doE<"DO!.!;$"<" " "D #'(<(>(>? N? DDDJJ1MMMN N N N N N N N N N N N N N N N N N $DO ;,,   )6)C)N)N)ND&  -2d6PPPPPP(    D	                 sH   4CC!C?E1D32E3
E =E?E  EEEc                 @    | j         | j        | j        | j        j        fS r2   )rN   rO   rP   r   rQ   r3   s    r$   handlezShmRingBuffer.handle   s%    M O#	
 	
r#   c                 8    | j         |                                 fS r2   )	__class__rh   r3   s    r$   
__reduce__zShmRingBuffer.__reduce__   s    NKKMM
 	
r#   c                     t          | d          r;| j                                         | j        r| j                                         d S d S d S )Nr   )hasattrr   closer^   unlinkr3   s    r$   __del__zShmRingBuffer.__del__   sb    4)) 	,$$&&& ,"))+++++	, 	,, ,r#   current_idxc              #      K   | j         || j        z  z   }|| j        z   }| j        j        ||         5 }|V  d d d            d S # 1 swxY w Y   d S r2   )r\   rO   r   r`   r4   rq   startendr`   s        r$   get_datazShmRingBuffer.get_data   s       ;1E#EEd**#E#I. 	#III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AA	A	c              #      K   | j         || j        z  z   }|| j        z   }| j        j        ||         5 }|V  d d d            d S # 1 swxY w Y   d S r2   )r]   rZ   r   r`   rs   s        r$   get_metadatazShmRingBuffer.get_metadata   s      ${T5G'GGd((#E#I. 	#III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rw   r2   )r8   r9   r:   intstrrE   rh   rk   rp   r   rv   ry   r"   r#   r$   rM   rM      s          a aa a 	a
 Dja a a aF
 
 

 
 
, , , C    ^     ^  r#   rM   c                       e Zd ZU  ee          Zee         ed<   dZe	eeee
f         dz  ed<   dZe
dz  ed<   dZe
dz  ed<   dZeed<   dS )	Handle)default_factorylocal_reader_ranksNbuffer_handlelocal_subscribe_addrremote_subscribe_addrFremote_addr_ipv6)r8   r9   r:   r   listr   rz   __annotations__r   tupler{   r   r   r   boolr"   r#   r$   r}   r}     s         $)E$$?$?$?S	???6:M5c3+,t3:::'+#*+++(,3:,,,"d"""""r#   r}   c                      e Zd Z	 	 	 	 d!dee         dz  dedededz  fdZd	efd
Ze	ded	d fd            Z
d Zed"dedz  fd            Ze	 	 	 d#dedz  dedz  defd            Zd"dedz  fdZ	 	 	 d#dedz  dedz  defdZe	dej        dedz  d	efd            Zd"dZe		 	 d$dededed	ed ee         f         fd            Ze		 	 	 d%deez  deded	d fd             ZdS )&MessageQueueN  
   r   rO   rP   
connect_ipc                    |t          t          |                    }nt          |          |k    sJ || _        ||z
  }|| _        t                      }|dk    rt          |||          | _        |                    t                    | _
        | j
                            t          d           t                      }	t                              d|	           | j
                            |	           d| _        nd | _        d }	d | _
        d| _        d}
|dk    r|st%                      }|                    t                    | _        | j                            t          d           t)                      }t+          |          r(| j                            t,          d           d}
d| d}d	| d
| }| j                            |           d	| d
| }n	d }d | _        d| _        d| _        d| _        d| _        t7                      | _        t;          || j        | j                                        nd |	||
          | _        t                              d| j                   d S )Nr   TzBinding to %sFrS   []ztcp://:)r   r   r   r   r   z+vLLM message queue communication handle: %s)r   rangelenn_local_readern_remote_readerr   rM   buffersocketr   local_socket
setsockoptr   r   loggerdebugbindrq   r   remote_socketr   r   r   
_is_writer_is_local_readerlocal_reader_rank_is_remote_readerr0   _read_spin_timerr}   rh   )r4   rN   r   r   rO   rP   r   r   contextr   r   remote_subscribe_portsocket_addrr   s                 r$   rE   zMessageQueue.__init__  s    %!%eN&;&;!<!<)**n<<<<,"^3.))A (TTDK
 !(t 4 4D ((t<<<#8#:#: LL*>???""#7888 DDK#'  $D!D Q  &#XX
!(!5!5D)),===$1OO!$Z00 /"--dA666#' ....
G:GG0EGGK##K000$QZ$Q$Q:O$Q$Q!!$(!!%D %!#!& )126+2I$+,,...t!5"7-
 
 
 	BDKPPPPPr#   r(   c                     | j         S r2   )rh   r3   s    r$   export_handlezMessageQueue.export_handled  s
    {r#   rh   c                 (   t                               t                     }| |_        d|_        t	                      }|| j        v r | j        J t          | j         |_        d|_	        | j        
                    |          |_        d|_        d|_        |                    t                    |_        |j                            t$          d           | j        }t(                              d|           |j                            |           d |_        t0          j        rt5                      nt7                      |_        nd |_        d|_	        d|_        d|_        d|_        d |_        |                    t                    |_        |j                            t$          d           | j        r |j                            t>          d           | j         }t(                              d|           |j                            |           |S )NFr   T zConnecting to %sr   rS   )!r   __new__rh   r   r   r   r   rM   r   rq   indexr   r   r   r   r   r   setsockopt_stringr   r   r   r   connectr   envsVLLM_SLEEP_WHEN_IDLEr<   r0   r   r   r   r   r   )rh   rankr4   r   r   s        r$   create_from_handlezMessageQueue.create_from_handleg  s   ##L11))6,,,'333')=>DK D%+%>%D%DT%J%JD"$(D!%*D" 's 3 3D//	2>>> 5KLL+[999%%k222!%D %)$=N   9;; !! DK!D%'D"$)D!%)D" $D!(!4!4D00B???& 7"--dA666 6KLL+[999&&{333r#   c                    | j         rt          | j                  D ]}| j                                         | j        dk    r| j                            d           t          | j                  D ]}| j                                         | j        dk    r| j                            d           dS dS | j        r#| j                                        }|dk    sJ dS | j	        r!| j                                        }|dk    sJ dS dS )zThis is a collective operation. All processes (including the
        readers and the writer) should call this function.
        r   s   READYN)
r   r   r   r   recvsendr   r   r   r   )r4   ir   s      r$   wait_until_readyzMessageQueue.wait_until_ready  sL    ? 	$ 4.// ) )!&&(((("Q&& !&&x000 4/00 * *"''))))#a'' "''11111 (' " 	$$))++D8####### 	$%**,,D8####	$ 	$ $#r#   timeoutc              #   n  K   | j         s
J d            t          j                    }d}	 | j                            | j                  5 }t                       t          |dd                    }|d         }|r|| j        j        k    rt                       t          j                    |z
  }|||k    rt          |t          |z  k    r1t                              t          t                               |dz  }	 d d d            d|d<   | j                            | j                  5 }|V  d d d            n# 1 swxY w Y   t!          d| j        j        dz             D ]}	d||	<   d|d<   t                       | j        dz   | j        j        z  | _        	 d d d            d S # 1 swxY w Y   )NzOnly writers can acquire writerS   Tr   )r   rB   rC   r   ry   rq   r%   sumrN   r   TimeoutError VLLM_RINGBUFFER_WARNING_INTERVALr   infor.   rv   r   rP   )
r4   r   
start_time	n_warningrf   
read_countwritten_flagelapsedr`   r   s
             r$   acquire_writezMessageQueue.acquire_write  sk     @@ @@@^%%
	7	))$*:;; 6  !455
.q1 J$+2F$F$F  MMM #n..;G*w/@/@** !AI!MMM./OPP   "Q	96 6 6 6 6 6 6D &'"[))$*:;; sIII               q$+"6":;; + +A)*OA&&%&" $($4q$8DK<R#R m6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 67	s>   	B3F*$F*,D=1F*=E	F*E	AF**F.1F.Fcancel
indefinitec              #     K   | j         s
J d            t          j                    }d}	 | j                            | j                  5 }t                       || j        dz            }|d         }|r|r| j        	                                 |#|
                                rt          d          t          j                    |z
  }	||	|k    rt          |s?|	t          |z  k    r1t                              t!          t                               |dz  }	 d d d            | j                            | j                  5 }
|
V  d d d            n# 1 swxY w Y   d|| j        dz   <   t                       | j        dz   | j        j        z  | _        | j                                         	 d d d            d S # 1 swxY w Y   )NzOnly readers can acquire readrS   Tr   	cancelled)r   rB   rC   r   ry   rq   r%   r   r   r7   is_setRuntimeErrorr   r   r   r   r.   rv   rP   r5   )r4   r   r   r   r   r   rf   	read_flagr   r   r`   s              r$   acquire_readzMessageQueue.acquire_read  s}      $EE&EEE$^%%
	5	))$*:;; 4 +D,BQ,FG	.q1# y  )..000)fmmoo)*;777 #n..;G*w/@/@** & '"BY"NNN./OPP   "Q	I4 4 4 4 4 4 4N [))$*:;; sIII              
 ?@ 6 :; $($4q$8DK<R#R %55777i4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 45	s>   	CF>%F>E	F>E	F>E	AF>>GGc                   	
 | j         s
J d            dg	d
dt          dt          f	
fd}t          j        |t          j        |          	d<   | j        dk    r
t          	d                   z   | j        j	        k    rO| 
                    |          5 }d	|d<   d
d
d
           n# 1 swxY w Y   | j                            	d           n| 
                    |          5 }d|d<   d}t          t          	          d          |d	|<   	D ]7}t          |          }|dz   }t          |d          |||<   |||||z   x}<   8	 d
d
d
           n# 1 swxY w Y   | j        dk    r| j                            	d           d
S d
S )z9Write to message queue with optional timeout (in seconds)zOnly writers can enqueuer#      r`   r(   c                     |                                  }t          |          dk     rdS                     |           t          |          dz   z  dS )Ni   T   F)rawr   append)r`   raw_bufall_bufferstotal_bytess     r$   oob_callbackz*MessageQueue.enqueue.<locals>.oob_callback;  sT    ggiiG7||k))tw'''3w<<!++K5r#   )protocolbuffer_callbackr   rS   NFcopy      r   )r   r   r   pickledumpsHIGHEST_PROTOCOLr   r   r   rO   r   r   send_multipartr+   r   r   )r4   objr   r   r`   offsetr   buf_len
buf_offsetr   r   s            @@r$   enqueuezMessageQueue.enqueue5  s{   :: :::*-	l 	t 	 	 	 	 	 	 	  &1<
 
 
A ""SQ000DK4OOO''00 CCF              !0050IIII ''00 	TCCFF$0[1A1A1$E$EC&M"- T T"%f++%+aZ
1=gq1I1IF:-.MSJJ4H*H&IJJT		T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T !##--k-FFFFF $#s%   B++B/2B/(A$EE Ec                 `   | j         r|                     |||          5 }|d         dk    }|sd}t          |d|                   }g }t          |          D ]@}	|dz   }
t          |||
                   }|
|z   }|                    ||
|                    At          j        |d         |dd                   }ddd           n# 1 swxY w Y   |r t                              | j	        |          }n7| j
        r!t                              | j        |          }nt          d          |S )z:Read from message queue with optional timeout (in seconds)r   rS   r   r   NbufferszOnly readers can dequeue)r   r   from_bytes_bigr   r   r   loadsr   r   r   r   r   r   )r4   r   r   r   r`   overflowr   	buf_countr   r   r   r   r   s                r$   dequeuezMessageQueue.dequeue`  s      	;""7FJ?? P3q6Q; 	PF .s1V8} = =I"$K"9-- C C%+aZ
"0VJ5F1G"H"H!+g!5#**3z&/@+ABBBB ,{1~{122OOOCP P P P P P P P P P P P P P P  D"''(97CC# 	;##D$6@@CC9:::
s   BC		CCr   c                     |d nt          |dz            }|                     |          st          |                     d          ^}}t	          j        ||          S )Ni  )r   Fr   r   )rz   pollr   recv_multipartr   r   )r   r   
timeout_msr   recv_oobs        r$   r   zMessageQueue.recv|  sf    $_TT#gn2E2E
{{:{.. 	 //U/;;x|D(3333r#   c                 f    | j         r|                     |           |S |                                 S r2   )r   r   r   )r4   r   s     r$   broadcast_objectzMessageQueue.broadcast_object  s1    ? 	LLJ||~~r#   r   pgreader_rankblockingc                    t          j                    }t          j                    }||z  ||z  k    }t	          d|rdnd||          }|                                }	||k    rdgt          j        |           z  nd}
t          j        |	|
||            |r|                                 |t          t          t                   |
pg           fS )a'  
        Creates a MessageQueue for a process group with a single reader.

        This method is designed for scenarios where only one process (the reader)
        will consume messages, and all other processes are writers. It sets up
        the shared memory buffer and communication handles accordingly, and
        gathers the handles from all processes to the reader.

        Args:
            pg (ProcessGroup): The torch distributed process group.
            max_chunk_bytes (int): Maximum size in bytes for each chunk in the buffer.
            max_chunks (int): Maximum number of chunks in the buffer.
            reader_rank (int, optional): The global rank that will act as the reader.
                Defaults to 0.
            blocking (bool, optional): If True, blocks until all processes are ready.
                Defaults to False.

        Returns:
            tuple[MessageQueue, list[Handle]]:
            The MessageQueue instance for the calling process,
            and a list of handles (only non-empty for the reader process).
        rS   r   )rN   r   rO   rP   N)dstgroup)r   device_countdistget_rankr   r   get_world_sizegather_objectr   r   r   r}   )r   rO   rP   r   r   
local_sizer   	same_node	buffer_iorh   handless              r$   'create_from_process_group_single_readerz4MessageQueue.create_from_process_group_single_reader  s    < &244
}J&+*CC	  )011q+!	
 
 
	 ((**6:k6I6I4&4.r2222t672FFFF 	)&&((($tF|W];;;;r#   Twriter_rankc                    t          | t                    r=t          j        |           }t          j        |           }t          j        |           }n/| j        }| j        }t          t          | j                            }ddl
m}	  |	|           }
|k    r|t                              ||          }nRd t          |
          D             }|dz
  }t          |          dz
  }fd|D             }t          |||||          }|                                }t          | t                    rt          j        |g|         | 	           n|                     |           not          | t                    r)dg}t          j        ||         | 	           |d         }n|                     d          }t                              ||          }|r|                                 |S )
a  
        Creates a MessageQueue for a distributed process group with one writer and
        multiple readers.

        This method is designed for scenarios where one process (the writer) sends
        messages, and all other processes (the readers) receive messages. It sets up
        the shared memory buffer and socket communication handles accordingly, and
        broadcasts the handle from the writer to all readers.

        Args:
            pg (ProcessGroup | StatelessProcessGroup): The torch distributed process
                group.
            max_chunk_bytes (int): Maximum size in bytes for each chunk in the buffer.
            max_chunks (int): Maximum number of chunks in the buffer.
            writer_rank (int, optional): The global rank that will act as the writer.
                Defaults to 0.
            external_writer_handle (Handle, optional): Used when there is a handle
                from an external Message Queue. If provided, use this handle to init
                PG writer message queue instead of creating a new one. Defaults to None.
            blocking (bool, optional): If True, blocks until all processes are ready.
                Defaults to True.

        Returns:
            MessageQueue: The MessageQueue instance for the calling process.

        r   )in_the_same_node_as)source_rankNc                     g | ]	\  }}||
S r"   r"   ).0r   ss      r$   
<listcomp>z:MessageQueue.create_from_process_group.<locals>.<listcomp>  s!    "H"H"HAa"H1"H"H"Hr#   rS   c                      g | ]
}|k    |S r"   r"   )r  r   r  s     r$   r
  z:MessageQueue.create_from_process_group.<locals>.<listcomp>  s#    %U%U%UAADTDTaDTDTDTr#   )rN   r   r   rO   rP   )srcr   )
isinstancer   r   r   r   get_process_group_ranksr   
world_sizer   r   vllm.distributed.parallel_stater  r   r   	enumerater   r   broadcast_object_listbroadcast_objr   )r   rO   rP   r  external_writer_handler   
group_rankgroup_world_sizeglobal_ranksr  statusr   same_node_ranksrN   r   r   rh   r   s      `              r$   create_from_process_groupz&MessageQueue.create_from_process_group  s>   F b,'' 	6r**J#22667;;LLJ!}bm 4 455LGGGGGG$$R[AAA$$%1(;;*J 		 #I"H61B1B"H"H"H+a/!$_!5!5!9%U%U%U%U%U%U%U"(%#1'9$3)  	 ,,..F"l++ 6*H,{";2       5555"l++ =v*l;7r    a))$<<$77
KKI 	)&&(((r#   )Nr   r   Nr2   )NNF)r   F)r   NT)r8   r9   r:   r   rz   r{   rE   r}   r   staticmethodr   r   r   rK   r   r   r   r   r   r   zmqSocketr
   r   r   r   r   r  r   r  r"   r#   r$   r   r     s       
 04  0!%QQ QQ !I,	QQ QQ QQ $JQQ QQ QQ QQfv     +6 +N + + + \+Z$ $ $B ; ;UT\ ; ; ; ^;z  !%# 	> >> > 	> > > ^>@)G )GEDL )G )G )G )GZ !%# 	   	   8 4SZ 4%$, 43 4 4 4 \4    
 +< +<+< 	+<
 +< 
~tF|+	,+< +< +< \+<Z 
 #Q Q00Q 	Q Q 
Q Q Q \Q Q Qr#   r   )B	functoolsr   	threadingrB   
contextlibr   dataclassesr   r   multiprocessingr   r   r   typingr	   r
   r   unittest.mockr   ra   torch.distributeddistributedr   r  r   r   r   r   r   r   r   	vllm.envsr   vllm.distributed.utilsr   r   vllm.loggerr   vllm.platformsr   vllm.utils.network_utilsr   r   r   r   	_typeshedr   r   partialrz   
from_bytesr   Lockr!   r%   bytesr+   r8   r   r{   r.   r0   r<   rM   r}   r   r"   r#   r$   <module>r1     s             % % % % % % ( ( ( ( ( ( ( ( ) ) ) ) ) )             + + + + + + + + + +                    



 * * * * * *                      E E E E E E E E # # # # # # + + + + + +             &%%%%%%#'#H  ""3>UCCC $Y^%%   *1 13 15 1 1 1 1 
X		# #               Y   8D D D D D D D DN # # # # # # # #z z z z z z z z z zr#   