o
    -i	                     @   s   d dl Z d dlZd dlZd dlZd dlmZ de jdeee	f deeef de	fddZ
G d	d
 d
ejZdede	ddfddZdS )    N)Anyargsmetrics
extra_inforeturnc                 C   s   g }t jdds|S | D ]:\}}ddt| idd| ji|||dd}|d	 d
 d d}|sDd|v rD|d |d	 d
 d d< || q|S )z
    Save the benchmark results in the format used by PyTorch OSS benchmark with
    on metric per record
    https://github.com/pytorch/pytorch/wiki/How-to-integrate-with-PyTorch-OSS-benchmark-database
     SAVE_TO_PYTORCH_BENCHMARK_FORMATFzvLLM benchmarkr   )namer   r   )r   benchmark_valuesr   )	benchmarkmodelmetricr
   r   tensor_parallel_size)osenvirongetitemsvarsr   append)r   r   r   recordsr   r	   recordtp r   V/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/benchmarks/lib/utils.py#convert_to_pytorch_benchmark_format   s*   r   c                       s4   e Zd ZdefddZdedef fddZ  ZS )
InfEncoderoc                    sX   t |tr fdd| D S t |tr fdd|D S t |tr*t|r*dS |S )Nc              
      s<   i | ]\}}t |tttttd fst|n| |qS N)
isinstancestrintfloatbooltype	clear_inf).0kvselfr   r   
<dictcomp>8   s    

z(InfEncoder.clear_inf.<locals>.<dictcomp>c                    s   g | ]}  |qS r   )r#   )r$   r&   r'   r   r   
<listcomp>?   s    z(InfEncoder.clear_inf.<locals>.<listcomp>inf)r   dictr   listr    mathisinf)r(   r   r   r'   r   r#   6   s   


zInfEncoder.clear_infr   c                    s    t  j| |g|R i |S r   )super
iterencoder#   )r(   r   r   kwargs	__class__r   r   r1   D   s    zInfEncoder.iterencode)__name__
__module____qualname__r   r#   r1   __classcell__r   r   r3   r   r   5   s    r   filenamer   c                 C   sF   t | d}tj||tdd d W d    d S 1 sw   Y  d S )Nwc                 S   s   dt | j dS )N<z is not JSON serializable>)r"   r5   )r   r   r   r   <lambda>N   s    zwrite_to_json.<locals>.<lambda>)clsdefault)openjsondumpr   )r9   r   fr   r   r   write_to_jsonH   s   "rC   )argparser@   r.   r   typingr   	Namespacer,   r   r-   r   JSONEncoderr   rC   r   r   r   r   <module>   s    


*