o
    :/i>                  	   @   s   U 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 ee	Z
daeed< e j	dded	ed
ed fddZe jd
ed fddZdaeed< dddZded
dfddZdS )    N)	Generator)CompilationMode
VllmConfig)init_loggerg        torch_compile_start_time"torch.compile took %.2f s in totalvllm_configmessagereturn)NNNc                 c   s.   t  a| j}d}|  }|jtjkr2|r2ddl}|j	ddd t
d| || }|  zEzdV  W n ty@    w t  t }|jtjkrUt
j||dd W |durvz
|ddd W dS  tyu   t
jddd	 Y dS w dS |durz	|ddd W w  ty   t
jddd	 Y w w w )
zContext manager that times torch.compile and manages depyf debugging.

    On normal exit: logs the compile time and exits depyf.
    On exception: cleans up depyf without logging (compilation failed).
    Nr   T)parentsexist_okzDumping depyf output to %slocalscopezException during depyf cleanup.)exc_info)timeperf_counterr   compilation_configcompile_debug_dump_pathmoder   VLLM_COMPILEdepyfmkdirloggerdebugprepare_debugas_posix	__enter__	Exception	info_once__exit__warning)r   r	   r   depyf_cmpathr   total_compile_time r%   e/lsinfo/ai/hellotax_ai/llm_service/venv_vllm/lib/python3.10/site-packages/vllm/compilation/monitor.pymonitor_torch_compile   sB   
r'   c                  c   sT    ddl m}  | j}t }dV  t | }| j|ks J dtjd|dd dS )zContext manager that times the initial profiling run.

    Asserts that no backend compilation occurs during the profiling run
    (all compilation should have completed before this point).
    r   )compilation_counterNzbackend compilation occurred during the initial profiling run; all compilation should be complete before the profiling run starts.z(Initial profiling/warmup run took %.2f sr   r   )vllm.compilation.counterr(   num_backend_compilationsr   r   r   r   )r(   backend_compilations_beforestartelapsedr%   r%   r&   monitor_profiling_run9   s   
r.   Tcudagraph_capturing_enabledc                   C   s   t stdd S )Nz]CUDA graph capturing detected at an inappropriate time. This operation is currently disabled.)r/   RuntimeErrorr%   r%   r%   r&   $validate_cudagraph_capturing_enabledV   s
   r1   enabledc                 C   s   | a d S )N)r/   )r2   r%   r%   r&   set_cudagraph_capturing_enabledb   s   r3   )r   )r
   N)
contextlibr   collections.abcr   vllm.configr   r   vllm.loggerr   __name__r   r   float__annotations__contextmanagerstrr'   r.   r/   boolr1   r3   r%   r%   r%   r&   <module>   s*   
'
