o
    i                     @   s   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ ed ZeG d	d
 d
ZdS )    )cached_property)AnyLiteralcastparse)Fieldfield_validatormodel_validator)version)config)	safe_hash)modelworkerallc                   @   s  e Zd ZU dZdZedB ed< 	 edefddZ	dZ
edB ed< 	 dZee dB ed< 	 d	Zeed
< 	 edd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efddZedefddZdefddZedededB dedB fddZedededB dedB fddZededee dB dee dB fd d!Zed"d#d$d% Z dS )&ObservabilityConfigz6Configuration for observability - metrics and tracing.Nshow_hidden_metrics_for_versionreturnc                 C   s   | j du rdS t| j S )z,Check if the hidden metrics should be shown.NF)r   r   _prev_minor_version_wasself r   O/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm/config/observability.pyshow_hidden_metrics   s   
z'ObservabilityConfig.show_hidden_metricsotlp_traces_endpointcollect_detailed_tracesFkv_cache_metricsg{Gz?r      )defaultgtlekv_cache_metrics_samplecudagraph_metricsenable_layerwise_nvtx_tracingenable_mfu_metricsenable_mm_processor_stats enable_logging_iteration_detailsc                 C      | j duod| j v pd| j v S )z6Whether to collect model forward time for the request.Nr   r   r   r   r   r   r   collect_model_forward_timeO      

z.ObservabilityConfig.collect_model_forward_timec                 C   r'   )z6Whether to collect model execute time for the request.Nr   r   r(   r   r   r   r   collect_model_execute_timeW   r*   z.ObservabilityConfig.collect_model_execute_timec                 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)r   factorshash_strr   r   r   compute_hash_   s   z ObservabilityConfig.compute_hashvaluec                 C   s   |d urt | |S )Nr   clsr3   r   r   r   )_validate_show_hidden_metrics_for_versionq   s   z=ObservabilityConfig._validate_show_hidden_metrics_for_versionc                 C   s0   |d urddl m}m} | std| |S )Nr   )is_tracing_availableotel_import_error_tracebackzOpenTelemetry is not available. Unable to configure 'otlp_traces_endpoint'. Ensure OpenTelemetry packages are installed. Original error:
)vllm.tracingr7   r8   
ValueError)r5   r3   r7   r8   r   r   r   _validate_otlp_traces_endpointy   s   z2ObservabilityConfig._validate_otlp_traces_endpointc                 C   s<   |durt |dkrd|d v rttt |d d}|S )zoHandle the legacy case where users might provide a comma-separated
        string instead of a list of strings.Nr   ,r   )lenr   listDetailedTraceModulessplitr4   r   r   r   !_validate_collect_detailed_traces   s    z5ObservabilityConfig._validate_collect_detailed_tracesafter)modec                 C   s   | j r
| js
td| S )NzDcollect_detailed_traces requires `--otlp-traces-endpoint` to be set.)r   r   r:   r   r   r   r   _validate_tracing_config   s
   z,ObservabilityConfig._validate_tracing_config)!__name__
__module____qualname____doc__r   r-   __annotations__r   boolr   r   r   r>   r?   r   r   r!   floatr"   r#   r$   r%   r&   r)   r+   r2   r	   classmethodr6   r;   rA   r
   rD   r   r   r   r   r      sX   
 

	r   N)	functoolsr   typingr   r   r   packaging.versionr   pydanticr   r	   r
   vllmr   vllm.config.utilsr   vllm.utils.hashingr   r?   r   r   r   r   r   <module>   s   