
                             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Zd	 Zd
 Zd Zej"                   ej$                  ej&                  j(                         G d dej*                                      Zy)zCLists compatible accelerator profiles for GKE Inference Quickstart.    )util)base)commands)profiles_csv_printer)profiles_printer_ga)resource_printerzx
To list compatible accelerator profiles for a model, run:

$ {command} --model=deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
c                 B    t        |       }t        | |z
  dz        }||fS )z5Converts a decimal representation to an Amount proto.    eA)int)decimal_valueunitsnanoss      )lib/surface/container/ai/profiles/list.pydecimal_to_amountr       s,     m
%
}u$+
,%
    c                 P    | j                   }|sd}|| j                  dz  z   }|dS )z*Converts cost to a decimal representation.r   r
   z.3fr   r   )costr   r   s      r   amount_to_decimalr   )   s4    
**%	EDJJ,,--#r   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   2   si     
uQx22)a++ 
uQx11(q)K)KL
-	..r   c                   &    e Zd ZdZed        Zd Zy)Lista  List compatible accelerator profiles.

  This command lists all supported accelerators with their performance details.
  By default, the supported accelerators are displayed in a table format with
  select information for each accelerator. To see all details, use
  --format=yaml or --format=csvprofile.

  To get supported model, model servers, and model server versions, run `gcloud
  container ai profiles models list`, `gcloud container ai
  profiles model-servers list`, and `gcloud container ai profiles
  model-server-versions list`.
  c                    | j                  dd       | j                  dd       | j                  dd       | j                  dt        d	
       | j                  dt        d
       | j                  dt        dd       | j                  dt        dd       | j                  ddt        d       | j                  dd       t	        j
                  t        j                  t        j                  d       t	        j
                  t        j                  t        j                  d       | j                  j                  t        j                         y )Nz--modelz
The model.)helpz--model-serverzThe model server version. Default is latest. Other options include the model server version of a profile, all which returns all versions.z--model-server-versionzPThe model server version. If not specified, this defaults to the latest version.z--target-ntpot-millisecondsa  The target normalized time per output token (NTPOT) in milliseconds. NTPOT is measured as the request_latency / output_tokens. If this field is set, the command will only return accelerators that can meet the target ntpot milliseconds and display their throughput performance at the target latency. Otherwise, the command will return all accelerators and display their highest throughput performance.)typer    z--target-ttft-millisecondsax  The target time to first token (TTFT) in milliseconds. TTFT is measured as the request_latency / output_tokens. If this field is set, the command will only return profiles that can meet the target ttft milliseconds and display their throughput performance at the target latency. Otherwise, the command will return all profiles and display their highest throughput performance.z'--target-cost-per-million-output-tokensFzfThe target cost per million output tokens to filter profiles by, unit is 1 USD up to 5 decimal places.)r!   requiredr    z&--target-cost-per-million-input-tokenszeThe target cost per million input tokens to filter profiles by, unit is 1 USD up to 5 decimal places.z--pricing-modelzsThe pricing model to use to calculate token cost. Currently, this supports on-demand, spot, 3-years-cud, 1-year-cud)r"   r!   r    z--formatzThe output format. Default is profile, which displays the profile information in a table format, including cost conversions. csvprofile displays the profile information in a CSV format.Options include csvprofile, profile, and yaml. T)hidden)add_argumentr   floatstrr   RegisterFormatterprofiles_printerPROFILES_PRINTER_FORMATProfilePrinterr   ProfileCSVPrinterdisplay_info	AddFormat)parsers    r   Argsz	List.ArgsS   s   
          %5	   $5	   15   05   A   F   &&00''
 &&44..
 !!"2"J"JKr   c                    t        j                  t        j                  j                        }t        j
                  t        j                  j                        }|j                         }|j                  r|j                  |_        |j                  r|j                  |_
        |j                  s|j                  s|j                  r|j                         }|j                  r0t        |j                        \  }}|j!                  ||      |_        |j                  r0t        |j                        \  }}|j!                  ||      |_        |j                  r|j                  |_        ||_        |j+                  |j,                  |j.                  |j0                        }|j                  |j                  |j(                  ||_        |j4                  j7                  |      }	|	j8                  r|	j8                  S g S )Nr   )modelmodelServermodelServerVersion)r   GetClientInstancer   ReleaseTrackGAGetMessagesModulePerformanceRequirementstarget_ntpot_millisecondstargetNtpotMillisecondstarget_ttft_millisecondstargetTtftMilliseconds%target_cost_per_million_output_tokens$target_cost_per_million_input_tokenspricing_modelCostr   Amountr   r   pricingModel
targetCostFetchProfilesRequestr1   model_servermodel_server_versionperformanceRequirementsprofilesFetchprofile)
selfargsclientmessagesperformance_requirementsr   r   r   requestresponses
             r   RunzList.Run   s   ##D$5$5$8$89F%%d&7&7&:&:;H'??A%%

(
( 6 $$

'
' 5
 	2244]]_d		3	3(66
u +3//u +: +
' 
	2	2(55
u *2u *9 *
& 
		 ..,0)++jj%%44 , G 	!88D#::F#..:(@g%$$W-Hir   N)__name__
__module____qualname____doc__staticmethodr/   rR    r   r   r   r   C   s%     ]L ]L~6r   r   N)rV   %googlecloudsdk.api_lib.ai.recommenderr   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   'googlecloudsdk.command_lib.run.printersr   r   r(   googlecloudsdk.core.resourcer   	_EXAMPLESr   r   r   DefaultUniverseOnlyReleaseTracksr5   r6   r   rX   r   r   <module>ra      s|    J 6 ( 3 H [ 9	 /" D%%(()d8== d * dr   