
                             d Z ddlmZ ddlmZ ddlmZ ddl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 G d dej                         Zy)z ai-platform local train command.    )absolute_import)division)unicode_literalsN)base)flags)local_train)log)filesz]{flag} is ignored if --distributed is not provided.
Did you mean to run distributed training?c                   &    e Zd ZdZed        Zd Zy)RunLocala  Run an AI Platform training job locally.

  This command runs the specified module in an environment
  similar to that of a live AI Platform Training Job.

  This is especially useful in the case of testing distributed models,
  as it allows you to validate that you are properly interacting with the
  AI Platform cluster configuration. If your model expects a specific
  number of parameter servers or workers (i.e. you expect to use the CUSTOM
  machine type), use the --parameter-server-count and --worker-count flags to
  further specify the desired cluster configuration, just as you would in
  your cloud training job configuration:

      $ {command} --module-name trainer.task \
              --package-path /path/to/my/code/trainer \
              --distributed \
              --parameter-server-count 4 \
              --worker-count 8

  Unlike submitting a training job, the --package-path parameter can be
  omitted, and will use your current working directory.

  AI Platform Training sets a TF_CONFIG environment variable on each VM in
  your training job. You can use TF_CONFIG to access the cluster description
  and the task description for each VM.

  Learn more about TF_CONFIG:
  https://cloud.google.com/ai-platform/training/docs/distributed-training-details.
  c                 T   t         j                  j                  |        t        j                         j                  |        t         j                  j                  |        t         j
                  j                  |        t         j                  j                  |        t        j                  dd      j                  |        t         j                  j                  |        t         j                  j                  |        t        j                  d      j                  |        y)z Register flags for this command.FT)upload_helpallow_local)localN)r   PACKAGE_PATHAddToParserGetModuleNameFlagDISTRIBUTED
EVALUATORSPARAM_SERVERSGetJobDirFlagWORKERS
START_PORTGetUserArgs)parsers    &lib/surface/ai_platform/local/train.pyArgszRunLocal.ArgsB   s     
""6*	))&1	!!&)	  (	##F+	Et<HHP	MMf%	  (	D!--f5    c           	         |j                   xs t        j                         }t        j                  j                  t        j                  j                  |            }|j                  xs g }|j                  r|j                  d|j                  f       |j                  dn|j                  }|j                  dn|j                  }|j                  rFt        j                  |j                  ||||j                   xs d|j"                  |      }|| _        y|j                  r)t%        j&                  t(        j+                  d             |j                  r)t%        j&                  t(        j+                  d             t        j,                  |j                  ||t        j.                         	      }|| _        y)
zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    z	--job-dirN   r   )	user_argsz--parameter-server-count)flagz--worker-count)args	task_type)package_pathr
   GetCWDospathdirnameabspathr!   job_dirextendworker_countparameter_server_countdistributedr   RunDistributedmodule_nameevaluator_count
start_portr	   warning_BAD_FLAGS_WARNING_MESSAGEformatMakeProcessGetPrimaryNodeName	exit_code)selfr#   r%   package_rootr!   r-   ps_countretvals           r   RunzRunLocal.RunO   sg    $$6L77??277??<#@AL$"I||T\\23))11t7H7HL//7qT=X=XH))









#!
//f* DN 
	$	$.55+ 6 - 	.			.55;K5LM&&



224	6f DNr   N)__name__
__module____qualname____doc__staticmethodr   r>    r   r   r   r   #   s     < 
6 
6*r   r   )rB   
__future__r   r   r   r'   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml_enginer   r   googlecloudsdk.corer	   googlecloudsdk.core.utilr
   r5   Commandr   rD   r   r   <module>rK      s?    ' &  ' 	 ( 6 < # * Vt|| Vr   