// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.aiplatform.v1beta1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/aiplatform/v1beta1/content.proto";
import "google/cloud/aiplatform/v1beta1/encryption_spec.proto";
import "google/cloud/aiplatform/v1beta1/evaluation_service.proto";
import "google/cloud/aiplatform/v1beta1/job_state.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.AIPlatform.V1Beta1";
option go_package = "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb;aiplatformpb";
option java_multiple_files = true;
option java_outer_classname = "TuningJobProto";
option java_package = "com.google.cloud.aiplatform.v1beta1";
option php_namespace = "Google\\Cloud\\AIPlatform\\V1beta1";
option ruby_package = "Google::Cloud::AIPlatform::V1beta1";

// Represents a TuningJob that runs with Google owned models.
message TuningJob {
  option (google.api.resource) = {
    type: "aiplatform.googleapis.com/TuningJob"
    pattern: "projects/{project}/locations/{location}/tuningJobs/{tuning_job}"
    plural: "tuningJobs"
    singular: "tuningJob"
  };

  oneof source_model {
    // The base model that is being tuned. See [Supported
    // models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/tuning#supported_models).
    string base_model = 4;

    // The pre-tuned model for continuous tuning.
    PreTunedModel pre_tuned_model = 31;
  }

  oneof tuning_spec {
    // Tuning Spec for Supervised Fine Tuning.
    SupervisedTuningSpec supervised_tuning_spec = 5;

    // Tuning Spec for Distillation.
    DistillationSpec distillation_spec = 17;

    // Tuning Spec for open sourced and third party Partner models.
    PartnerModelTuningSpec partner_model_tuning_spec = 21;

    // Tuning Spec for Veo Tuning.
    VeoTuningSpec veo_tuning_spec = 33;

    // Tuning Spec for Veo LoRA Tuning.
    VeoLoraTuningSpec veo_lora_tuning_spec = 38;
  }

  // Output only. Identifier. Resource name of a TuningJob. Format:
  // `projects/{project}/locations/{location}/tuningJobs/{tuning_job}`
  string name = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  // Optional. The display name of the
  // [TunedModel][google.cloud.aiplatform.v1.Model]. The name can be up to 128
  // characters long and can consist of any UTF-8 characters.
  string tuned_model_display_name = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The description of the
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob].
  string description = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The user-provided path to custom model weights. Set this field
  // to tune a custom model. The path must be a Cloud Storage directory that
  // contains the model weights in .safetensors format along with associated
  // model metadata files. If this field is set, the base_model field must still
  // be set to indicate which base model the custom model is derived from. This
  // feature is only available for open source models.
  string custom_base_model = 26 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The detailed state of the job.
  JobState state = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time when the
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob] was created.
  google.protobuf.Timestamp create_time = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time when the
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob] for the first time
  // entered the `JOB_STATE_RUNNING` state.
  google.protobuf.Timestamp start_time = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time when the TuningJob entered any of the following
  // [JobStates][google.cloud.aiplatform.v1.JobState]: `JOB_STATE_SUCCEEDED`,
  // `JOB_STATE_FAILED`, `JOB_STATE_CANCELLED`, `JOB_STATE_EXPIRED`.
  google.protobuf.Timestamp end_time = 9
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time when the
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob] was most recently
  // updated.
  google.protobuf.Timestamp update_time = 10
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Only populated when job's state is `JOB_STATE_FAILED` or
  // `JOB_STATE_CANCELLED`.
  google.rpc.Status error = 11 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The labels with user-defined metadata to organize
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob] and generated resources
  // such as [Model][google.cloud.aiplatform.v1.Model] and
  // [Endpoint][google.cloud.aiplatform.v1.Endpoint].
  //
  // Label keys and values can be no longer than 64 characters
  // (Unicode codepoints), can only contain lowercase letters, numeric
  // characters, underscores and dashes. International characters are allowed.
  //
  // See https://goo.gl/xmQnxf for more information and examples of labels.
  map<string, string> labels = 12 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The Experiment associated with this
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob].
  string experiment = 13 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/Context"
    }
  ];

  // Output only. The tuned model resources associated with this
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob].
  TunedModel tuned_model = 14 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The tuning data statistics associated with this
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob].
  TuningDataStats tuning_data_stats = 15
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The resource name of the PipelineJob associated with the
  // [TuningJob][google.cloud.aiplatform.v1.TuningJob]. Format:
  // `projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`.
  string pipeline_job = 18 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/PipelineJob"
    }
  ];

  // Customer-managed encryption key options for a TuningJob. If this is set,
  // then all resources created by the TuningJob will be encrypted with the
  // provided encryption key.
  EncryptionSpec encryption_spec = 16;

  // The service account that the tuningJob workload runs as.
  // If not specified, the Vertex AI Secure Fine-Tuned Service Agent in the
  // project will be used. See
  // https://cloud.google.com/iam/docs/service-agents#vertex-ai-secure-fine-tuning-service-agent
  //
  // Users starting the pipeline must have the `iam.serviceAccounts.actAs`
  // permission on this service account.
  string service_account = 22;

  // Optional. Cloud Storage path to the directory where tuning job outputs are
  // written to. This field is only available and required for open source
  // models.
  string output_uri = 25 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Evaluation runs for the Tuning Job.
  repeated EvaluateDatasetRun evaluate_dataset_runs = 32
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The Model Registry Model and Online Prediction Endpoint associated with
// this [TuningJob][google.cloud.aiplatform.v1.TuningJob].
message TunedModel {
  // Output only. The resource name of the TunedModel. Format:
  //
  // `projects/{project}/locations/{location}/models/{model}@{version_id}`
  //
  // When tuning from a base model, the version_id will be 1.
  //
  // For continuous tuning, the version id will be incremented by 1 from the
  // last version id in the parent model. E.g.,
  // `projects/{project}/locations/{location}/models/{model}@{last_version_id +
  // 1}`
  string model = 1 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/Model"
    }
  ];

  // Output only. A resource name of an Endpoint. Format:
  // `projects/{project}/locations/{location}/endpoints/{endpoint}`.
  string endpoint = 2 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/Endpoint"
    }
  ];

  // Output only. The checkpoints associated with this TunedModel.
  // This field is only populated for tuning jobs that enable intermediate
  // checkpoints.
  repeated TunedModelCheckpoint checkpoints = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Dataset distribution for Supervised Tuning.
