o
    -iK                     @   s   U d dl Z d dlZd dlmZmZ d dlmZ d dlmZ dZ		 eG dd deZ
eG dd	 d	e
ZeG d
d de
ZeG dd de
ZeG dd de
ZeeeedZeeee
 f ed< G dd ded ZG dd deee
f ZdS )    N)ABCabstractmethod)	dataclass)overrideg:0yE>c                   @   s`   e Zd ZU eed< ededefddZededefddZd	e	eef d
edefddZ
dS )SLACriterionBasetargetactualreturnc                 C      t )z
        Return a negative value or `0` if this criterion is met;
        otherwise a positive value indicating the distance to the target.
        NotImplementedErrorselfr    r   \/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/benchmarks/sweep/sla_sweep.pycompute_margin   s   zSLACriterionBase.compute_marginlhsc                 C   r
   Nr   r   r   r   r   r   format_cond   s   zSLACriterionBase.format_condmetricsmetrics_keyc                 C   sL   || }|  |}| | d|d}td| d|dkr dnd  |S )Nz = .2fzValidating SLA: z | r   PASSEDFAILED)r   r   print)r   r   r   metricmargincondr   r   r   print_and_compute_margin   s
   
 z)SLACriterionBase.print_and_compute_marginN)__name__
__module____qualname__float__annotations__r   r   strr   dictr   r   r   r   r   r      s   
 
r   c                   @   8   e Zd ZededefddZededefddZdS )	SLALessThanr   r	   c                 C   s   |t  | j S r   )SLA_EPSr   r   r   r   r   r   .      zSLALessThan.compute_marginr   c                 C      | d| j dS )N<r   r   r   r   r   r   r   2      zSLALessThan.format_condNr    r!   r"   r   r#   r   r%   r   r   r   r   r   r(   ,   
    r(   c                   @   r'   )	SLALessThanOrEqualTor   r	   c                 C   s
   || j  S r   r-   r   r   r   r   r   9      
z#SLALessThanOrEqualTo.compute_marginr   c                 C   r+   )N<=r   r-   r   r   r   r   r   =   r.   z SLALessThanOrEqualTo.format_condNr/   r   r   r   r   r1   7   r0   r1   c                   @   r'   )	SLAGreaterThanr   r	   c                 C   s   | j t | S r   )r   r)   r   r   r   r   r   D   r*   zSLAGreaterThan.compute_marginr   c                 C   r+   )N>r   r-   r   r   r   r   r   H   r.   zSLAGreaterThan.format_condNr/   r   r   r   r   r4   B   r0   r4   c                   @   r'   )	SLAGreaterThanOrEqualTor   r	   c                 C   s
   | j | S r   r-   r   r   r   r   r   O   r2   z&SLAGreaterThanOrEqualTo.compute_marginr   c                 C   r+   )N>=r   r-   r   r   r   r   r   S   r.   z#SLAGreaterThanOrEqualTo.format_condNr/   r   r   r   r   r6   M   r0   r6   )r3   r7   r,   r5   SLA_CRITERIAc                   @   s>   e Zd ZedejfddZedeee	e	f  fddZ
dS )SLASweepfilepathc                 C   s>   t |d}t|}W d    n1 sw   Y  | |S )Nrb)openjsonloadfrom_records)clsr:   frecordsr   r   r   	read_jsonb   s   
zSLASweep.read_jsonrB   c                 C   s.   t |tstdt| | dd |D S )Nz@The SLA sweep should be a list of dictionaries, but found type: c                 s   s    | ]}t |V  qd S r   )SLASweepItemfrom_record).0recordr   r   r   	<genexpr>q   s    z(SLASweep.from_records.<locals>.<genexpr>)
isinstancelist	TypeErrortype)r@   rB   r   r   r   r?   i   s   
zSLASweep.from_recordsN)r    r!   r"   classmethodosPathLikerC   rJ   r&   r%   r?   r   r   r   r   r9   a   s
     r9   rD   c                   @   s:   e Zd Zedeeef fddZd
dedefddZd	S )rD   rG   c              	   C   sn   i }|  D ],\}}tD ]}||r"t| t||||<  nqtd| d| dtt q| |S )Nz%Invalid operator for SLA constraint '=z'. Valid operators are: )itemsr8   
startswithr#   removeprefix
ValueErrorsorted)r@   rG   sla_criteria
metric_keymetric_valueop_keyr   r   r   rE   u   s(   
zSLASweepItem.from_record, sepr	   c                 C   s   | dd |  D S )Nc                 s   s    | ]
\}}| |V  qd S r   )r   )rF   kvr   r   r   rH      s    z'SLASweepItem.as_text.<locals>.<genexpr>)joinrQ   )r   r[   r   r   r   as_text   s   zSLASweepItem.as_textN)rZ   )r    r!   r"   rM   r&   r%   rE   r_   r   r   r   r   rD   t   s    )r=   rN   abcr   r   dataclassesr   typing_extensionsr   r)   r   r(   r1   r4   r6   r8   r&   r%   rL   r$   rJ   r9   rD   r   r   r   r   <module>   s0   



