
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SrS	 rS
 r\R$                  \R&                  " \R(                  R*                  5       " S S\
R,                  5      5       5       rg)z7Outputs benchmarking data for GKE Inference Quickstart.    )
exceptions)util)base)commands)profiles_csv_printer)resource_printerz
To get benchmarking data for a given model and model server, run:

$ {command} --model=google/gemma-2-27b-it --model-server=vllm --pricing-model=spot
c                 X    U R                   nU(       d  SnXR                  S-  -   7nU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   !   s2    
**%	EJJ,,--#    c                     SnU (       a,  U S   R                   (       a  [        U S   R                   5      nSnU (       a,  U S   R                  (       a  [        U S   R                  5      nX!4$ )zjReturns 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   *   sa     
uQx22)%(*M*MN
uQx11(q)K)KL
	..r   c                   .    \ rS rSrSr\S 5       rS rSrg)List9   a  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                    U R                  SSSS9  U R                  SSSS9  U R                  SSS	9  U R                  S
SS	9  U R                  SSS	9  U R                  SSSS9  [        R                  " [        R                  [        R
                  5        U R                  R                  [        R                  5        g )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.z--pricing-modelFzsThe pricing model to use to calculate token cost. Currently, this supports on-demand, spot, 3-years-cud, 1-year-cud)add_argumentr   RegisterFormatterr   PROFILES_PRINTER_FORMATProfileCSVPrinterdisplay_info	AddFormat)parsers    r   Args	List.ArgsF   s    
  
    
            A	   &&44.. !!"6"N"NOr   c                 Z   [         R                  " [        R                  R                  5      n[         R
                  " [        R                  R                  5      n UR                  UR                  UR                  UR                  S9nUR                  UUR                  UR                  S9nUR                  R                  U5      nUR                  (       d  / $ UR                  $ ! [         R"                   a*  n[$        R&                  " U[         R(                  5      eS nAff = f)N)modelmodelServermodelServerVersion)modelServerInfoinstanceTypepricingModel)r   GetClientInstancer   ReleaseTrackGAGetMessagesModuleModelServerInfor(   model_servermodel_server_versionFetchBenchmarkingDataRequestinstance_typepricing_modelbenchmarkingDataFetchprofileapitools_exceptions	HttpErrorr   HttpExceptionHTTP_ERROR_FORMAT)selfargsclientmessagesmodel_server_inforequestresponseerrors           r   RunList.Runy   s    ##D$5$5$8$89F%%d&7&7&:&:;HD"22

''!66 3 
 55+)))) 6 g
 ((..w7h	(( D$$UD,B,BCCDs   BC,  C, ,D* %D%%D* N)	__name__
__module____qualname____firstlineno____doc__staticmethodr%   rG   __static_attributes__rI   r   r   r   r   9   s$     0P 0PdDr   r   N)rN   apitools.base.pyr   r;   %googlecloudsdk.api_lib.ai.recommenderr   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper   googlecloudsdk.command_lib.runr   'googlecloudsdk.command_lib.run.printersr   googlecloudsdk.core.resourcer   _EXAMPLEr   r   DefaultUniverseOnlyReleaseTracksr/   r0   r   rI   r   r   <module>r[      sz    > > 6 2 ( 3 H 9 / D%%(()SD8== SD * SDr   