
    J                        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SKJr  SS	KJr  SS
KJr  S rS r\R&                  " \R(                  R*                  5       " S S\R,                  5      5       r\R&                  " \R(                  R0                  \R(                  R2                  5       " S S\5      5       rSS0r\\l        g)z)ai-platform jobs submit training command.    )absolute_import)division)unicode_literals)jobs)base)
exceptions)flags)	jobs_util)labels_utilc                    [         R                  R                  U 5        [         R                  R                  U 5        [         R                  R                  U 5        [         R
                  " SS9R                  U 5        [        R                  " U SS5        [         R                  R                  U 5        [         R                  R                  U 5        [         R                  " SS9R                  U 5        [         R                  " SS9R                  U 5        [        R                  " 5       R                  R                  U 5        [         R                  R                  U 5        [         R                   " U S5        [         R"                  R                  U 5        [         R$                  R                  U 5        U R'                  5       nUR)                  S	S
SSS9  UR)                  SS
SS9  [*        R,                  " U 5        g)z1Add arguments for `jobs submit training` command.F)requiredzmachine learning training jobsubmitT)upload_help)localzduring trainingz--async
store_trueasync_z(DEPRECATED) Display information about the operation in progress without waiting for the operation to complete. Enabled by default and can be omitted; use `--stream-logs` to run synchronously.)actiondesthelpz--stream-logszBlock until job completion and stream the logs while the job runs.

Note that even if command execution is halted, the job will still run until cancelled with

    $ gcloud ai-platform jobs cancel JOB_ID)r   r   N)r	   JOB_NAMEAddToParserPACKAGE_PATHPACKAGESGetModuleNameFlagcompute_flagsAddRegionFlagCONFIGSTAGING_BUCKETGetJobDirFlagGetUserArgsr
   ScaleTierFlagMap
choice_argRUNTIME_VERSIONAddPythonVersionFlagTRAINING_SERVICE_ACCOUNTENABLE_WEB_ACCESSadd_mutually_exclusive_groupadd_argumentr   AddCreateLabelsFlags)parser
sync_groups     /lib/surface/ai_platform/jobs/submit/training.py_AddSubmitTrainingArgsr-      s   ..V$  (..V$5)55f=f&E&(,,6"""6*$'33F;% ,,V4))55f=##F+V%67  ,,V4%%f-224* 8   :  < ""6*    c                 4   [        U R                  S5      (       a}  U R                  R                  R                  5       nU(       a  UR	                  5       $ S H;  n[        XR                  SS5      S5      (       d  M&  [        R                  " SS5      e   gg)zFParse CMEK resource arg, and check if the arg was partially specified.kms_key)zkms-keyzkms-keyringzkms-locationzkms-project-_Nz	--kms-keyz#Encryption key not fully specified.)	hasattrCONCEPTSr0   ParseRelativeNamegetattrreplacer   InvalidArgumentException)argskms_refkeywords      r,   _GetAndValidateKmsKeyr=   D   s    T]]I&&mm##))+G!!##N'4c2D9933@B B O 'r.   c                   2    \ rS rSrSrSr\S 5       rS rSr	g)TrainQ   #Submit an AI Platform training job.Fc                     [        U5        [        R                  " XR                  S9  [        R                  " US5        UR
                  R                  [        R                  5        g )Nsupport_tpu_tf_versionjob)	r-   r	   AddCustomContainerFlags_SUPPORT_TPU_TF_VERSIONAddKmsKeyFlagdisplay_info	AddFormatr
   
JOB_FORMATclsr*   s     r,   Args
Train.ArgsW   sL    6"	!!'B'BD	&
!!)"6"67r.   c           	         [         R                  " UR                  UR                  5      n[         R                  " 5       R                  UR                  5      nU(       a  UR                  OS n[        R                  " 5       n[         R                  " XQ5      n[         R                  R                  XR                  5      nUR                  5         [         R                  " UUR                   40 SUR"                  _SUR$                  _SUR&                  _SUR(                  _SU_SUR*                  _SUR,                  _SUR.                  _S	UR0                  _S
[3        US
5      (       a  UR4                  OS _SUR6                  _SU_SU_SUR8                  _S[;        U5      _SU_SUR<                  _6nU(       a*  UR>                  UR@                  RB                  La  SU l"        U$ )Njob_dirstaging_bucketpackagespackage_path
scale_tierconfigmodule_nameruntime_versionpython_versionnetworkservice_accountlabelsstream_logs	user_argsr0   custom_train_server_configenable_web_access   )#r
   GetStreamLogsr   r]   r!   GetEnumForChoicerU   namer   
JobsClientParseCreateLabelsTrainingCustomInputServerConfigFromArgsrG   ValidateConfigSubmitTrainingrE   rQ   rR   rS   rT   rV   rW   rX   rY   r3   rZ   r[   r^   r=   r`   stateStateValueValuesEnum	SUCCEEDED	exit_code)	selfr:   r]   rU   scale_tier_namejobs_clientr\   custom_container_configrE   s	            r,   Run	Train.Run_   s   ))$++t7G7GHK++->>tOJ)3jooO//#K((;F11::..	0  **,

"
"2 2 **	2
 2 &&2 #2 {{2 $$2 ,,2 **2 !(i 8 8d2 ,,2 2  2  ..!2" &d+#2$ $;%2& 00'2C* syy(@(@(J(JJdnJr.   )rn   N)
__name__
__module____qualname____firstlineno____doc__rG   classmethodrN   rs   __static_attributes__ r.   r,   r?   r?   Q   s"    +!8 8!r.   r?   c                   ,    \ rS rSrSrSr\S 5       rSrg)TrainAlphaBeta   rA   Tc                    [        U5        [        R                  " US5        [        R                  R	                  U5        [        R
                  " XR                  S9  UR                  R                  [        R                  5        g )NrE   rC   )r-   r	   rH   NETWORKr   rF   rG   rI   rJ   r
   rK   rL   s     r,   rN   TrainAlphaBeta.Args   s^    6"	&	MMf%	!!'B'BD
!!)"6"67r.   r|   N)	ru   rv   rw   rx   ry   rG   rz   rN   r{   r|   r.   r,   r~   r~      s    + 8 8r.   r~   DESCRIPTIONaD  Submit an AI Platform training job.

This creates temporary files and executes Python code staged
by a user on Cloud Storage. Model code can either be
specified with a path, e.g.:

    $ {command} my_job \
            --module-name trainer.task \
            --staging-bucket gs://my-bucket \
            --package-path /my/code/path/trainer \
            --packages additional-dep1.tar.gz,dep2.whl

Or by specifying an already built package:

    $ {command} my_job \
            --module-name trainer.task \
            --staging-bucket gs://my-bucket \
            --packages trainer-0.0.1.tar.gz,additional-dep1.tar.gz,dep2.whl

If `--package-path=/my/code/path/trainer` is specified and there is a
`setup.py` file at `/my/code/path/setup.py`, the setup file will be invoked
with `sdist` and the generated tar files will be uploaded to Cloud Storage.
Otherwise, a temporary `setup.py` file will be generated for the build.

By default, this command runs asynchronously; it exits once the job is
successfully submitted.

To follow the progress of your job, pass the `--stream-logs` flag (note that
even with the `--stream-logs` flag, the job will continue to run after this
command exits and must be cancelled with `gcloud ai-platform jobs cancel JOB_ID`).

For more information, see:
https://cloud.google.com/ai-platform/training/docs/overview
N)ry   
__future__r   r   r    googlecloudsdk.api_lib.ml_enginer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r   $googlecloudsdk.command_lib.ml_enginer
   $googlecloudsdk.command_lib.util.argsr   r-   r=   ReleaseTracksReleaseTrackGACommandr?   ALPHABETAr~   _DETAILED_HELPdetailed_helpr|   r.   r,   <module>r      s    0 &  ' 1 ( . E 6 : <#+L
B D%%(().DLL . *.b D%%++T->->-C-CD8U 8 E8  !	$L % r.   