o
    پiN                     @   s   d Z ddlZddlZe  ddlm  mZ ddlm	Z	m
Z
 dZdZejjZdd Zeej_e Zdd	ed
edefddZdS )z
Do some monkey patch to make the documentation compilation faster and more reliable.

- Avoid port conflicts
- Reduce the server launch time
    N)execute_shell_commandreserve_port   i P  c                 C   s2   t |  | jd u rt| _| jd u rt| _d| _d S )N   )_original_post_initmax_running_requestsDEFAULT_MAX_RUNNING_REQUESTSmax_total_tokensDEFAULT_MAX_TOTAL_TOKENScuda_graph_max_bs)self r   I/home/ubuntu/.local/lib/python3.10/site-packages/sglang/test/doc_patch.pypatched_post_init   s   


r   0.0.0.0commandhostportc                 C   s`   |du rt |\}}nd}dt dt d}|  d| d| }t|}|dur,|t|< ||fS )zj
    Launch the server using the given command.
    If no port is specified, a free port is reserved.
    Nz--max-running-requests z --max-total-tokens z --cuda-graph-max-bs 4z --port  )r   r   r
   r   process_socket_map)r   r   r   lock_socketextra_flagsfull_commandprocessr   r   r   launch_server_cmd%   s   r   )r   N)__doc__weakrefnest_asyncioapplysglang.srt.server_argssrtserver_argsserver_args_modsglang.utilsr   r   r   r
   
ServerArgs__post_init__r   r   WeakKeyDictionaryr   strintr   r   r   r   r   <module>   s    	