
    -`iA                         d dl Z d dlmZ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 d dlmZ d dlmZ  ee          Zed	         Zd
edefdZee G d d                                  ZdS )    N)AnyLiteral)Fieldmodel_validator)	dataclass)Self)config)init_logger)	safe_hash)torchcudapathreturnc                 j    d| v r.|                      d          d         }t          |          dk    S dS )zCheck if path is a URI (scheme://...), excluding Windows drive letters.

    Supports custom URI schemes like gs://, s3://, hdfs://, etc.
    These paths should not be converted to absolute paths.
    z://r      F)splitlen)r   schemes     h/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/config/profiler.py_is_uri_pathr      s:     }}E""1% 6{{Q5    c                   h   e Zd ZU dZdZedz  ed<   	 dZeed<   	 dZ	e
ed<   	 dZe
ed	<   	 dZe
ed
<   	 dZe
ed<   	 dZe
ed<   	 dZe
ed<   	 dZe
ed<   	  edd          Zeed<   	  edd          Zeed<   	 defdZdededdfdZ	 	 ddedede
de
ddf
dZ ed          defd            ZdS )ProfilerConfigz8Dataclass which contains profiler config for the engine.Nprofiler torch_profiler_dirTtorch_profiler_with_stackFtorch_profiler_with_flopstorch_profiler_use_gzip#torch_profiler_dump_cuda_time_totaltorch_profiler_record_shapestorch_profiler_with_memoryignore_frontendr   )defaultgedelay_iterationsmax_iterationsr   c                     g }t          t          |                                          d                                          }|S )a  
        WARNING: Whenever a new field is added to this config,
        ensure that it is included in the factors list if
        it affects the computation graph.

        Provide a hash that uniquely identifies all the configs
        that affect the structure of the computation
        graph from input ids/embeddings to the final hidden states,
        excluding anything before input ids/embeddings and after
        the final hidden states.
        F)usedforsecurity)r   strencode	hexdigest)selffactorshash_strs      r   compute_hashzProfilerConfig.compute_hashW   s>      S\\0022EJJJTTVVr   
field_nameenv_var_namec                     t          j        |          r4t          t           |          }t                              d|||           |S dS )z8Get field from env var if set, with deprecation warning.zUsing %s environment variable is deprecated and will be removed in v0.15.0 or v1.0.0, whichever is soonest. Please use --profiler-config.%s command line argument or ProfilerConfig(%s=...) config field instead.N)envsis_setgetattrloggerwarning_once)r-   r1   r2   values       r   _get_from_env_if_setz#ProfilerConfig._get_from_env_if_seti   sY     ;|$$ 	D,//E?    Ltr   to_boolto_intc                     |                      ||          }|,|r|dk    }|rt          |          }t          | ||           dS dS )z8Set field from env var if set, with deprecation warning.N1)r:   intsetattr)r-   r1   r2   r;   r<   r9   s         r   _set_from_env_if_setz#ProfilerConfig._set_from_env_if_setz   sc     ))*lCC % #E

D*e,,,,, r   after)modec                    |                      dd          }||dk    rdnd | _        n|                     ddd           | j        rd	| _        |                     d
d           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dddd           |                     dddd           | j        dk    p
| j        dk    }| j        d	k    r#|r!| j        st                              d           | j        }|r| j        d	k    rt          d           | j        d	k    r|st          d!          |rPt          |          sAt          j                            t          j                            |                    | _        | S )"Nr   VLLM_TORCH_CUDA_PROFILEr>   r   r   VLLM_TORCH_PROFILER_DIRF)r;   r   r!   !VLLM_TORCH_PROFILER_RECORD_SHAPESr"   'VLLM_TORCH_PROFILER_WITH_PROFILE_MEMORYr   VLLM_TORCH_PROFILER_WITH_STACKr   VLLM_TORCH_PROFILER_WITH_FLOPSr#   %VLLM_TORCH_PROFILER_DISABLE_ASYNC_LLMr   VLLM_TORCH_PROFILER_USE_GZIPr    (VLLM_TORCH_PROFILER_DUMP_CUDA_TIME_TOTALr&   VLLM_PROFILER_DELAY_ITERST)r;   r<   r'   VLLM_PROFILER_MAX_ITERSr   zzUsing 'torch' profiler with delay_iterations or max_iterations while ignore_frontend is False may result in high overhead.zEtorch_profiler_dir is only applicable when profiler is set to 'torch'z7torch_profiler_dir must be set when profiler is 'torch')r:   r   rA   r   r&   r'   r#   r7   r8   
ValueErrorr   osr   abspath
expanduser)r-   maybe_use_cuda_profilerhas_delay_or_limitprofiler_dirs       r   _validate_profiler_configz(ProfilerConfig._validate_profiler_config   s   "&";";1#
 #
 #.&=&D&DFF$DMM%%$&? &    &  '))27   ))0=   ))/4   ))/4   ))%;   ))-2   ))9>  
 	!! ;USW 	" 	
 	
 	
 	!!7t 	" 	
 	
 	
 "2Q6Q$:MPQ:Q=G##(:#4CW#N  
 . 	DMW44W   =G##L#VWWW  	X\ : : 	X&(goobg6H6H6V6V&W&WD#r   )TF)__name__
__module____qualname____doc__r   ProfilerKind__annotations__r   r*   r   boolr   r   r    r!   r"   r#   r   r&   r?   r'   r0   r:   rA   r   r   rW    r   r   r   r   #   s         CB$(HlT!((($
 !   $ '+t***U&+t+++W$(T(((S04'444X). $...V',,,, "OT!!! "E!222c222  %a000NC000c    $s # $    * - -- - 	-
 - 
- - - -  _'"""D4 D D D #"D D Dr   r   )rQ   typingr   r   pydanticr   r   pydantic.dataclassesr   typing_extensionsr   	vllm.envsr4   vllm.config.utilsr	   vllm.loggerr
   vllm.utils.hashingr   rX   r7   r\   r*   r^   r   r   r_   r   r   <module>rh      s9   
			         + + + + + + + + * * * * * * " " " " " "       $ $ $ $ $ $ # # # # # # ( ( ( ( ( (	X		's t     
j j j j j j j  j j jr   