
                            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dl
mZ dd	l
mZ dd
lmZ d Zd Z e	j"                  e	j$                  j&                  e	j$                  j(                         G d de	j*                               Z e	j"                  e	j$                  j.                         G d de	j*                               Zy)z1ai-platform jobs submit batch prediction command.    )absolute_import)division)unicode_literals)jobs)arg_parsers)base)flags)	jobs_util)labels_utilc           
      &   t        j                  d      }|j                  t        j                  dddt	        j
                  d      d             |j                  t        j                         j                         |j                  |        y	)
z%Add arguments for accelerator config.zAccelerator Configuration.helpz--accelerator-countT   )lower_boundzCThe number of accelerators to attach to the machines. Must be >= 1.)requireddefaulttyper   N)
r   ArgumentGroupAddArgumentArgumentr   
BoundedIntr
   AcceleratorFlagMap
choice_argAddToParser)parseraccelerator_config_groups     1lib/surface/ai_platform/jobs/submit/prediction.py_AddAcceleratorFlagsr      s}    !//') &&t}}!!a0(   &&""$//1&&v.    c                    | j                  dd       | j                  d      }|j                  dd       |j                  dd	       | j                  d
d       | j                  dt        j                  d      ddd       t	        j
                         j                  j                  |        | j                  ddd       | j                  ddd       | j                  ddt        d       | j                  ddt        d       t        j                  j                  |        t        j                  j                  |        t        j                  |        y)z3Add arguments for `jobs submit prediction` command.jobz!Name of the batch prediction job.r   T)r   z--model-dirz9Cloud Storage location where the model files are located.z--modelz(Name of the model to use for prediction.z	--versionzModel version to be used.

This flag may only be given if --model is specified. If unspecified, the default
version of the model will be used. To list versions for a model, run

    $ gcloud ai-platform versions list
z--input-pathsr   )
min_length
INPUT_PATHa)  Cloud Storage paths to the instances to run prediction on.

Wildcards (```*```) accepted at the *end* of a path. More than one path can be
specified if multiple file patterns are needed. For example,

  gs://my-bucket/instances*,gs://my-bucket/other-instances1

will match any objects whose names start with `instances` in `my-bucket` as well
as the `other-instances1` bucket, while

  gs://my-bucket/instance-dir/*

will match any objects in the `instance-dir` "directory" (since directories
aren't a first-class Cloud Storage concept) of `my-bucket`.
)r   r   metavarr   z--output-pathzOCloud Storage path to which to save the output. Example: gs://my-bucket/output.)r   r   z--regionz,The Compute Engine region to run the job in.z--max-worker-countFzbThe maximum number of workers to be used for parallel processing. Defaults to 10 if not specified.)r   r   r   z--batch-sizezThe number of records per batch. The service will buffer batch_size number of records in memory before invoking TensorFlow. Defaults to 64 if not specified.N)add_argumentadd_mutually_exclusive_groupr   ArgListr
   DataFormatFlagMapr   r   intr	   SIGNATURE_NAMERUNTIME_VERSIONr   AddCreateLabelsFlags)r   model_groups     r   _AddSubmitPredictionArgsr.   .   s   e"EF33T3B++  - @  B  	 	!,  * **66v>(  ) 	9  ; 	/	  1 	0	  2 ""6*##F+""6*r   c                   &    e Zd ZdZed        Zd Zy)
Prediction*Start an AI Platform batch prediction job.c                 l    t        |        | j                  j                  t        j                         y N)r.   display_info	AddFormatr
   
JOB_FORMATr   s    r   ArgszPrediction.Argsy   s$    V$
!!)"6"67r   c                    t        j                         j                  |j                        }t	        j
                         }t        j                  ||      }t        j                  ||j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  |      S )N)	model_dirmodelversioninput_pathsdata_formatoutput_pathregionruntime_versionmax_worker_count
batch_sizesignature_namelabels)r
   r(   GetEnumForChoicer>   r   
JobsClientParseCreateLabelsSubmitPredictionr!   r:   r;   r<   r=   namer?   r@   rA   rB   rC   rD   selfargsr>   jobs_clientrE   s        r   RunzPrediction.Run~   s    --/@@K//#K((d;F%%TXX..jj$$$$$${{,,..??** r   N__name__
__module____qualname____doc__staticmethodr8   rO    r   r   r0   r0   t   s     38 8r   r0   c                   &    e Zd ZdZed        Zd Zy)PredictionAlphar1   c                     t        |        t        |        | j                  j                  t        j
                         y r3   )r.   r   r4   r5   r
   r6   r7   s    r   r8   zPredictionAlpha.Args   s,    V$ 
!!)"6"67r   c                    t        j                         j                  |j                        }t	        j
                         }t        j                  ||      }t        j                  ||j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  ||j(                  |j*                        S )N)r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   accelerator_typeaccelerator_count)r
   r(   rF   r>   r   rG   rH   rI   r!   r:   r;   r<   r=   rJ   r?   r@   rA   rB   rC   rD   r[   r\   rK   s        r   rO   zPredictionAlpha.Run   s    --/@@K//#K((d;F%%TXX..jj$$$$$${{,,..??**..002 2r   NrP   rV   r   r   rX   rX      s    28 8
2r   rX   N)rT   
__future__r   r   r    googlecloudsdk.api_lib.ml_enginer   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.ml_enginer	   r
   $googlecloudsdk.command_lib.util.argsr   r   r.   ReleaseTracksReleaseTrackGABETACommandr0   ALPHArX   rV   r   r   <module>rh      s    8 &  ' 1 / ( 6 : </"C+L D%%((%%**, ,< D%%++,2dll 2 -2r   