def Run(self, args):
        """This 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.
    """
        # TODO(b/33234717): remove this after deprecation period
        flags.ProcessPackages(args)

        region = properties.VALUES.compute.region.Get(required=True)
        uris = jobs_prep.RunSetupAndUpload(args.packages, args.staging_bucket,
                                           args.package_path, args.job)
        log.debug('Using {0} as trainer uris'.format(uris))
        job = jobs.BuildTrainingJob(path=args.config,
                                    module_name=args.module_name,
                                    job_name=args.job,
                                    trainer_uri=uris,
                                    region=region,
                                    user_args=args.user_args)

        job = jobs.Create(job)
        if args. async:
            log.status.Print('Job [{}] submitted successfully.'.format(
                job.jobId))
            log.status.Print(_FOLLOW_UP_MESSAGE.format(job_id=job.jobId))
            return job

        log_fetcher = jobs.LogFetcher(job_id=job.jobId,
                                      polling_interval=_POLLING_INTERVAL,
                                      allow_multiline_logs=False)

        printer = resource_printer.Printer(jobs.LogFetcher.LOG_FORMAT,
                                           out=log.err)

        def _CtrlCHandler(signal, frame):
            del signal, frame  # Unused
            raise KeyboardInterrupt

        with execution_utils.CtrlCSection(_CtrlCHandler):
            try:
                printer.Print(log_fetcher.YieldLogs())
            except KeyboardInterrupt:
                log.status.Print('Received keyboard interrupt.')
                log.status.Print(_FOLLOW_UP_MESSAGE.format(job_id=job.jobId))

        job = jobs.Get(job.jobId)
        # If the job itself failed, we will return a failure status.
        if job.state is not job.StateValueValuesEnum.SUCCEEDED:
            self.exit_code = 1

        return job
Beispiel #2
0
    def Run(self, args):
        """This 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.
    """
        job = jobs.BuildBatchPredictionJob(job_name=args.job,
                                           model_name=args.model,
                                           version_name=args.version,
                                           input_paths=args.input_paths,
                                           data_format=args.data_format,
                                           output_path=args.output_path,
                                           region=args.region)
        return jobs.Create(job)
    def Run(self, args):
        """This 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.
    """
        uris = jobs_prep.RunSetupAndUpload(args.packages, args.staging_bucket,
                                           args.package_path)
        log.debug('Using {0} as trainer uris'.format(uris))
        job = jobs.BuildTrainingJob(path=args.config,
                                    module_name=args.module_name,
                                    job_name=args.job,
                                    trainer_uri=uris,
                                    region=args.region,
                                    user_args=args.user_args)
        return jobs.Create(job)