
    C                     *   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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  \	R.                  " SSSS9r\	R.                  " SS\R2                  " 5       SS9r\	R.                  " S\R6                  " S5      S9r\	R.                  " SS\R:                  " \\\\\\\\\\\R2                  " SS9\R2                  " SS9\R2                  " SS9S.S9S \R6                  " S!5      S"9r \	R.                  " S#\R2                  " 5       S$\RB                  S%S&9r"\	R.                  " S'S(\R2                  " 5       \RB                  S)S*9r#\	R.                  " S+S,S-S.9r$S/ r%\RL                  4S0 jr'S1 r(g)2z8Flags definition specifically for gcloud ai custom-jobs.    )absolute_import)division)unicode_literalsN)arg_parsers)base)concepts)	constants)flags)region_util)custom_jobs_util)labels_util)concept_parsersz--display-nameTz)Display name of the custom job to create.)requiredhelpz--python-package-urisPYTHON_PACKAGE_URISzThe common Python package URIs to be used for training with a pre-built container image. e.g. `--python-package-uri=path1,path2` If you are using multiple worker pools and want to specify a different Python packag fo reach pool, use `--config` instead.metavartyper   z--configa        Path to the job configuration file. This file should be a YAML document
      containing a [`CustomJobSpec`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/CustomJobSpec).
      If an option is specified both in the configuration file **and** via command-line arguments, the command-line arguments
      override the configuration file. Note that keys with underscore are invalid.

      Example(YAML):

        workerPoolSpecs:
          machineSpec:
            machineType: n1-highmem-2
          replicaCount: 1
          containerSpec:
            imageUri: gcr.io/ucaip-test/ucaip-training-test
            args:
            - port=8500
            command:
            - start)r   z--worker-pool-specappend;)custom_delim_char)zreplica-countzmachine-typezaccelerator-typezaccelerator-countzcontainer-image-urizexecutor-image-urizoutput-image-urizpython-modulescriptzlocal-package-pathrequirementsz
