
    |              	          S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	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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SK$J%r%  SSK$J&r&  SSK$J'r'  Sr(Sr)Sr*Sr+Sr,Sr- " S S\%R\                  5      r/ " S S \R`                  5      r1S! r2\Rf                  " S"S#S$S%S&9r4\Rf                  " S'\5S(S)9r6\Rf                  " S*\5S+S)9r7\Rf                  " S,\5S-S)9r8\Rf                  " S.\5S/S0S19r9\Rf                  " S2S3S49r:\Rf                  " S5S6S49r;\Rf                  " S7S8S49r<\Rf                  " S9S:S49r=\Rf                  " S;/ \R|                  " 5       S<S=S>9r?S?r@S@rASSA jrB\Rf                  " SBS$SCSD9rC\Rf                  " SESFS49rD\Rf                  " SB\R                  " 5       S$\	R                  " SG5      SH9rG\Rf                  " SIS#S$S$\	R                  " SJ5      SK9rHSSM jrISSN jrJSSO jrK\Rf                  " SPSQS49rL\Rf                  " SRSSS49rM\Rf                  " ST\R                  " SU\R                  SLSV9S$SW\R                  " \'R                  R                  R                  5      SXSY9rT\Rf                  " SZS#S[S\9rU\Rf                  " S]S$SS^S_9rVS`SaSbSc.rW\!R                  " Sd\R                  " 5       R                  R                  \WSeSf9r\Sg r]Sh r^SSi jr_Sj r`\Rf                  " Sk\R                  R                  SlS)9rc\Rf                  " SmS$\dSnSo9reSp rfSq rgSr rhSs riSt rjSu rkSv rlSw rmSSx jrnSSy jroSz rpS{ rqS| rrS} rsS~ rtS ruSS jrv\!R                  " S\R                  " 5       R                  R                  SS S$S9ry\!R                  " S\R                  " 5       R                  R                  SS S$S9rz\!R                  " S\R                  " 5       R                  R                  SS S$S9r}Sr~S rS rS rS rSS jrS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rg)z>Provides common arguments for the AI Platform command surface.    )absolute_import)division)unicode_literalsN)jobs)versions_api)storage_util)actions)arg_parsers)base)concepts)
completers)iam_util)resource_args)	constants)models_util)	arg_utils)concept_parsers)
exceptions)log)
propertieszptable[box,title="Job Overview"](
  jobId,
  createTime,
  startTime,
  endTime,
  state,
  {INPUT},
  {OUTPUT})
a(  trainingInput:format='table[box,title="Training Input Summary"](
  runtimeVersion:optional,
  region,
  scaleTier:optional,
  pythonModule,
  parameterServerType:optional,
  parameterServerCount:optional,
  masterType:optional,
  workerType:optional,
  workerCount:optional,
  jobDir:optional
)'
ztrainingOutput:format='table[box,title="Training Output Summary"](
  completedTrialCount:optional:label=TRIALS,
  consumedMLUnits:label=ML_UNITS)'
  {HP_OUTPUT}
z,trainingOutput.trials.sort(trialId):format='table[box,title="Training Output Trials"](
  trialId:label=TRIAL,
  finalMetric.objectiveValue:label=OBJECTIVE_VALUE,
  finalMetric.trainingStep:label=STEP,
  hyperparameters.list(separator="
"))'
zpredictionInput:format='table[box,title="Predict Input Summary"](
  runtimeVersion:optional,
  region,
  model.basename():optional,
  versionName.basename(),
  outputPath,
  uri:optional,
  dataFormat,
  batchSize:optional
)'
zpredictionOutput:format='table[box,title="Predict Output Summary"](
  errorCount,
  nodeHours,
  outputPath,
  predictionCount
  )'
c                       \ rS rSrSrg)ArgumentErrorn    N)__name__
__module____qualname____firstlineno____static_attributes__r       1lib/googlecloudsdk/command_lib/ml_engine/flags.pyr   r   n   s    r    r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )MlEngineIamRolesCompleterr   c                 P   > [         [        U ]
  " S[        R                  SS.UD6  g )Nmodel)resource_collectionresource_destr   )superr#   __init__r   MODELS_COLLECTION)selfkwargs	__class__s     r!   r*   "MlEngineIamRolesCompleter.__init__t   s.    	
#T3 '99 r    r   )r   r   r   r   r*   r   __classcell__)r.   s   @r!   r#   r#   r   s     r    r#   c           	      J    [         R                  " SSS SR                  U S9S9$ )Nz--descriptionFzDescription of the {noun}.nounrequireddefaulthelp)r   Argumentformatr2   s    r!   GetDescriptionFlagr:   {   s-    	'..D.9	
; ;r    z--distributed
store_trueFzwRuns the provided code in distributed mode by providing cluster configurations as environment variables to subprocesses)actionr6   r7   --parameter-server-countzdNumber of parameter servers with which to run. Ignored if --distributed is not specified. Default: 2typer7   --worker-countzZNumber of workers with which to run. Ignored if --distributed is not specified. Default: 2z--evaluator-countz]Number of evaluators with which to run. Ignored if --distributed is not specified. Default: 0z--start-porti.j  zStart of the range of ports reserved by the local cluster. This command will use
a contiguous block of ports equal to parameter-server-count + worker-count + 1.

If --distributed is not specified, this flag is ignored.
)r?   r6   r7   	operationzName of the operation.r7   z--configa2  Path to the job configuration file. This file should be a YAML document (JSON
also accepted) containing a Job resource as defined in the API (all fields are
optional): https://cloud.google.com/ml/reference/rest/v1/projects.jobs

EXAMPLES:

JSON:

  {
    "jobId": "my_job",
    "labels": {
      "type": "prod",
      "owner": "alice"
    },
    "trainingInput": {
      "scaleTier": "BASIC",
      "packageUris": [
        "gs://my/package/path"
      ],
      "region": "us-east1"
    }
  }

YAML:

  jobId: my_job
  labels:
    type: prod
    owner: alice
  trainingInput:
    scaleTier: BASIC
    packageUris:
    - gs://my/package/path
    region: us-east1



If an option is specified both in the configuration file **and** via command line
arguments, the command line arguments override the configuration file.
jobzName of the job.z--package-pathaX  Path to a Python package to build. This should point to a *local* directory
containing the Python source for the job. It will be built using *setuptools*
(which must be installed) using its *parent* directory as context. If the parent
directory contains a `setup.py` file, the build will use that; otherwise,
it will use a simple built-in one.
z
--packagesPACKAGEzPath to Python archives used for training. These can be local paths
(absolute or relative), in which case they will be uploaded to the Cloud
Storage bucket given by `--staging-bucket`, or Cloud Storage URLs
('gs://bucket-name/path/to/package.tar.gz').
)r6   r?   metavarr7   a>  Google Cloud region of the regional endpoint to use for this command.
If unspecified, the command uses the global endpoint of the AI Platform Training
and Prediction API.

Learn more about regional endpoints and see a list of available regions:
 https://cloud.google.com/ai-platform/prediction/docs/regional-endpoints
a   Google Cloud region of the regional endpoint to use for this command.
For the global endpoint, the region needs to be specified as `global`.

Learn more about regional endpoints and see a list of available regions:
 https://cloud.google.com/ai-platform/prediction/docs/regional-endpoints
c                     U (       a(  [         R                  " S[        R                  [        S9$ [         R                  " S[        R
                  [        S9$ )zAAdds --region flag to determine endpoint for models and versions.z--region)choicesr7   )r   r8   r   SUPPORTED_REGIONS_WITH_GLOBAL!_REGION_FLAG_WITH_GLOBAL_HELPTEXTSUPPORTED_REGIONS_REGION_FLAG_HELPTEXT)include_globals    r!   GetRegionArgrM      sG    ==77.0 0 
)) 
" "r    z--service-accountz:Specifies the service account for resource access control.r5   r7   z	--networka  Full name of the Google Compute Engine
network (https://cloud.google.com/vpc/docs) to which the Job
is peered with. For example, ``projects/12345/global/networks/myVPC''. The
format is of the form projects/{project}/global/networks/{network}, where
{project} is a project number, as in '12345', and {network} is network name.
Private services access must already have been configured
(https://cloud.google.com/vpc/docs/configure-private-services-access)
for the network. If unspecified, the Job is not peered with any network.
ad        The email address of a service account to use when running the
      training appplication. You must have the `iam.serviceAccounts.actAs`
      permission for the specified service account. In addition, the AI Platform
      Training Google-managed service account must have the
      `roles/iam.serviceAccountAdmin` role for the specified service account.
      [Learn more about configuring a service
      account.](https://cloud.google.com/ai-platform/training/docs/custom-service-account)
      If not specified, the AI Platform Training Google-managed service account
      is used by default.
      r?   r5   r7   z--enable-web-accessa        Whether you want AI Platform Training to enable [interactive shell
      access]
      (https://cloud.google.com/ai-platform/training/docs/monitor-debug-interactive-shell)
      to training containers. If set to `true`, you can access interactive
      shells at the URIs given by TrainingOutput.web_access_uris or
      HyperparameterOutput.web_access_uris (within TrainingOutput.trials).
      )r<   r5   r6   r7   Tc                 .    [         R                  " SU SS9$ )Nz--module-namezName of the module to run.rN   r   r8   r5   s    r!   GetModuleNameFlagrS   7  s    	/K
M Mr    c                     SR                  SU(       a  SOS-   S9nU (       a  US-  nU(       a  [        nO-[        R                  " [        R
                  R                  SS9n[        R                  " S	X2S
9$ )a   Get base.Argument() for `--job-dir`.

If allow_local is provided, this Argument gives a str when parsed; otherwise,
it gives a (possibly empty) ObjectReference.

Args:
  upload_help: bool, whether to include help text related to object upload.
    Only useful in remote situations (`jobs submit training`).
  allow_local: bool, whether to allow local directories (only useful in local
    situations, like `local train`) or restrict input to directories in Cloud
    Storage.

Returns:
  base.Argument() for the corresponding `--job-dir` flag.
ap  {dir_type} in which to store training outputs and other data
needed for training.

This path will be passed to your TensorFlow program as the `--job-dir` command-line
arg. The benefit of specifying this field is that AI Platform will validate
the path for use in training. However, note that your training program will need
to parse the provided `--job-dir` argument.
zCloud Storage pathz or local_directory )dir_typezf
If packages must be uploaded and `--staging-bucket` is not provided, this path
will be used instead.
T)allow_empty_objectz	--job-dirr>   )	r9   str	functoolspartialr   ObjectReferenceFromArgumentr   r8   )upload_helpallow_localhelp_type_s       r!   GetJobDirFlagra   <  s}      F"(3$=  ?  	  E El::GG157E	{	;;r    c                 b    U (       a  SnOSn[         R                  " S[        R                  US9$ )NzAdditional user arguments to be forwarded to user code. Any relative paths will
be relative to the *parent* directory of `--package-path`.
z6Additional user arguments to be forwarded to user code	user_args)nargsr7   )r   r8   argparse	REMAINDER)local	help_texts     r!   GetUserArgsri   f  s4    
I
 II	
 r    versionzName of the model version.z--runtime-versionzAI Platform runtime version for this job. Must be specified unless --master-image-uri is specified instead. It is defined in documentation along with the list of supported versions: https://cloud.google.com/ai-platform/prediction/docs/runtime-version-listz--polling-interval   	unlimited<   zKNumber of seconds to wait between efforts to fetch the latest log messages.)r?   r5   r6   r<   r7   z--allow-multiline-logsz0Output multiline log messages as single records.)r<   r7   z--task-namez7If set, display only the logs for this particular task.r4   
tensorflowzscikit-learnxgboost)
TENSORFLOWSCIKIT_LEARNXGBOOSTz--frameworkz`ML framework used to train this version of the model. If not specified, defaults to 'tensorflow')custom_mappingshelp_strc                 R    SR                  SS5      n[        R                  " XUS9  g )Nz{} must hold permission {}z/The 'AI Platform Service Agent' service accountz)'Cloud KMS CryptoKey Encrypter/Decrypter')permission_info)r9   kms_resource_argsAddKmsKeyResourceArg)parserresourcerw   s      r!   AddKmsKeyFlagr|     s-    077713/ ((9r    c                 n    SR                  US9n[        R                  " SUS9nUR                  U 5        g )Na        Version of Python used {context}. Choices are 3.7, 3.5, and 2.7.
      However, this value must be compatible with the chosen runtime version
      for the job.

      Must be used with a compatible runtime version:

      * 3.7 is compatible with runtime versions 1.15 and later.
      * 3.5 is compatible with runtime versions 1.4 through 1.14.
      * 2.7 is compatible with runtime versions 1.15 and earlier.
      )contextz--python-versionrB   )r9   r   r8   AddToParser)rz   r~   ru   rj   s       r!   AddPythonVersionFlagr     s@    

 &&
