예제 #1
0
def _Run(args, version):
    """Create a new Vertex AI endpoint."""
    validation.ValidateDisplayName(args.display_name)

    region_ref = args.CONCEPTS.region.Parse()
    args.region = region_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        if version == constants.GA_VERSION:
            op = endpoints_client.Create(
                region_ref, args.display_name,
                labels_util.ParseCreateArgs(
                    args, endpoints_client.messages.
                    GoogleCloudAiplatformV1Endpoint.LabelsValue),
                args.description, args.network, args.endpoint_id)
        else:
            op = endpoints_client.CreateBeta(
                region_ref, args.display_name,
                labels_util.ParseCreateArgs(
                    args, endpoints_client.messages.
                    GoogleCloudAiplatformV1beta1Endpoint.LabelsValue),
                args.description, args.network, args.endpoint_id)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'name' in response:
                log.status.Print(('Created Vertex AI endpoint: {}.').format(
                    response['name']))
        return response_msg
def _Run(args, version):
    """Deploy a model to an existing Vertex AI endpoint."""
    validation.ValidateDisplayName(args.display_name)
    if version != constants.GA_VERSION:
        validation.ValidateAutoscalingMetricSpecs(
            args.autoscaling_metric_specs)

    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        if version == constants.GA_VERSION:
            op = endpoints_client.DeployModel(
                endpoint_ref,
                args.model,
                args.region,
                args.display_name,
                machine_type=args.machine_type,
                accelerator_dict=args.accelerator,
                min_replica_count=args.min_replica_count,
                max_replica_count=args.max_replica_count,
                enable_access_logging=args.enable_access_logging,
                disable_container_logging=args.disable_container_logging,
                service_account=args.service_account,
                traffic_split=args.traffic_split,
                deployed_model_id=args.deployed_model_id)
        else:
            op = endpoints_client.DeployModelBeta(
                endpoint_ref,
                args.model,
                args.region,
                args.display_name,
                machine_type=args.machine_type,
                accelerator_dict=args.accelerator,
                min_replica_count=args.min_replica_count,
                max_replica_count=args.max_replica_count,
                autoscaling_metric_specs=args.autoscaling_metric_specs,
                enable_access_logging=args.enable_access_logging,
                enable_container_logging=args.enable_container_logging,
                service_account=args.service_account,
                traffic_split=args.traffic_split,
                deployed_model_id=args.deployed_model_id)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'deployedModel' in response and 'id' in response[
                    'deployedModel']:
                log.status.Print(('Deployed a model to the endpoint {}. '
                                  'Id of the deployed model: {}.').format(
                                      endpoint_ref.AsDict()['endpointsId'],
                                      response['deployedModel']['id']))
        return response_msg
예제 #3
0
def _Run(args, version):
    """Undeploy a model fro man existing AI Platform endpoint."""
    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.UndeployModelBeta(endpoint_ref, args)
        return operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
def _Run(args, version):
    """Delete an existing Vertex AI endpoint."""
    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    endpoint_id = endpoint_ref.AsDict()['endpointsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        console_io.PromptContinue(
            'This will delete endpoint [{}]...'.format(endpoint_id),
            cancel_on_no=True)
        op = endpoints_client.Delete(endpoint_ref)
        return operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
예제 #5
0
def _Run(args, version):
    """Create a new AI Platform endpoint."""
    validation.ValidateDisplayName(args.display_name)

    region_ref = args.CONCEPTS.region.Parse()
    args.region = region_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.CreateBeta(region_ref, args)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'name' in response:
                log.status.Print(('Created AI Platform endpoint: {}.').format(
                    response['name']))
        return response_msg
def _Run(args, version):
  """Undeploy a model fro man existing Vertex AI endpoint."""
  endpoint_ref = args.CONCEPTS.endpoint.Parse()
  args.region = endpoint_ref.AsDict()['locationsId']
  with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
    endpoints_client = client.EndpointsClient(version=version)
    operation_client = operations.OperationsClient()
    if version == constants.GA_VERSION:
      op = endpoints_client.UndeployModel(
          endpoint_ref,
          args.deployed_model_id,
          traffic_split=args.traffic_split)
    else:
      op = endpoints_client.UndeployModelBeta(
          endpoint_ref,
          args.deployed_model_id,
          traffic_split=args.traffic_split)
    return operations_util.WaitForOpMaybe(
        operation_client, op, endpoints_util.ParseOperation(op.name))
예제 #7
0
def _Run(args, version):
    """Deploy a model to an existing AI Platform endpoint."""
    validation.ValidateDisplayName(args.display_name)

    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.DeployModelBeta(endpoint_ref, args)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'deployedModel' in response and 'id' in response[
                    'deployedModel']:
                log.status.Print(('Deployed a model to the endpoint {}. '
                                  'Id of the deployed model: {}.').format(
                                      endpoint_ref.AsDict()['endpointsId'],
                                      response['deployedModel']['id']))
        return response_msg