
    K*                        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  \	R                  \	R                  " \	R                   R"                  5       " S S\	R$                  5      5       5       r\	R                  \	R                  " \	R                   R(                  5       " S	 S
\	R$                  5      5       5       rg)zFGenerates optimized Kubernetes manifests for GKE Inference Quickstart.    )
exceptions)util)base)log)filesc                   4    \ rS rSrSr\S 5       rS rS rSr	g)Create   t  Generate ready-to-deploy Kubernetes manifests with compute, load balancing, and autoscaling capabilities.

To get supported model, model servers, and model server versions, run `gcloud
alpha container ai profiles model-and-server-combinations list`. To get
supported accelerators with their performance metrics, run `gcloud alpha
container ai profiles accelerators list`.
c                 f   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  U R                  SSS	9  U R                  S/ SQSSS9  U R                  SSS	9  U R                  SSS	9  g )N--modelT
The model.requiredhelp--model-serverThe model server.--model-server-versionPThe model server version. If not specified, this defaults to the latest version.r   --target-ntpot-milliseconds  The maximum normalized time per output token (NTPOT) in milliseconds. NTPOT is measured as the request_latency / output_tokens. If this is set, the manifests will include Horizontal Pod Autoscaler (HPA) resources which automatically adjust the model server replica count in response to changes in model server load to keep p50 NTPOT below the specified threshold. If the provided target-ntpot-milliseconds is too low to achieve, the HPA manifest will not be generated. typer   z--target-ttft-millisecondszIf specified, results will only show accelerators that can meet the latency target and will show their throughput performances at the target ttft target to achieve, the HPA manifest will not be generated. --accelerator-typeThe accelerator type.--namespaceIThe namespace to deploy the manifests in. Default namespace is 'default'.--outputmanifestcommentsallr#   &The output to display. Default is all.choicesdefaultr   --output-pathIThe path to save the output to. If not specified, output to the terminal.--model-bucket-urizThe Google Cloud Storage bucket URI to load the model from. This URI must point to the directory containing the model's config file (config.json) and model weights. If unspecified, defaults to loading the model from Hugging Face.add_argumentintparsers    5lib/surface/container/ai/profiles/manifests/create.pyArgsCreate.Args%   s0   
  
    
     %D	   $	  	 $  
    /5	      4      c                    [         R                  " [        R                  R                  5      n[         R
                  " [        R                  R                  5      n UR                  UR                  UR                  UR                  S9nUR                  5       nUR                  (       a  UR                  Ul        UR                  (       a  UR                  Ul        UR                  5       nUR                   (       a  UR                   Ul        UR%                  UUR&                  UR(                  S9nUR                  c  UR                  b  XWl        UR"                  b  Xgl        UR.                  R1                  U5      nU$ ! [2        R4                   a*  n	[6        R8                  " U	[         R:                  5      eS n	A	ff = f)N)modelmodelServermodelServerVersion)modelServerInfoacceleratorTypekubernetesNamespace)r   GetClientInstancer   ReleaseTrackGAGetMessagesModuleModelServerInfor5   model_servermodel_server_versionPerformanceRequirementstarget_ntpot_millisecondstargetNtpotMillisecondstarget_ttft_millisecondstargetTtftMillisecondsStorageConfigmodel_bucket_urimodelBucketUri GenerateOptimizedManifestRequestaccelerator_type	namespaceperformanceRequirementsstorageConfigoptimizedManifestGenerateapitools_exceptions	HttpErrorapi_lib_exceptionsHttpExceptionHTTP_ERROR_FORMAT)
selfargsclientmessagesmodel_server_infoperformance_requirementsstorage_configrequestresponseerrors
             r0   Run
Create.Runs   s   ##D$5$5$8$89F%%d&7&7&:&:;H#L"22

''!66 3 
 "*!A!A!C		'	'** 	!8 
	&	&)) 	!7  --/n			(,(=(=%99+//"nn : g #
:
:
F%<<H*B'		&	&	2 .))227;ho(( L,,UD4J4JKKLs   D)F G%GGc                    U(       d   [         R                  R                  S5        g SnUR                  S:w  a$  UR                   H  nX4R
                  S-   -  nM     UR                  (       a3  SR                  UR                   Vs/ s H  nSU 3PM
     sn5      nX6-  nUR                  (       ai   [        R                  " UR                  U5       nUR                  U5        S S S 5        [         R                  R                  SUR                   35        g [         R                  R                  U5        g s  snf ! , (       d  f       N`= f! [        R                   a#  n[         R                  " SU 35         S nAg S nAff = f)	NNo manifests generated. r"   
---

# Output saved to /An error occurred while saving output to file: )r   outPrintoutputkubernetesManifestscontentr"   joinoutput_pathr   
FileWriterwriter   Errorr_   	rV   rW   	resourcesoutput_contentr!   linecomment_stringfes	            r0   DisplayCreate.Display   s5   	ggmm-.N{{j 33(**Y66 4 yy):L:L!M:L$Btf+:L!MNn&nId..?1
''.
! @()9)9(:;< 
ggmmN# "N
 @?  I		CA3GHHIs6   D<4!E E'4E 
EE F	&FF	 N
__name__
__module____qualname____firstlineno____doc__staticmethodr1   r`   r{   __static_attributes__r}   r3   r0   r	   r	      s*     K KZ'LR$r3   r	   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)CreateAlpha   r   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S9  U R                  SSS	9  U R                  S/ SQSSS9  U R                  SSS	9  U R                  SSSS9  g )Nr   Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r#   r$   r%   r(   r)   r*   zQGCS bucket URI to pull model from. If not specified, default to the model hoster.)hiddenr   r+   r.   s    r0   r1   CreateAlpha.Args   s   
  
    
     %D	   $  
    /5	      $	  r3   c           
      h   [         R                  " [        R                  R                  5      n[         R
                  " [        R                  R                  5      n UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9nUR                  R                  U5      nU$ ! [         R"                   aG  n[$        R&                  " SU 35        [$        R(                  R+                  SU 35        / s S nA$ S nAff = f)N)!modelAndModelServerInfo_modelName'modelAndModelServerInfo_modelServerName*modelAndModelServerInfo_modelServerVersionrD   r9   r:   storageConfig_modelBucketUrizAn error has occurred: )r   r;   r   r<   ALPHAr>   &GkerecommenderOptimizedManifestRequestr5   r@   rA   rC   rK   rL   rH   v1alpha1OptimizedManifestr   rs   r   r_   statusrk   )rV   rW   rX   rY   r]   r^   rz   s          r0   r`   CreateAlpha.Run  s    ##D$5$5$;$;<F%%d&7&7&=&=>H??,0JJ262C2C595N5N"&"@"@//"nn'+'<'< @ g 227;ho 	ii)!-.	jj045is   A7C D1*<D,&D1,D1c                 x   U(       d   [         R                  R                  S5        g SnUR                  S:X  d  UR                  S:X  a$  UR                   H  nX4R
                  S-   -  nM     UR                  S:X  d  UR                  S:X  aD  UR                  (       a3  SR                  UR                   Vs/ s H  nSU 3PM
     sn5      nX6-  nUR                  (       ai   [        R                  " UR                  U5       nUR                  U5        S S S 5        [         R                  R                  S	UR                   35        g [         R                  R                  U5        g s  snf ! , (       d  f       N`= f! [        R                   a#  n[         R                  " S
U 35         S nAg S nAff = f)Nrc   rd   r!   r#   re   r"   rf   rg   rh   ri   )r   rj   rk   rl   k8sManifestsrn   r"   ro   rp   r   rq   rr   r   rs   r_   rt   s	            r0   r{   CreateAlpha.Display  sW   	ggmm-.N{{j DKK5$8,,(**Y66 - {{j DKK5$8			I<N<N#O<NDbK<N#OP(Id..?1
''.
! @()9)9(:;< 
ggmmN# $P
 @?  I		CA3GHHIs6   8E,$!F E14F 1
E?;F F9F44F9r}   Nr~   r}   r3   r0   r   r      s(     @ @D*$r3   r   N)r   apitools.base.pyr   rQ   %googlecloudsdk.api_lib.ai.recommenderr   googlecloudsdk.api_lib.utilrS   googlecloudsdk.callioper   googlecloudsdk.corer   googlecloudsdk.core.utilr   DefaultUniverseOnlyReleaseTracksr<   r=   CreateCommandr	   r   r   r}   r3   r0   <module>r      s    M > 6 H ( * # * D%%(()V$T V$ * V$r D%%++,x$$$$ x$ - x$r3   