!  MM' 
fr    c                 h    SnU (       a  [         R                  " SUS9$ [         R                  " SX!S9$ )NzName of the model.r&   rB   --model)r7   r5   rQ   )
positionalr5   rh   s      r!   GetModelNamer     s,    ")==y11==FFr    c                     U R                   bg  [        U R                   5      S:  a  [        R                  " S5        [	        [
        R                  R                  U R                   5      5      U l         gg)z?Flatten PACKAGES flag and warn if multiple arguments were used.Nrk   zoUse of --packages with space separated values is deprecated and will not work in the future. Use comma instead.)packageslenr   warninglist	itertoolschainfrom_iterable)argss    r!   ProcessPackagesr     sT    	]]
4==A	kk   66t}}EFDM r    z--staging-bucketz        Bucket in which to stage training archives.

        Required only if a file upload is necessary (that is, other flags
        include local paths) and no other flags implicitly specify an upload
        path.
        z--signature-namea"      Name of the signature defined in the SavedModel to use for
    this job. Defaults to DEFAULT_SERVING_SIGNATURE_DEF_KEY in
    https://www.tensorflow.org/api_docs/python/tf/compat/v1/saved_model/signature_constants,
    which is "serving_default". Only applies to TensorFlow models.
    r5   r?   r7   c                  0    [         R                  " SSSSS9$ )Nz--summarizer;   Fa        Summarize job output in a set of human readable tables instead of
      rendering the entire resource as json or yaml. The tables currently rendered
      are:

      * `Job Overview`: Overview of job including, jobId, status and create time.
      * `Training Input Summary`: Summary of input for a training job including
         region, main training python module and scale tier.
      * `Training Output Summary`: Summary of output for a training job including
         the amount of ML units consumed by the job.
      * `Training Output Trials`: Summary of hyperparameter trials run for a
         hyperparameter tuning training job.
      * `Predict Input Summary`: Summary of input for a prediction job including
         region, model verion and output path.
      * `Predict Output Summary`: Summary of output for a prediction job including
         prediction count and output path.

      This flag overrides the `--format` flag. If
      both are present on the command line, a warning is displayed.
      )r<   r5   r7   rQ   r   r    r!   GetSummarizeFlagr     s!    	
	
 r    c                  T    [         R                  [        [        R                  SS9S9$ )z0Get tabular format for standard ml training job.rU   	HP_OUTPUTINPUTOUTPUT)_JOB_SUMMARYr9   _JOB_TRAIN_INPUT_SUMMARY_FORMAT _JOB_TRAIN_OUTPUT_SUMMARY_FORMATr   r    r!   GetStandardTrainingJobSummaryr      s0    			+-44r4B 
 
D Dr    c                  \    [         R                  [        [        R                  [        S9S9$ )z4Get tablular format to HyperParameter tuning ml job.r   r   )r   r9   !_JOB_PREDICT_INPUT_SUMMARY_FORMATr   _JOB_TRAIN_OUTPUT_TRIALS_FORMATr   r    r!   GetHPTrainingJobSummaryr     s3    			--443 5 5 
 
6 6r    c                  :    [         R                  [        [        S9$ )z'Get table format for ml prediction job.r   )r   r9   r   "_JOB_PREDICT_OUTPUT_SUMMARY_FORMATr   r    r!   GetPredictJobSummaryr     s     			-/ 
 
1 1r    c                  ,    [         R                  " SSS9$ )Nr&   zModel for the {resource}.namerh   r    ResourceParameterAttributeConfigr   r    r!   ModelAttributeConfigr     s    		2	2+
- -r    c                  ,    [         R                  " SSS9$ )Nrj   zVersion for the {resource}.r   r   r   r    r!   VersionAttributeConfigr     s    		2	2-
/ /r    c                  n    [         R                  " SS[        5       [        5       [         R                  S9$ )Nzml.projects.models.versionsrj   )resource_name
versionsIdmodelsId
projectsId)r   ResourceSpecr   r    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr   r    r!   GetVersionResourceSpecr   "  s0    			#')#%::
< <r    c                     [         R                  R                  S[        5       SR	                  U5      SS9R                  U 5        g)z3Add a resource argument for an AI Platform version.rj   The AI Platform model {}.TrR   N)r   ConceptParserForResourcer   r9   r   )rz   verbs     r!   AddVersionResourceArgr   +  sA    ++!((.	 ,  ![(r    c                 L    [         R                  " SU [         R                  SS9$ )Nzml.projects.modelsTr   r   disable_auto_completersr   r   r   )r   s    r!   GetModelResourceSpecr   4  s'    			!::"	
$ $r    c                     U (       a  SnOSn[         R                  R                  U[        5       SR	                  U5      US9$ )at  Add a resource argument for AI Platform model.

NOTE: Must be used only if it's the only resource arg in the command.

Args:
  positional: bool, if True, means that the model is a positional rather
  required: bool, if True means that argument is required.
  verb: str, the verb to describe the resource, such as 'to update'.

Returns:
  An argparse.ArgumentParse object.
r&   r   r   rR   )r   r   r   r   r9   )r   r5   r   r   s       r!   GetModelResourceArgr   <  sI     DD		&	&	2	2
!((.	 
3 
 r    c                  L    [         R                  " SS[         R                  SS9$ )Nzml.projects.locationslocationTr   r   r   r    r!   GetLocationResourceSpecr   T  s'    			::"	
$ $r    c                  R    [         R                  R                  S[        5       SSS9$ )z`Add a resource argument for AI Platform location.

Returns:
  An argparse.ArgumentParse object.
r   z*The location you want to show details for.TrR   )r   r   r   r   r   r    r!   GetLocationResourceArgr   \  s1     
	&	&	2	22	 
3 
 r    c           	         [         R                  " SS9nUR                  [         R                  " SSS95        UR                  [         R                  " S[        R
                  " 5       SSS95        UR                  U 5        g	)
z-Add args that configure user prediction code.z          Configure user code in prediction.

          AI Platform allows a model to have user-provided prediction
          code; these options configure that code.
          rB   z--prediction-classz          Fully-qualified name of the custom prediction class in the package
          provided for custom prediction.

          For example, `--prediction-class=my_package.SequenceModel`.
          z--package-urisPACKAGE_URIz          Comma-separated list of Cloud Storage URIs ('gs://...') for
          user-supplied Python packages to use.
          )r?   rE   r7   N)r   ArgumentGroupAddArgumentr8   r
   ArgListr   )rz   user_code_groups     r!   AddUserCodeArgsr   i  s|    && - / dmm  dmm 	  f%r    c                     [         R                  " S[        R                  " [        [
        S.S/S9SR                  SR                  [        R                   V s/ s H  n SR                  U 5      PM     sn 5      5      S9$ s  sn f )	Nz--acceleratorr?   countr?   specrequired_keysa  Manage the accelerator config for GPU serving. When deploying a model with
Compute Engine Machine Types, a GPU accelerator may also
be selected.

*type*::: The type of the accelerator. Choices are {}.

*count*::: The number of accelerators to attach to each machine running the job.
 If not specified, the default value is 1. Your model must be specially designed
to accommodate more than 1 accelerator per machine. To configure how many
replicas your model has, set the `manualScaling` or `autoScaling`
parameters., '{}'r>   )
r   r8   r
   ArgDictrX   intr9   join_OP_ACCELERATOR_TYPE_MAPPERrG   )cs    r!   GetAcceleratorFlagr     s    	 #8	%
 vdii:BBCB!V]]1BCE F%
G G& Ds   Bc                    [         R                   Vs/ s H  oPM     nnU c  gU R                  SS5      nX2;  aI  [        SR	                  SR                  U Vs/ s H  nSR	                  U5      PM     sn5      5      5      eU R                  SS5      nUS::  a  [        S	5      e[        R                  " 5       R                  n[        R                  " X5R                  5      nU" UUS
9$ s  snf s  snf )z:Validates and returns a accelerator config message object.Nr?   zBThe type of the accelerator can only be one of the following: {}.
r   r   r   rk   r   z5The count of the accelerator must be greater than 0.
)r   r?   )_ACCELERATOR_TYPE_MAPPERrG   getr   r9   r   r   GetMessagesModule GoogleCloudMlV1AcceleratorConfigr   ChoiceToEnumTypeValueValuesEnum)acceleratorr   typesraw_typeaccelerator_countaccelerator_msgaccelerator_types          r!   ParseAcceleratorFlagr     s    .66
7616%
7__VT*(
 
F49961fmmA&678: : "oogq1!
    "33555 ++335	
 # 8 7s   C-C2c           	      x   [         R                  " S/ SQSSS9R                  U 5        [         R                  " S[        R
                  " S[        R                  SS	9S
SSS9R                  U 5        [         R                  " S[        R
                  " S[        R                  SS	9S
SSS9R                  U 5        g)z'Add args that configure explainability.z--explanation-method)zintegrated-gradientszsampled-shapleyxraiFz          Enable explanations and select the explanation method to use.

          The valid options are:
            integrated-gradients: Use Integrated Gradients.
            sampled-shapley: Use Sampled Shapley.
            xrai: Use XRAI.
      )rG   r5   ru   z--num-integral-stepsrk   Trl   2   z          Number of integral steps for Integrated Gradients. Only valid when
          `--explanation-method=integrated-gradients` or
          `--explanation-method=xrai` is specified.
      )r?   r6   r5   r7   z--num-pathsz          Number of paths for Sampled Shapley. Only valid when
          `--explanation-method=sampled-shapley` is specified.
      N)r   ChoiceArgumentr   r8   r
   
BoundedIntsysmaxsizerz   s    r!   AddExplainabilityFlagsr     s    A
	 K--!!!S[[DA

 K--!!!S[[DA
	 Kr    c                 :   [        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        [	        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        [        5       R                  U 5        U(       a  [        5       R                  U 5        gg)z%Add Custom container flags to parser.N)GetMasterMachineTyper   GetMasterAcceleratorGetMasterImageUri#GetParameterServerMachineTypeConfigGetParameterServerAcceleratorGetParameterServerImageUriGetWorkerMachineConfigGetWorkerAcceleratorGetWorkerImageUriGetUseChiefInTfConfigGetTpuTfVersion)rz   support_tpu_tf_versions     r!   AddCustomContainerFlagsr     s    $$V,$$V,!!&)%'33F;!--f5**62&&v.$$V,!!&)%%f-!!&) r    zgeneric-acceleratorz Available types of accelerators.c                     U S:g  $ )NACCELERATOR_TYPE_UNSPECIFIEDr   xs    r!   <lambda>r    s
    Q"@@r    )ru   include_filterr5   c                 $    U R                  S5      $ )NNVIDIA)
startswithr  s    r!   r  r    s    Q\\(3r    zautoscaling-metric-namezThe available metric names.c                     U S:g  $ )NMETRIC_NAME_UNSPECIFIEDr   r  s    r!   r  r    s
    Q";;r    z   Hardware accelerator config for the {worker_type}. Must specify
   both the accelerator type (TYPE) for each server and the number of
   accelerators to attach to each server (COUNT).
  c                 h    [         R                  " U [        R                  S[        R                  S9$ )Nr   )	item_typevalid_choices)r   r   r   enumrG   )
choice_strs    r!   "_ConvertAcceleratorTypeToEnumValuer    s.    			
,D,I,I*7.F.N.N
P Pr    c                 T    [        U 5      nUS::  a  [        R                  " S5      eU$ )Nr   z4The count of the accelerator must be greater than 0.)r   r
   ArgumentTypeError)r   r   s     r!   _ValidateAcceleratorCountr    s1    

 %
aZ

'
'>@ @	,r    c                     [        [        R                  5      nX;  aI  [        SR	                  SR                  U Vs/ s H  nSR	                  U5      PM     sn5      5      5      eU $ s  snf )z(Value validation for Metric target name.zBThe autoscaling metric name can only be one of the following: {}.
r   r   )r   "_OP_AUTOSCALING_METRIC_NAME_MAPPERrG   r   r9   r   )keynamesr   s      r!   _ValidateMetricTargetKeyr    sb    
199
:%
 
F49961fmmA&678: : 
* 7s   A*c                      [        U 5      nUS:  d  US:  a  [        SU -  5      eU$ ! [        [        4 a    [        SU -  5      ef = f)z)Value validation for Metric target value.z4Metric target percentage value %s is not an integer.r   d   z0Metric target value %s is not between 0 and 100.)r   	TypeError
ValueErrorr   )valueresults     r!   _ValidateMetricTargetValuer     si    ZF
 aZ6C<
:UBD D	- Z	  
N  s	   ) Ac                     SR                  SR                  [        R                  5      5      nSn[        R
                  " U U[        R                  " [        [        S.SS/S9SR                  XUS	9S
9nU$ )z=Creates an ArgDict representing an AcceleratorConfig message.z1*type*::: Type of the accelerator. Choices are {},zd*count*::: Number of accelerators to attach to each machine running the job. Must be greater than 0.r   r?   r   r   z'{arg_help}

{type_help}

{count_help}

)arg_help	type_help
count_helpr   )
r9   r   r   rG   r   r8   r
   r   r  r  )arg_namer!  r5   r"  r#  args         r!   _MakeAcceleratorArgConfigArgr&  .  s    AHH	hh'//02)C*4,% (* FHjFI	K# 
*r    c                  2    Sn [         R                  " SSU S9$ )zBuild master-machine-type flag.z  Specifies the type of virtual machine to use for training job's master worker.

  You must set this value when `--scale-tier` is set to `CUSTOM`.
  z--master-machine-typeFrN   rQ   rh   s    r!   r   r   F  s#    )
 
I
? ?r    c                  <    [         R                  SS9n [        SU S9$ )zBuild master-accelerator flag.zmaster workerworker_typez--master-acceleratorr!  _ACCELERATOR_TYPE_HELPr9   r&  r(  s    r!   r   r   Q  s'    $+++H)	%y
2 2r    c                  .    [         R                  " SSSS9$ )zBuild master-image-uri flag.z--master-image-uriFzDocker image to run on each master worker. This image must be in Container Registry. Only one of `--master-image-uri` and `--runtime-version` must be specified.rN   rQ   r   r    r!   r   r   X  s!    	N
P Pr    c            	         [         R                  " SSSS9n [         R                  " S[        R                  " S[        R
                  SS9SSS	9n[         R                  " S
SS9nUR                  U 5        UR                  U5        U$ )z1Build parameter-server machine type config group.z--parameter-server-machine-typeTzType of virtual machine to use for training job's parameter servers. This flag must be specified if any of the other arguments in this group are specified machine to use for training job's parameter servers.rN   r=   rk   rl   z8Number of parameter servers to use for the training job.rO   Fz1Configure parameter server machine type settings.r   r8   r
   r   r   r   r   r   machine_typemachine_countmachine_type_groups      r!   r   r   b  s    '13, -- !!!S[[DAF	I- ))>@   .  /	r    c                  <    [         R                  SS9n [        SU S9$ )z(Build parameter-server-accelerator flag.zparameter serversr*  z--parameter-server-acceleratorr,  r-  r(  s    r!   r   r   z  s(    $++8K+L)	%&
< <r    c                  .    [         R                  " SSSS9$ )z&Build parameter-server-image-uri flag.z--parameter-server-image-uriFzDocker image to run on each parameter server. This image must be in Container Registry. If not specified, the value of `--master-image-uri` is used.rN   rQ   r   r    r!   r   r     s!    	$D
F Fr    c            	         [         R                  " SSSS9n [         R                  " S[        R                  " S[        R
                  SS9SSS	9n[         R                  " S
SS9nUR                  U 5        UR                  U5        U$ )z'Build worker machine type config group.z--worker-machine-typeTz?Type of virtual machine to use for training job's worker nodes.rN   r@   rk   rl   z3Number of worker nodes to use for the training job.rO   Fz,Configure worker node machine type settings.r1  r2  s      r!   r   r     s    #%, --!!!S[[DA@	B- ))9;   .  /	r    c                  <    [         R                  SS9n [        SU S9$ )zBuild worker-accelerator flag.zworker nodesr*  z--worker-acceleratorr,  r-  r(  s    r!   r   r     s'    $+++G)	%y
2 2r    c                  .    [         R                  " SSSS9$ )zBuild worker-image-uri flag.z--worker-image-uriFzDocker image to run on each worker node. This image must be in Container Registry. If not specified, the value of `--master-image-uri` is used.rN   rQ   r   r    r!   r   r     s!    	D
F Fr    c                  .    [         R                  " SSSS9$ )zBuild tpu-tf-version flag.z--tpu-tf-versionFzRuntime version of TensorFlow used by the container. This field must be specified if a custom container on the TPU worker is being used.rN   rQ   r   r    r!   r   r     s    	
 r    c                  V    [         R                  " SS[        R                  " 5       SS9$ )z"Build use-chief-in-tf-config flag.z--use-chief-in-tf-configFzUse "chief" role in the cluster instead of "master". This is required for TensorFlow 2.0 and newer versions. Unlike "master" node, "chief" node does not run evaluation.r   )r   r8   r
   
ArgBooleanr   r    r!   r   r     s*    	 !!#:	
< <r    c                 L    [         R                  " SSS9R                  U 5        g )Nz--machine-typezType of machine on which to serve the model. Currently only applies to online prediction. For available machine types,
see https://cloud.google.com/ai-platform/prediction/docs/machine-types-online-prediction#available_machine_types.
rB   )r   r8   r   r   s    r!   AddMachineTypeFlagToParserr?    s"    --
 [r    c           
      h   U R                  SS9nUR                  SSS9  UR                  S[        R                  " 5       S[        R                  SS9  UR                  S	S
[        R                  " 5       [        R                  SS9  UR                  SS[        R
                  " 5       [        R                  SS9  UR                  SS
[        R                  " [        R                  " SS5      S9[        R                  SS9  U R                  SS9nUR                  SSS9  UR                  SSS9  g)z@Adds flags related to custom containers to the specified parser.z'Configure the container to be deployed.rB   z--imagezMName of the container image to deploy (e.g. gcr.io/myproject/server:latest).
z	--commandCOMMANDzgEntrypoint for the container image. If not specified, the container
image's default Entrypoint is run.
)r?   rE   r<   r7   z--argsARGzComma-separated arguments passed to the command run by the container
image. If not specified and no '--command' is provided, the container
image's default Cmd is used.
)rE   r?   r<   r7   z
--env-varsz	KEY=VALUEz8List of key-value pairs to set as environment variables.z--portsrk   i  )element_typezYContainer ports to receive requests at. Must be a number between 1 and 65535,
inclusive.
zGFlags to control the paths that requests and health checks are sent to.z--predict-routez>HTTP path to send prediction requests to inside the container.z--health-routez8HTTP path to send health checks to inside the container.N)add_argument_groupadd_argumentr
   r   UpdateActionr   r   )rz   container_grouproute_groups      r!   AddContainerFlagsrI    sh   --4 . 6/  
  %%    %%  	  %%E   K,B,B1e,LM%%   )) * + K   E  r    c           	          U R                  SS9nUR                  S[        SS9  UR                  S[        SS9  UR                  SS	[        R                  " [
        [        S
9[        R                  0 SS9  g)z:Adds flags related to autoscaling to the specified parser.z2Configure the autoscaling settings to be deployed.rB   z--min-nodesz<The minimum number of nodes to scale this model under load.
r>   z--max-nodesz<The maximum number of nodes to scale this model under load.
z--metric-targetszMETRIC-NAME=TARGET)key_type
value_typezList of key-value pairs to set as metrics' target for autoscaling.
Autoscaling could be based on CPU usage or GPU duty cycle, valid key could be
cpu-usage or gpu-duty-cycle.
)rE   r?   r<   r6   r7   N)rD  rE  r   r
   r   r  r  rF  )rz   autoscaling_groups     r!   AddAutoScalingFlagsrN  
  s    //? 0 A   !     !    "+8RT%% ! r    c                 v    U R                  SS9nUR                  S[        SS9  UR                  S[        SS9  g)	z/Adds flags related to request response logging.z#Configure request response logging.rB   z--bigquery-table-namezyFully qualified name (project_id.dataset_name.table_name) of the BigQuery
table where requests and responses are logged.
r>   z--sampling-percentagezPercentage of requests to be logged, expressed as a number between 0 and 1.
For example, set this value to 1 in order to log all requests or to 0.1 to log
10% of requests.
N)rD  rE  rX   float)rz   groups     r!   AddRequestLoggingConfigFlagsrR  (  sX    

#
#0 $ 2%     r    )F)T)TF)r&   )TFrU   )__doc__
__future__r   r   r   re   rY   r   r   textwrap googlecloudsdk.api_lib.ml_enginer   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper	   r
   r    googlecloudsdk.calliope.conceptsr   googlecloudsdk.command_lib.iamr   iam_completersr   core_iam_utilgooglecloudsdk.command_lib.kmsr   rx   $googlecloudsdk.command_lib.ml_enginer   r   $googlecloudsdk.command_lib.util.apisr   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   r   r   r   r   r   r   r   Errorr   IamRolesCompleterr#   r:   r8   DISTRIBUTEDr   PARAM_SERVERSWORKERS
EVALUATORS
START_PORTOPERATION_NAMECONFIGJOB_NAMEPACKAGE_PATHr   PACKAGESrK   rI   rM   SERVICE_ACCOUNTNETWORKGetIamAccountFormatValidatordedentTRAINING_SERVICE_ACCOUNTENABLE_WEB_ACCESSrS   ra   ri   VERSION_NAMERUNTIME_VERSIONr   r   StorePropertyVALUES	ml_enginepolling_intervalPOLLING_INTERVALALLOW_MULTILINE_LOGS	TASK_NAME_FRAMEWORK_CHOICESChoiceEnumMapperr   GoogleCloudMlV1VersionFrameworkValueValuesEnumFRAMEWORK_MAPPERr|   r   r   r   BucketReferencer\   STAGING_BUCKETrX   SIGNATURE_NAMEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   GoogleCloudMlV1MetricSpecNameValueValuesEnumr  r.  r  r  r  r  r&  r   r   r   r   r   r   r   r   r   r   r   r?  rI  rN  rR  r   r    r!   <module>r     sF   E &  '    
  1 9 7 + / ( 5 G D M : < : D * # *	# $  # % !& "J$$  @ @ ; mmD	F 	BD
 --	BD
 ]]	BD

 ]]	
		
 {1IJ 
'
)
T ==%78}}
 ==				

 % !
" --	EG
 --	
  ==		3	3	5	 

 

	   MM	 
 
 M
'<T }}Y-IJ--	T ==			3;;$	?  !2!2!<!<!M!MN
  }}	;=  MM	B	D	 " 
 --##%44&=? 9$GG 		%	%	2	2
	 	
			6D61-/<)$0$
&6G.0#L*  %55 &&':':/@  (88==/3  &/%?%?""$>>*;& " P0?2P0<F.2F<6r<r    