extra-dirszextra-packages)specWORKER_POOL_SPECa        Define the worker pool configuration used by the custom job. You can
      specify multiple worker pool specs in order to create a custom job with
      multiple worker pools.

      The spec can contain the following fields:

      *machine-type*::: (Required): The type of the machine.
        see https://cloud.google.com/vertex-ai/docs/training/configure-compute#machine-types
        for supported types. This is corresponding to the `machineSpec.machineType`
        field in `WorkerPoolSpec` API message.
      *replica-count*::: The number of worker replicas to use for this worker
        pool, by default the value is 1. This is corresponding to the `replicaCount`
        field in `WorkerPoolSpec` API message.
      *accelerator-type*::: The type of GPUs.
        see https://cloud.google.com/vertex-ai/docs/training/configure-compute#specifying_gpus
        for more requirements. This is corresponding to the `machineSpec.acceleratorType`
        field in `WorkerPoolSpec` API message.
      *accelerator-count*::: The number of GPUs for each VM in the worker pool to
        use, by default the value if 1. This is corresponding to the
        `machineSpec.acceleratorCount` field in `WorkerPoolSpec` API message.
      *container-image-uri*::: The URI of a container image to be directly run on
        each worker replica. This is corresponding to the
        `containerSpec.imageUri` field in `WorkerPoolSpec` API message.
      *executor-image-uri*::: The URI of a container image that will run the
        provided package.
      *output-image-uri*::: The URI of a custom container image to be built for
      autopackaged custom jobs.
      *python-module*::: The Python module name to run within the provided
        package.
      *local-package-path*::: The local path of a folder that contains training
        code.
      *script*::: The relative path under the `local-package-path` to a file to
        execute. It can be a Python file or an arbitrary bash script.
      *requirements*::: Python dependencies to be installed from PyPI, separated
        by ";". This is supposed to be used when some public packages are
        required by your training application but not in the base images.
        It has the same effect as editing a "requirements.txt" file under
        `local-package-path`.
      *extra-packages*::: Relative paths of local Python archives to be installed,
        separated by ";". This is supposed to be used when some custom packages
        are required by your training application but not in the base images.
        Every path should be relative to the `local-package-path`.
      *extra-dirs*::: Relative paths of the folders under `local-package-path`
       to be copied into the container, separated by ";". If not specified, only
       the parent directory that contains the main executable (`script` or
       `python-module`) will be copied.


      ::::
      Note that some of these fields are used for different job creation methods
      and are categorized as mutually exclusive groups listed below. Exactly one of
      these groups of fields must be specified:


      `container-image-uri`::::
      Specify this field to use a custom container image for training. Together
      with the `--command` and `--args` flags, this field represents a
      [`WorkerPoolSpec.ContainerSpec`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/CustomJobSpec?#containerspec)
      message.
      In this case, the `--python-package-uris` flag is disallowed.

      Example:
      --worker-pool-spec=replica-count=1,machine-type=n1-highmem-2,container-image-uri=gcr.io/ucaip-test/ucaip-training-test

      `executor-image-uri, python-module`::::
      Specify these fields to train using a pre-built container and Python
      packages that are already in Cloud Storage. Together with the
      `--python-package-uris` and `--args` flags, these fields represent a
      [`WorkerPoolSpec.PythonPackageSpec`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/CustomJobSpec#pythonpackagespec)
      message .

      Example:
      --worker-pool-spec=machine-type=e2-standard-4,executor-image-uri=us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-4:latest,python-module=trainer.task

      `output-image-uri`::::
      Specify this field to push the output custom container training image to a specific path in Container Registry or Artifact Registry for an autopackaged custom job.

      Example:
      --worker-pool-spec=machine-type=e2-standard-4,executor-image-uri=us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-4:latest,output-image-uri='eu.gcr.io/projectName/imageName',python-module=trainer.task

      `local-package-path, executor-image-uri, output-image-uri, python-module|script`::::
      Specify these fields, optionally with `requirements`, `extra-packages`, or
      `extra-dirs`, to train using a pre-built container and Python code from a
      local path.
      In this case, the `--python-package-uris` flag is disallowed.

      Example using `python-module`:
      --worker-pool-spec=machine-type=e2-standard-4,replica-count=1,executor-image-uri=us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-4:latest,python-module=trainer.task,local-package-path=/usr/page/application

      Example using `script`:
      --worker-pool-spec=machine-type=e2-standard-4,replica-count=1,executor-image-uri=us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-4:latest,script=my_run.sh,local-package-path=/usr/jeff/application
      )actionr   r   r   z	--commandCOMMANDz    Command to be invoked when containers are started.
    It overrides the entrypoint instruction in Dockerfile when provided.
    )r   r   r   r   z--argsARGz?Comma-separated arguments passed to containers or python tasks.)r   r   r   r   z--persistent-resource-idPERSISTENT_RESOURCE_IDa      The name of the persistent resource from the same project and region on
    which to run this custom job.

    If this is specified, the job will be run on existing machines held by the
    PersistentResource instead of on-demand short-lived machines.
    The network and CMEK configs on the job should be consistent with those on
    the PersistentResource, otherwise, the job will be rejected.
    r   r   c                 8   [         R                  " U S[        R                  " [        R
                  5      S9  [         R                  R                  U 5        [         R                  R                  U 5        [         R                  R                  U 5        [         R                  R                  U 5        [         R                  " U S5        [        R                  " U 5        [        R                  U 5        [        R                  U 5        [         R                  U 5        ["        R                  U 5        [$        R                  U 5        [&        R(                  " SSS9nUR+                  [,        5        UR+                  [.        5        UR                  U 5        g)z*Adds flags related to create a custom job.zto create a custom jobprompt_func
custom jobzWorker pool specification.T)r   r   N)shared_flagsAddRegionResourceArgr   GetPromptForRegionFuncr	   SUPPORTED_TRAINING_REGIONSTRAINING_SERVICE_ACCOUNTAddToParserNETWORKENABLE_WEB_ACCESSENABLE_DASHBOARD_ACCESSAddKmsKeyResourceArgr   AddCreateLabelsFlags_DISPLAY_NAME_PYTHON_PACKAGE_URIS_CUSTOM_JOB_ARGS_CUSTOM_JOB_COMMAND_PERSISTENT_RESOURCE_IDr   ArgumentGroupAddArgument_CUSTOM_JOB_CONFIG_WORKER_POOL_SPEC)parserworker_pool_spec_groups     6lib/googlecloudsdk/command_lib/ai/custom_jobs/flags.pyAddCreateCustomJobFlagsr<      s%   ##44

.
.01
 ''33F;""6*  ,,V4&&226:##FL9""6*F#""6*v&!!&)%%f---'$8$$%78$$%67$$V,    c           	      4   [         R                  " [        R                  S[        R
                  " [        R                  " U5      S9[         R                  SS9n[        R                  R                  SUSR                  U5      SS9R                  U 5        g	)
a&  Add a resource argument for a Vertex AI custom job.

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

Args:
  parser: the parser for the command.
  verb: str, the verb to describe the job resource, such as 'to update'.
  regions: list[str], the list of supported regions.
r$   r"   F)resource_collectionresource_namelocationsId
projectsIddisable_auto_completers
custom_jobzThe custom job {}.T)r   N)r   ResourceSpecr   CUSTOM_JOB_COLLECTIONr%   RegionAttributeConfigr   r'    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr   ConceptParserForResourceformatr*   )r9   verbregionsjob_resource_specs       r;   AddCustomJobResourceArgrO      s     ++*@@ 44!88AC::#% ++!!$'	 ,  ![(r=   c           	         U R                  5       nUR                  SS[        R                  " S5      S9  UR                  SS[        R                  " S5      S9  U R                  SS	S
/[        R                  " S5      S9  U R                  SS[        R
                  " 5       [        R                  " S5      S9  U R                  SSSS/[        R                  " S5      S9  U R                  SS[        R
                  " 5       [        R                  " S5      S9  U R                  SS[        R
                  " 5       [        R                  " S5      S9  U R                  SS[        R                  " S5      S9  U R                  S S!S"S#S$9  U R                  S%S&S[        R
                  " 5       [        R                  " S'5      S(9  U R                  S)S*[        R                  " S+5      S9  U R                  S,[        R                  / S-S.S/9  g0)1z*Add local-run related flags to the parser.z--python-modulePYTHON_MODULEz
      Name of the python module to execute, in 'trainer.train' or 'train'
      format. Its path should be relative to the `work_dir`.
      r    z--scriptSCRIPTz
      The relative path of the file to execute. Accepets a Python file or an
      arbitrary bash script. This path should be relative to the `work_dir`.
      z--local-package-path
LOCAL_PATHz
--work-dira  
      local path of the directory where the python-module or script exists.
      If not specified, it use the directory where you run the this command.

      Only the contents of this directory will be accessible to the built
      container image.
      )r   suggestion_aliasesr   z--extra-dirs	EXTRA_DIRa  
      Extra directories under the working directory to include, besides the one
      that contains the main executable.

      By default, only the parent directory of the main script or python module
      is copied to the container.
      For example, if the module is "training.task" or the script is
      "training/task.py", the whole "training" directory, including its
      sub-directories, will always be copied to the container. You may specify
      this flag to also copy other directories if necessary.

      Note: if no parent is specified in 'python_module' or 'scirpt', the whole
      working directory is copied, then you don't need to specify this flag.
      r   z--executor-image-uri	IMAGE_URITz--base-imagea   
      URI or ID of the container image in either the Container Registry or local
      that will run the application.
      See https://cloud.google.com/vertex-ai/docs/training/pre-built-containers
      for available pre-built container images provided by Vertex AI for training.
      )r   r   rT   r   z--requirementsREQUIREMENTSax  
      Python dependencies from PyPI to be used when running the application.
      If this is not specified, and there is no "setup.py" or "requirements.txt"
      in the working directory, your application will only have access to what
      exists in the base image with on other dependencies.

      Example:
      'tensorflow-cpu, pandas==1.2.0, matplotlib>=3.0.2'
      z--extra-packagesPACKAGEa8  
      Local paths to Python archives used as training dependencies in the image
      container.
      These can be absolute or relative paths. However, they have to be under
      the work_dir; Otherwise, this tool will not be able to access it.

      Example:
      'dep1.tar.gz, ./downloads/dep2.whl'
      z--output-image-uriOUTPUT_IMAGEzf
      Uri of the custom container image to be built with the your application
      packed in.
      z--gpu
store_trueFzEnable to use GPU.)r   defaultr   z--docker-run-optionsDOCKER_RUN_OPTIONSz
      Custom Docker run options to pass to image during execution.
      For example, '--no-healthcheck, -a stdin'.

      See https://docs.docker.com/engine/reference/commandline/run/#options for
      more details.
      )r   hiddenr   r   z--service-account-key-fileACCOUNT_KEY_FILEaG  
      The JSON file of a Google Cloud service account private key.
      When specified, the corresponding service account will be used to
      authenticate the local container to access Google Cloud services.
      Note that the key file won't be copied to the container, it will be
      mounted during running time.
      argsz>Additional user arguments to be forwarded to your application.zX$ {command} --script=my_run.sh --base-image=gcr.io/my/image -- --my-arg bar --enable_foo)nargsr[   r   exampleN)add_mutually_exclusive_groupadd_argumenttextwrapdedentr   ArgListargparse	REMAINDER)r9   application_groups     r;   AddLocalRunCustomJobFlagsrj     sV    99;  ?? 
  !    ?? 
  !  	&?? 
 	  
 	 ?? 
 	  ( 	()?? 
   
 	 ?? 
 	   	 ?? 
 	   	?? 
    	lE8L  N 	" ?? 
    	" ?? 
   	 	O.  0r=   ))__doc__
__future__r   r   r   rg   rd   googlecloudsdk.callioper   r    googlecloudsdk.calliope.conceptsr   googlecloudsdk.command_lib.air	   r
   r%   r   )googlecloudsdk.command_lib.ai.custom_jobsr   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr   Argumentr0   rf   r1   re   r7   ArgDictintstrr8   UpdateActionr3   r2   r4   r<   r(   rO   rj    r=   r;   <module>ry      s   ? &  '   / ( 5 3 ? 5 F < D
58
 }}!				K	M  ]]	  
 * MM			  #!$#&"% # "%'//#F%--D)11CH

  	 \
 \
)p d mm				##
	  ==				##	JL  --$
	 -< %.$H$H)6N0r=   