message SupervisedTuningDatasetDistribution {
  // Dataset bucket used to create a histogram for the distribution given a
  // population of values.
  message DatasetBucket {
    // Output only. Number of values in the bucket.
    double count = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Left bound of the bucket.
    double left = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Right bound of the bucket.
    double right = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Output only. Sum of a given population of values.
  int64 sum = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Sum of a given population of values that are billable.
  int64 billable_sum = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The minimum of the population values.
  double min = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The maximum of the population values.
  double max = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The arithmetic mean of the values in the population.
  double mean = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The median of the values in the population.
  double median = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The 5th percentile of the values in the population.
  double p5 = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The 95th percentile of the values in the population.
  double p95 = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Defines the histogram bucket.
  repeated DatasetBucket buckets = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Tuning data statistics for Supervised Tuning.
message SupervisedTuningDataStats {
  // Output only. Number of examples in the tuning dataset.
  int64 tuning_dataset_example_count = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of tuning characters in the tuning dataset.
  int64 total_tuning_character_count = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of billable characters in the tuning dataset.
  int64 total_billable_character_count = 3
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of billable tokens in the tuning dataset.
  int64 total_billable_token_count = 9
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of tuning steps for this Tuning Job.
  int64 tuning_step_count = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the user input tokens.
  SupervisedTuningDatasetDistribution user_input_token_distribution = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the user output tokens.
  SupervisedTuningDatasetDistribution user_output_token_distribution = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the messages per example.
  SupervisedTuningDatasetDistribution user_message_per_example_distribution = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Sample user messages in the training dataset uri.
  repeated Content user_dataset_examples = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The number of examples in the dataset that have been dropped.
  // An example can be dropped for reasons including: too many tokens, contains
  // an invalid image, contains too many images, etc.
  int64 total_truncated_example_count = 10
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. A partial sample of the indices (starting from 1) of the
  // dropped examples.
  repeated int64 truncated_example_indices = 11
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. For each index in `truncated_example_indices`, the user-facing
  // reason why the example was dropped.
  repeated string dropped_example_reasons = 12
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Distribution computed over a tuning dataset.
message DatasetDistribution {
  // Dataset bucket used to create a histogram for the distribution given a
  // population of values.
  message DistributionBucket {
    // Output only. Number of values in the bucket.
    int64 count = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Left bound of the bucket.
    double left = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Right bound of the bucket.
    double right = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Output only. Sum of a given population of values.
  double sum = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The minimum of the population values.
  double min = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The maximum of the population values.
  double max = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The arithmetic mean of the values in the population.
  double mean = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The median of the values in the population.
  double median = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The 5th percentile of the values in the population.
  double p5 = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The 95th percentile of the values in the population.
  double p95 = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Defines the histogram bucket.
  repeated DistributionBucket buckets = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Statistics computed over a tuning dataset.
message DatasetStats {
  // Output only. Number of examples in the tuning dataset.
  int64 tuning_dataset_example_count = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of tuning characters in the tuning dataset.
  int64 total_tuning_character_count = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of billable characters in the tuning dataset.
  int64 total_billable_character_count = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of tuning steps for this Tuning Job.
  int64 tuning_step_count = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the user input tokens.
  DatasetDistribution user_input_token_distribution = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the user output tokens.
  optional DatasetDistribution user_output_token_distribution = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Dataset distributions for the messages per example.
  DatasetDistribution user_message_per_example_distribution = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Sample user messages in the training dataset uri.
  repeated Content user_dataset_examples = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Statistics computed for datasets used for distillation.
message DistillationDataStats {
  // Output only. Statistics computed for the training dataset.
  DatasetStats training_dataset_stats = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The tuning data statistic values for
// [TuningJob][google.cloud.aiplatform.v1.TuningJob].
message TuningDataStats {
  oneof tuning_data_stats {
    // The SFT Tuning data stats.
    SupervisedTuningDataStats supervised_tuning_data_stats = 1;

    // Output only. Statistics for distillation.
    DistillationDataStats distillation_data_stats = 3
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }
}

// Hyperparameters for SFT.
message SupervisedHyperParameters {
  // Supported adapter sizes for tuning.
  enum AdapterSize {
    // Adapter size is unspecified.
    ADAPTER_SIZE_UNSPECIFIED = 0;

    // Adapter size 1.
    ADAPTER_SIZE_ONE = 1;

    // Adapter size 2.
    ADAPTER_SIZE_TWO = 6;

    // Adapter size 4.
    ADAPTER_SIZE_FOUR = 2;

    // Adapter size 8.
    ADAPTER_SIZE_EIGHT = 3;

    // Adapter size 16.
    ADAPTER_SIZE_SIXTEEN = 4;

    // Adapter size 32.
    ADAPTER_SIZE_THIRTY_TWO = 5;
  }

  // Optional. Number of complete passes the model makes over the entire
  // training dataset during training.
  int64 epoch_count = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Multiplier for adjusting the default learning rate.
  // Mutually exclusive with `learning_rate`.
  double learning_rate_multiplier = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Learning rate for tuning.
  // Mutually exclusive with `learning_rate_multiplier`.
  // This feature is only available for open source models.
  double learning_rate = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Adapter size for tuning.
  AdapterSize adapter_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Batch size for tuning.
  // This feature is only available for open source models.
  int64 batch_size = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Tuning Spec for Supervised Tuning for first party models.
message SupervisedTuningSpec {
  // Supported tuning modes.
  enum TuningMode {
    // Tuning mode is unspecified.
    TUNING_MODE_UNSPECIFIED = 0;

    // Full fine-tuning mode.
    TUNING_MODE_FULL = 1;

    // PEFT adapter tuning mode.
    TUNING_MODE_PEFT_ADAPTER = 2;
  }

  // Required. Training dataset used for tuning. The dataset can be specified as
  // either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string training_dataset_uri = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. Validation dataset used for tuning. The dataset can be specified
  // as either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string validation_dataset_uri = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hyperparameters for SFT.
  SupervisedHyperParameters hyper_parameters = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. If set to true, disable intermediate checkpoints for SFT and only
  // the last checkpoint will be exported. Otherwise, enable intermediate
  // checkpoints for SFT. Default is false.
  bool export_last_checkpoint_only = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Evaluation Config for Tuning Job.
  EvaluationConfig evaluation_config = 5
      [(google.api.field_behavior) = OPTIONAL];

  // Tuning mode.
  TuningMode tuning_mode = 7;
}

// Tuning Spec for Distillation.
message DistillationSpec {
  // The teacher model that is being distilled from. See [Supported
  // models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/tuning#supported_models).
  oneof teacher_model {
    // The base teacher model that is being distilled. See [Supported
    // models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/tuning#supported_models).
    string base_teacher_model = 5;

    // The resource name of the Tuned teacher model. Format:
    // `projects/{project}/locations/{location}/models/{model}`.
    string tuned_teacher_model_source = 6 [(google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/Model"
    }];
  }

  // Required. Cloud Storage path to file containing training dataset for
  // tuning. The dataset must be formatted as a JSONL file.
  string training_dataset_uri = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. Cloud Storage path to file containing validation dataset for
  // tuning. The dataset must be formatted as a JSONL file.
  optional string validation_dataset_uri = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hyperparameters for Distillation.
  DistillationHyperParameters hyper_parameters = 3
      [(google.api.field_behavior) = OPTIONAL];

  // The student model that is being tuned, e.g., "google/gemma-2b-1.1-it".
  string student_model = 4;

  // Required. A path in a Cloud Storage bucket, which will be treated as the
  // root output directory of the distillation pipeline. It is used by the
  // system to generate the paths of output artifacts.
  string pipeline_root_directory = 7 [(google.api.field_behavior) = REQUIRED];
}

// Hyperparameters for Distillation.
message DistillationHyperParameters {
  // Optional. Number of complete passes the model makes over the entire
  // training dataset during training.
  optional int64 epoch_count = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Multiplier for adjusting the default learning rate.
  optional double learning_rate_multiplier = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Adapter size for distillation.
  SupervisedHyperParameters.AdapterSize adapter_size = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Tuning spec for Partner models.
message PartnerModelTuningSpec {
  // Required. Cloud Storage path to file containing training dataset for
  // tuning. The dataset must be formatted as a JSONL file.
  string training_dataset_uri = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. Cloud Storage path to file containing validation dataset for
  // tuning. The dataset must be formatted as a JSONL file.
  string validation_dataset_uri = 2 [(google.api.field_behavior) = OPTIONAL];

  // Hyperparameters for tuning. The accepted hyper_parameters and their valid
  // range of values will differ depending on the base model.
  map<string, google.protobuf.Value> hyper_parameters = 3;
}

// TunedModel Reference for legacy model migration.
message TunedModelRef {
  // The Tuned Model Reference for the model.
  oneof tuned_model_ref {
    // Support migration from model registry.
    string tuned_model = 1 [(google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/Model"
    }];

    // Support migration from tuning job list page, from gemini-1.0-pro-002
    // to 1.5 and above.
    string tuning_job = 2 [(google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/TuningJob"
    }];

    // Support migration from tuning job list page, from bison model to gemini
    // model.
    string pipeline_job = 3 [(google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/PipelineJob"
    }];
  }
}

// Hyperparameters for Veo.
message VeoHyperParameters {
  // An enum defining the tuning task used for Veo.
  enum TuningTask {
    // Default value. This value is unused.
    TUNING_TASK_UNSPECIFIED = 0;

    // Tuning task for image to video.
    TUNING_TASK_I2V = 1;

    // Tuning task for text to video.
    TUNING_TASK_T2V = 2;

    // Tuning task for reference to video.
    TUNING_TASK_R2V = 3;
  }

  // The speed of the tuning job. Only supported for Veo 3.0 models.
  enum TuningSpeed {
    // The default / unset value. For Veo 3.0 models, this defaults to FAST.
    TUNING_SPEED_UNSPECIFIED = 0;

    // Regular tuning speed.
    REGULAR = 1;

    // Fast tuning speed.
    FAST = 2;
  }

  // Adapter size for LoRA tuning.
  enum AdapterSize {
    // Adapter size is unspecified.
    ADAPTER_SIZE_UNSPECIFIED = 0;

    // Adapter size 8.
    // This is the default adapter size for Veo LoRA tuning.
    ADAPTER_SIZE_EIGHT = 8;

    // Adapter size 16.
    ADAPTER_SIZE_SIXTEEN = 16;

    // Adapter size 32.
    ADAPTER_SIZE_THIRTY_TWO = 32;
  }

  // Optional. Number of complete passes the model makes over the entire
  // training dataset during training.
  int64 epoch_count = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Multiplier for adjusting the default learning rate.
  double learning_rate_multiplier = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The tuning task. Either I2V or T2V.
  TuningTask tuning_task = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The ratio of Google internal dataset to use in the training
  // mixture, in range of `[0, 1)`. If `0.2`, it means 20% of Google internal
  // dataset and 80% of user dataset will be used for training. If not set, the
  // default value is 0.1.
  optional double veo_data_mixture_ratio = 4
      [(google.api.field_behavior) = OPTIONAL];

  // The speed of the tuning job. Only supported for Veo 3.0 models.
  optional TuningSpeed tuning_speed = 5;

  // Optional. The adapter size for LoRA tuning.
  AdapterSize adapter_size = 6 [(google.api.field_behavior) = OPTIONAL];
}

// Tuning Spec for Veo Model Tuning.
message VeoTuningSpec {
  // Required. Training dataset used for tuning. The dataset can be specified as
  // either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string training_dataset_uri = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. Validation dataset used for tuning. The dataset can be specified
  // as either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string validation_dataset_uri = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hyperparameters for Veo.
  VeoHyperParameters hyper_parameters = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Tuning Spec for Veo LoRA Model Tuning.
message VeoLoraTuningSpec {
  // Required. Training dataset used for tuning. The dataset can be specified as
  // either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string training_dataset_uri = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. Validation dataset used for tuning. The dataset can be specified
  // as either a Cloud Storage path to a JSONL file or as the resource name of a
  // Vertex Multimodal Dataset.
  string validation_dataset_uri = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hyperparameters for Veo LoRA.
  VeoHyperParameters hyper_parameters = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Evaluation Config for Tuning Job.
message EvaluationConfig {
  // Required. The metrics used for evaluation.
  repeated Metric metrics = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Config for evaluation output.
  OutputConfig output_config = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Autorater config for evaluation.
  AutoraterConfig autorater_config = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Configuration options for inference generation and outputs.
  // If not set, default generation parameters are used.
  GenerationConfig inference_generation_config = 5
      [(google.api.field_behavior) = OPTIONAL];
}

// Evaluate Dataset Run Result for Tuning Job.
message EvaluateDatasetRun {
  // Output only. The operation ID of the evaluation run. Format:
  // `projects/{project}/locations/{location}/operations/{operation_id}`.
  string operation_name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The resource name of the evaluation run. Format:
  // `projects/{project}/locations/{location}/evaluationRuns/{evaluation_run_id}`.
  string evaluation_run = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The checkpoint id used in the evaluation run. Only populated
  // when evaluating checkpoints.
  string checkpoint_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Results for EvaluationService.
  EvaluateDatasetResponse evaluate_dataset_response = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The error of the evaluation run if any.
  google.rpc.Status error = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// TunedModelCheckpoint for the Tuned Model of a Tuning Job.
message TunedModelCheckpoint {
  // The ID of the checkpoint.
  string checkpoint_id = 1;

  // The epoch of the checkpoint.
  int64 epoch = 2;

  // The step of the checkpoint.
  int64 step = 3;

  // The Endpoint resource name that the checkpoint is deployed to. Format:
  // `projects/{project}/locations/{location}/endpoints/{endpoint}`.
  string endpoint = 4;
}

// A pre-tuned model for continuous tuning.
message PreTunedModel {
  // The resource name of the Model.
  // E.g., a model resource name with a specified version id or alias:
  //
  // `projects/{project}/locations/{location}/models/{model}@{version_id}`
  //
  // `projects/{project}/locations/{location}/models/{model}@{alias}`
  //
  // Or, omit the version id to use the default version:
  //
  // `projects/{project}/locations/{location}/models/{model}`
  string tuned_model_name = 1 [(google.api.resource_reference) = {
    type: "aiplatform.googleapis.com/Model"
  }];

  // Optional. The source checkpoint id. If not specified, the default
  // checkpoint will be used.
  string checkpoint_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The name of the base model this
  // [PreTunedModel][google.cloud.aiplatform.v1beta1.PreTunedModel] was tuned
  // from.
  string base_model = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}
