o
    -iA                     @   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 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eG dd dZdS )    N)AnyLiteral)Fieldmodel_validator)	dataclass)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   Q/home/ubuntu/veenaModal/venv/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dededdfddZ		d"dedede
de
dd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_hashW   s   zProfilerConfig.compute_hash
field_nameenv_var_namec                 C   s,   t |rt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)   r-   r.   valuer   r   r   _get_from_env_if_seti   s   

	z#ProfilerConfig._get_from_env_if_setto_boolto_intc                 C   s@   |  ||}|dur|r|dk}|rt|}t| || dS dS )z8Set field from env var if set, with deprecation warning.N1)r5   intsetattr)r)   r-   r.   r6   r7   r4   r   r   r   _set_from_env_if_setz   s   z#ProfilerConfig._set_from_env_if_setafter)modec                 C   sF  |  dd}|d ur|dkrdnd | _n8| jdddd | jrLd	| _| d
d | dd | dd | dd | dd | dd | dd | jddddd | jddddd | jdkpg| jdk}| jd	krw|rw| jswtd | j}|r| jd	krt	d | jd	kr|st	d!|rt
|stjtj|| _| S )"Nr   VLLM_TORCH_CUDA_PROFILEr8   r   r   VLLM_TORCH_PROFILER_DIRF)r6   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)r6   r7   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')r5   r   r;   r   r#   r$   r    r2   r3   
ValueErrorr   osr   abspath
expanduser)r)   maybe_use_cuda_profilerhas_delay_or_limitprofiler_dirr   r   r   _validate_profiler_config   sv   z(ProfilerConfig._validate_profiler_config)TF)__name__
__module____qualname____doc__r   ProfilerKind__annotations__r   r&   r   boolr   r   r   r   r   r    r   r#   r9   r$   r,   r5   r;   r   r   rP   r   r   r   r   r   #   sR   
 
r   )rJ   typingr   r   pydanticr   r   pydantic.dataclassesr   typing_extensionsr   	vllm.envsr/   vllm.config.utilsr   vllm.loggerr	   vllm.utils.hashingr
   rQ   r2   rU   r&   rW   r   r   r   r   r   r   <module>   s   