
    S                        d 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 ddlmZ d	Zd
 Zd Zej"                   ej$                  ej&                  j(                         G d dej*                                      Zy)z7Outputs benchmarking data for GKE Inference Quickstart.    )util)base)commands)profiles_csv_printer)
exceptions)log)resource_printerz
To get benchmarking data for a given model and model server, run:

$ {command} --model=google/gemma-2-27b-it--model-server=vllm
c                 P    | j                   }|sd}|| j                  dz  z   }|dS )z*Converts cost to a decimal representation.r   g    eAz.3f)unitsnanos)costr   decimal_values      4lib/surface/container/ai/profiles/benchmarks/list.pyamount_to_decimalr       s4    
**%	EDJJ,,--#    c                     d}| r'| d   j                   rt        | d   j                         }d}| r'| d   j                  rt        | d   j                        }||fS )zpReturns the cost per million normalized output tokens as a decimal.

  Args:
    costs: The costs to convert.
  zN/Ar   )costPerMillionOutputTokensr   costPerMillionInputTokens)costsoutput_token_costinput_token_costs      r   get_decimal_costr   )   sd     
uQx22)%(*M*MN
uQx11(q)K)KL
-	..r   c                   &    e Zd ZdZed        Zd Zy)Lista  List benchmarks for a given model and model server.

  This command lists all benchmarking data for a given model and model server.
  By default, the benchmarks are displayed in a CSV format.

  For examples of visualizing the benchmarking data, see the accompanying Colab
  notebook:
  https://colab.research.google.com/github/GoogleCloudPlatform/kubernetes-engine-samples/blob/main/ai-ml/notebooks/giq_visualizations.ipynb
  c                 |   | j                  ddd       | j                  ddd       | j                  dd	       | j                  d
d	       | j                  dd	       t        j                  t        j                  t        j
                         | j                  j                  t        j                         y )Nz--modelTz
The model.)requiredhelpz--model-serverzThe model server.z--model-server-versionzThe model server version. Default is latest. Other options include the model server version of a profile, all which returns all versions.)r   z--instance-typezGThe instance type. If not specified, this defaults to anyinstance type.z--formatzThe format to print the output in. Default is csvprofile, which displays the profile information in a CSV format, includingcost conversions.)add_argumentr	   RegisterFormatterr   PROFILES_PRINTER_FORMATProfileCSVPrinterdisplay_info	AddFormat)parsers    r   Argsz	List.ArgsE   s    
  
    
            &&44.. !!"6"N"NOr   c                 x   t        j                  t        j                  j                        }t        j
                  t        j                  j                        }	 |j                  |j                  |j                  |j                        }|j                  ||j                        }|j                  j                  |      }|j                  sg S |j                  S # t        j                   $ rF}t#        j$                  d|        t"        j&                  j)                  d|        g cY d }~S d }~ww xY w)N)modelmodelServermodelServerVersion)modelServerInfoinstanceTypezAn error has occurred: )r   GetClientInstancer   ReleaseTrackGAGetMessagesModuleModelServerInfor'   model_servermodel_server_versionFetchBenchmarkingDataRequestinstance_typebenchmarkingDataFetchprofiler   Errorr   errorstatusPrint)selfargsclientmessagesmodel_server_inforequestresponsees           r   RunzList.Runo   s   ##D$5$5$8$89F%%d&7&7&:&:;H"22

''!66 3 
 55+)) 6 g ((..w7h	 	ii)!-.	jj045is%   A7C  C   D93;D4.D94D9N)__name__
__module____qualname____doc__staticmethodr%   rD    r   r   r   r   8   s#     'P 'PRr   r   N)rH   %googlecloudsdk.api_lib.ai.recommenderr   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   'googlecloudsdk.command_lib.run.printersr   googlecloudsdk.corer   r   googlecloudsdk.core.resourcer	   _EXAMPLEr   r   DefaultUniverseOnlyReleaseTracksr-   r.   r   rJ   r   r   <module>rT      sy    > 6 ( 3 H * # 9 / D%%(()K8== K * Kr   