o
    i                     @   s   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 eeZed Zd	ed
efddZe
G dd dZdS )    N)AnyLiteral)Fieldmodel_validator)Self)config)init_logger)	safe_hash)torchcudapathreturnc                 C   s&   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   scheme r   J/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm/config/profiler.py_is_uri_path   s   r   c                   @   s   e Zd ZU dZdZedB 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dZeed< 	 edddZeed< 	 defddZedddefd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                 C   s    g }t t| d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_strr   r   r   compute_hashT   s   zProfilerConfig.compute_hashafter)modec                 C   s   | 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r2|s2td|rCt|sCt	j
t	j
|| _| S )Nr   r
   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#   r   r   loggerwarning_oncer   
ValueErrorr   osr   abspath
expanduser)r(   has_delay_or_limitprofiler_dirr   r   r   _validate_profiler_configf   s   z(ProfilerConfig._validate_profiler_config)__name__
__module____qualname____doc__r   ProfilerKind__annotations__r   r%   r   boolr   r   r   r   r   r   r   r"   intr#   r+   r   r   r6   r   r   r   r   r   !   s6   
 r   )r1   typingr   r   pydanticr   r   typing_extensionsr   vllm.config.utilsr   vllm.loggerr   vllm.utils.hashingr	   r7   r.   r;   r%   r=   r   r   r   r   r   r   <module>   s   