Exemplo n.º 1
0
 def Run(self, args):
   region_ref = args.CONCEPTS.region.Parse()
   region = region_ref.AsDict()['locationsId']
   with endpoint_util.AiplatformEndpointOverrides(
       version=constants.BETA_VERSION, region=region):
     response = client.CustomJobsClient(version=constants.BETA_VERSION).Create(
         region_ref.RelativeName(), args.worker_pool_spec, args.config,
         args.display_name, args.python_package_uris, args.args, args.command,
         validation.GetAndValidateKmsKey(args), args.network,
         args.service_account)
     log.status.Print(
         constants.CUSTOM_JOB_CREATION_DISPLAY_MESSAGE.format(
             id=custom_jobs_util.ParseJobName(response.name),
             state=response.state))
     return response
Exemplo n.º 2
0
 def Run(self, args):
   region_ref = args.CONCEPTS.region.Parse()
   region = region_ref.AsDict()['locationsId']
   with endpoint_util.AiplatformEndpointOverrides(
       version=constants.BETA_VERSION, region=region):
     algorithm = arg_utils.ChoiceToEnum(
         args.algorithm, client.HpTuningJobsClient.GetAlgorithmEnum())
     response = client.HpTuningJobsClient().Create(
         parent=region_ref.RelativeName(),
         config_path=args.config,
         display_name=args.display_name,
         max_trial_count=args.max_trial_count,
         parallel_trial_count=args.parallel_trial_count,
         algorithm=algorithm,
         kms_key_name=validation.GetAndValidateKmsKey(args))
     log.status.Print(
         constants.HPTUNING_JOB_CREATION_DISPLAY_MESSAGE.format(
             id=hp_tuning_jobs_util.ParseJobName(response.name),
             state=response.state))
     return response
  def Run(self, args):
    project = properties.VALUES.core.project.GetOrFail()
    region_ref = args.CONCEPTS.region.Parse()
    region = region_ref.AsDict()['locationsId']
    validation.ValidateRegion(region)

    with endpoint_util.AiplatformEndpointOverrides(
        version=self._version, region=region):
      api_client = client.CustomJobsClient(version=self._version)
      job_spec = self._PrepareJobSpec(args, api_client, project)
      labels = labels_util.ParseCreateArgs(
          args,
          api_client.CustomJobMessage().LabelsValue)

      response = api_client.Create(
          parent=region_ref.RelativeName(),
          display_name=args.display_name,
          job_spec=job_spec,
          kms_key_name=common_validation.GetAndValidateKmsKey(args),
          labels=labels)
      self._DisplayResult(response)
      return response
    def Create(self, location_ref, args):
        """Creates a model deployment monitoring job."""
        endpoint_ref = _ParseEndpoint(args.endpoint, location_ref)
        job_spec = api_util.GetMessage('ModelDeploymentMonitoringJob',
                                       self._version)()
        kms_key_name = common_validation.GetAndValidateKmsKey(args)
        if kms_key_name is not None:
            job_spec.encryptionSpec = api_util.GetMessage(
                'EncryptionSpec', self._version)(kmsKeyName=kms_key_name)

        if args.monitoring_config_from_file:
            data = yaml.load_path(args.monitoring_config_from_file)
            if data:
                job_spec = messages_util.DictToMessageWithErrorCheck(
                    data,
                    api_util.GetMessage('ModelDeploymentMonitoringJob',
                                        self._version))
        else:
            job_spec.modelDeploymentMonitoringObjectiveConfigs = self._ConstructObjectiveConfigForCreate(
                location_ref, endpoint_ref.RelativeName(),
                args.feature_thresholds, args.feature_attribution_thresholds,
                args.dataset, args.bigquery_uri, args.data_format,
                args.gcs_uris, args.target_field, args.training_sampling_rate)
        job_spec.endpoint = endpoint_ref.RelativeName()
        job_spec.displayName = args.display_name

        enable_anomaly_cloud_logging = False if args.anomaly_cloud_logging is None else args.anomaly_cloud_logging
        job_spec.modelMonitoringAlertConfig = api_util.GetMessage(
            'ModelMonitoringAlertConfig',
            self._version)(enableLogging=enable_anomaly_cloud_logging,
                           emailAlertConfig=api_util.GetMessage(
                               'ModelMonitoringAlertConfigEmailAlertConfig',
                               self._version)(userEmails=args.emails))

        job_spec.loggingSamplingStrategy = api_util.GetMessage(
            'SamplingStrategy',
            self._version)(randomSampleConfig=api_util.GetMessage(
                'SamplingStrategyRandomSampleConfig', self._version)(
                    sampleRate=args.prediction_sampling_rate))

        job_spec.modelDeploymentMonitoringScheduleConfig = api_util.GetMessage(
            'ModelDeploymentMonitoringScheduleConfig',
            self._version)(monitorInterval='{}s'.format(
                six.text_type(3600 * int(args.monitoring_frequency))))

        if args.predict_instance_schema:
            job_spec.predictInstanceSchemaUri = args.predict_instance_schema

        if args.analysis_instance_schema:
            job_spec.analysisInstanceSchemaUri = args.analysis_instance_schema

        if args.log_ttl:
            job_spec.logTtl = '{}s'.format(
                six.text_type(86400 * int(args.log_ttl)))

        if args.sample_predict_request:
            instance_json = model_monitoring_jobs_util.ReadInstanceFromArgs(
                args.sample_predict_request)
            job_spec.samplePredictInstance = encoding.PyValueToMessage(
                extra_types.JsonValue, instance_json)

        if self._version == constants.ALPHA_VERSION:
            return self._service.Create(
                self.messages.
                AiplatformProjectsLocationsModelDeploymentMonitoringJobsCreateRequest(
                    parent=location_ref.RelativeName(),
                    googleCloudAiplatformV1alpha1ModelDeploymentMonitoringJob=
                    job_spec))
        elif self._version == constants.BETA_VERSION:
            return self._service.Create(
                self.messages.
                AiplatformProjectsLocationsModelDeploymentMonitoringJobsCreateRequest(
                    parent=location_ref.RelativeName(),
                    googleCloudAiplatformV1beta1ModelDeploymentMonitoringJob=
                    job_spec))
        else:
            return self._service.Create(
                self.messages.
                AiplatformProjectsLocationsModelDeploymentMonitoringJobsCreateRequest(
                    parent=location_ref.RelativeName(),
                    googleCloudAiplatformV1ModelDeploymentMonitoringJob=job_spec
                ))