From d49e04c05522859e725fbaa0407b262684002512 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:28:43 -0700 Subject: [PATCH] feat: add TunedModelRef and RebaseTunedModel Api for Vertex GenAiTuningService (#7692) docs: limit comment `SupervisedTuningSpec` for 1p tuning PiperOrigin-RevId: 676969679 Source-Link: https://github.com/googleapis/googleapis/commit/2a98f797cb083b632a6c03b8472f850a8a674fb0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/eb6e7f595a86b385f1f4593e43cbe1015c29ef79 Copy-Tag: eyJwIjoiQWlQbGF0Zm9ybS8uT3dsQm90LnlhbWwiLCJoIjoiZWI2ZTdmNTk1YTg2YjM4NWYxZjQ1OTNlNDNjYmUxMDE1YzI5ZWY3OSJ9 --- AiPlatform/metadata/V1/GenaiTuningService.php | 23 +- AiPlatform/metadata/V1/TuningJob.php | Bin 4455 -> 4686 bytes .../rebase_tuned_model.php | 89 ++++++ .../V1/Client/GenAiTuningServiceClient.php | 106 +++++++ .../V1/RebaseTunedModelOperationMetadata.php | 78 +++++ AiPlatform/src/V1/RebaseTunedModelRequest.php | 267 ++++++++++++++++++ AiPlatform/src/V1/SupervisedTuningSpec.php | 2 +- AiPlatform/src/V1/TunedModelRef.php | 147 ++++++++++ AiPlatform/src/V1/gapic_metadata.json | 5 + .../gen_ai_tuning_service_client_config.json | 5 + ...en_ai_tuning_service_descriptor_config.php | 20 ++ ...n_ai_tuning_service_rest_client_config.php | 12 + .../Client/GenAiTuningServiceClientTest.php | 142 ++++++++++ 13 files changed, 891 insertions(+), 5 deletions(-) create mode 100644 AiPlatform/samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php create mode 100644 AiPlatform/src/V1/RebaseTunedModelOperationMetadata.php create mode 100644 AiPlatform/src/V1/RebaseTunedModelRequest.php create mode 100644 AiPlatform/src/V1/TunedModelRef.php diff --git a/AiPlatform/metadata/V1/GenaiTuningService.php b/AiPlatform/metadata/V1/GenaiTuningService.php index b5113f67b5e1..d7be0592dcc8 100644 --- a/AiPlatform/metadata/V1/GenaiTuningService.php +++ b/AiPlatform/metadata/V1/GenaiTuningService.php @@ -18,12 +18,15 @@ public static function initOnce() { \GPBMetadata\Google\Api\Client::initOnce(); \GPBMetadata\Google\Api\FieldBehavior::initOnce(); \GPBMetadata\Google\Api\Resource::initOnce(); + \GPBMetadata\Google\Cloud\Aiplatform\V1\Io::initOnce(); + \GPBMetadata\Google\Cloud\Aiplatform\V1\Operation::initOnce(); \GPBMetadata\Google\Cloud\Aiplatform\V1\TuningJob::initOnce(); + \GPBMetadata\Google\Longrunning\Operations::initOnce(); \GPBMetadata\Google\Protobuf\GPBEmpty::initOnce(); $pool->internalAddGeneratedFile( ' -Ò -5google/cloud/aiplatform/v1/genai_tuning_service.protogoogle.cloud.aiplatform.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.proto+google/cloud/aiplatform/v1/tuning_job.protogoogle/protobuf/empty.proto"“ +’ +5google/cloud/aiplatform/v1/genai_tuning_service.protogoogle.cloud.aiplatform.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.proto#google/cloud/aiplatform/v1/io.proto*google/cloud/aiplatform/v1/operation.proto+google/cloud/aiplatform/v1/tuning_job.proto#google/longrunning/operations.protogoogle/protobuf/empty.proto"“ CreateTuningJobRequest9 parent ( B)àAúA# !locations.googleapis.com/Location> @@ -44,13 +47,25 @@ public static function initOnce() { next_page_token ( "S CancelTuningJobRequest9 name ( B+àAúA% -#aiplatform.googleapis.com/TuningJob2¶ +#aiplatform.googleapis.com/TuningJob"Ò +RebaseTunedModelRequest9 +parent ( B)àAúA# +!locations.googleapis.com/LocationG +tuned_model_ref ( 2).google.cloud.aiplatform.v1.TunedModelRefBàA> + +tuning_job ( 2%.google.cloud.aiplatform.v1.TuningJobBàAM +artifact_destination ( 2*.google.cloud.aiplatform.v1.GcsDestinationBàA$ +deploy_to_same_endpoint (BàA"s +!RebaseTunedModelOperationMetadataN +generic_metadata ( 24.google.cloud.aiplatform.v1.GenericOperationMetadata2¶ GenAiTuningServiceÄ CreateTuningJob2.google.cloud.aiplatform.v1.CreateTuningJobRequest%.google.cloud.aiplatform.v1.TuningJob"VÚAparent,tuning_job‚Óä“<"./v1/{parent=projects/*/locations/*}/tuningJobs: tuning_job¥ GetTuningJob/.google.cloud.aiplatform.v1.GetTuningJobRequest%.google.cloud.aiplatform.v1.TuningJob"=ÚAname‚Óä“0./v1/{name=projects/*/locations/*/tuningJobs/*}¸ ListTuningJobs1.google.cloud.aiplatform.v1.ListTuningJobsRequest2.google.cloud.aiplatform.v1.ListTuningJobsResponse"?ÚAparent‚Óä“0./v1/{parent=projects/*/locations/*}/tuningJobs¦ -CancelTuningJob2.google.cloud.aiplatform.v1.CancelTuningJobRequest.google.protobuf.Empty"GÚAname‚Óä“:"5/v1/{name=projects/*/locations/*/tuningJobs/*}:cancel:*MÊAaiplatform.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÕ +CancelTuningJob2.google.cloud.aiplatform.v1.CancelTuningJobRequest.google.protobuf.Empty"GÚAname‚Óä“:"5/v1/{name=projects/*/locations/*/tuningJobs/*}:cancel:*ý +RebaseTunedModel3.google.cloud.aiplatform.v1.RebaseTunedModelRequest.google.longrunning.Operation"”ÊA. + TuningJob!RebaseTunedModelOperationMetadataÚAparent,tuned_model_ref‚Óä“D"?/v1/{parent=projects/*/locations/*}/tuningJobs:rebaseTunedModel:*MÊAaiplatform.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÕ com.google.cloud.aiplatform.v1BGenAiTuningServiceProtoPZ>cloud.google.com/go/aiplatform/apiv1/aiplatformpb;aiplatformpbªGoogle.Cloud.AIPlatform.V1ÊGoogle\\Cloud\\AIPlatform\\V1êGoogle::Cloud::AIPlatform::V1bproto3' , true); diff --git a/AiPlatform/metadata/V1/TuningJob.php b/AiPlatform/metadata/V1/TuningJob.php index 195142335932fa9b957bdb96eca9578d2c5cf4a7..869e513605254f17c060681c413ac388ad7d1103 100644 GIT binary patch delta 189 zcmaE^bWUZ%EM}%>GMncxui?>Cdd$eh8&aB=n&O+ElA05gnkHn;#a#jth|dLyNH8ie zYH&KK{Bl&}lAo;0E~Nxk=)oXl$HfIymzkFypOv2^!30*O@yk(_OBtk06KE(<&MQ9& zsMLvzry#Q+H77GK6|9&UtXS)pV~jeNDoC|L08|>R-bs*)AIS;vMX70CJPP*YIrC7nElN09OVF0{{R3 diff --git a/AiPlatform/samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php b/AiPlatform/samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php new file mode 100644 index 000000000000..3036fada50ef --- /dev/null +++ b/AiPlatform/samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php @@ -0,0 +1,89 @@ +setParent($formattedParent) + ->setTunedModelRef($tunedModelRef); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $genAiTuningServiceClient->rebaseTunedModel($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var TuningJob $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } else { + /** @var Status $error */ + $error = $response->getError(); + printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedParent = GenAiTuningServiceClient::locationName('[PROJECT]', '[LOCATION]'); + + rebase_tuned_model_sample($formattedParent); +} +// [END aiplatform_v1_generated_GenAiTuningService_RebaseTunedModel_sync] diff --git a/AiPlatform/src/V1/Client/GenAiTuningServiceClient.php b/AiPlatform/src/V1/Client/GenAiTuningServiceClient.php index 7386de0b23ee..100038b5446c 100644 --- a/AiPlatform/src/V1/Client/GenAiTuningServiceClient.php +++ b/AiPlatform/src/V1/Client/GenAiTuningServiceClient.php @@ -27,6 +27,7 @@ use Google\ApiCore\ApiException; use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\GapicClientTrait; +use Google\ApiCore\OperationResponse; use Google\ApiCore\PagedListResponse; use Google\ApiCore\ResourceHelperTrait; use Google\ApiCore\RetrySettings; @@ -37,6 +38,7 @@ use Google\Cloud\AIPlatform\V1\CreateTuningJobRequest; use Google\Cloud\AIPlatform\V1\GetTuningJobRequest; use Google\Cloud\AIPlatform\V1\ListTuningJobsRequest; +use Google\Cloud\AIPlatform\V1\RebaseTunedModelRequest; use Google\Cloud\AIPlatform\V1\TuningJob; use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; @@ -46,6 +48,8 @@ use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; +use Google\LongRunning\Client\OperationsClient; +use Google\LongRunning\Operation; use GuzzleHttp\Promise\PromiseInterface; /** @@ -63,6 +67,7 @@ * @method PromiseInterface createTuningJobAsync(CreateTuningJobRequest $request, array $optionalArgs = []) * @method PromiseInterface getTuningJobAsync(GetTuningJobRequest $request, array $optionalArgs = []) * @method PromiseInterface listTuningJobsAsync(ListTuningJobsRequest $request, array $optionalArgs = []) + * @method PromiseInterface rebaseTunedModelAsync(RebaseTunedModelRequest $request, array $optionalArgs = []) * @method PromiseInterface getLocationAsync(GetLocationRequest $request, array $optionalArgs = []) * @method PromiseInterface listLocationsAsync(ListLocationsRequest $request, array $optionalArgs = []) * @method PromiseInterface getIamPolicyAsync(GetIamPolicyRequest $request, array $optionalArgs = []) @@ -96,6 +101,8 @@ final class GenAiTuningServiceClient /** The default scopes required by the service. */ public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform']; + private $operationsClient; + private static function getClientDefaults() { return [ @@ -115,6 +122,56 @@ private static function getClientDefaults() ]; } + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) + ? $this->descriptors[$methodName]['longRunning'] + : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Create the default operation client for the service. + * + * @param array $options ClientOptions for the client. + * + * @return OperationsClient + */ + private function createOperationsClient(array $options) + { + // Unset client-specific configuration options + unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']); + + if (isset($options['operationsClient'])) { + return $options['operationsClient']; + } + + return new OperationsClient($options); + } + /** * Formats a string containing the fully-qualified path to represent a context * resource. @@ -195,6 +252,25 @@ public static function modelName(string $project, string $location, string $mode ]); } + /** + * Formats a string containing the fully-qualified path to represent a pipeline_job + * resource. + * + * @param string $project + * @param string $location + * @param string $pipelineJob + * + * @return string The formatted pipeline_job resource. + */ + public static function pipelineJobName(string $project, string $location, string $pipelineJob): string + { + return self::getPathTemplate('pipelineJob')->render([ + 'project' => $project, + 'location' => $location, + 'pipeline_job' => $pipelineJob, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a * project_location_endpoint resource. @@ -266,6 +342,7 @@ public static function tuningJobName(string $project, string $location, string $ * - endpoint: projects/{project}/locations/{location}/endpoints/{endpoint} * - location: projects/{project}/locations/{location} * - model: projects/{project}/locations/{location}/models/{model} + * - pipelineJob: projects/{project}/locations/{location}/pipelineJobs/{pipeline_job} * - projectLocationEndpoint: projects/{project}/locations/{location}/endpoints/{endpoint} * - projectLocationPublisherModel: projects/{project}/locations/{location}/publishers/{publisher}/models/{model} * - tuningJob: projects/{project}/locations/{location}/tuningJobs/{tuning_job} @@ -346,6 +423,7 @@ public function __construct(array $options = []) { $clientOptions = $this->buildClientOptions($options); $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); } /** Handles execution of the async variants for each documented method. */ @@ -473,6 +551,34 @@ public function listTuningJobs(ListTuningJobsRequest $request, array $callOption return $this->startApiCall('ListTuningJobs', $request, $callOptions); } + /** + * Rebase a TunedModel. + * Creates a LongRunningOperation that takes a legacy Tuned GenAI model + * Reference and creates a TuningJob based on newly available model. + * + * The async variant is {@see GenAiTuningServiceClient::rebaseTunedModelAsync()} . + * + * @example samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php + * + * @param RebaseTunedModelRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function rebaseTunedModel(RebaseTunedModelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('RebaseTunedModel', $request, $callOptions)->wait(); + } + /** * Gets information about a location. * diff --git a/AiPlatform/src/V1/RebaseTunedModelOperationMetadata.php b/AiPlatform/src/V1/RebaseTunedModelOperationMetadata.php new file mode 100644 index 000000000000..8cc1f264727b --- /dev/null +++ b/AiPlatform/src/V1/RebaseTunedModelOperationMetadata.php @@ -0,0 +1,78 @@ +google.cloud.aiplatform.v1.RebaseTunedModelOperationMetadata + */ +class RebaseTunedModelOperationMetadata extends \Google\Protobuf\Internal\Message +{ + /** + * The common part of the operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + */ + protected $generic_metadata = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\AIPlatform\V1\GenericOperationMetadata $generic_metadata + * The common part of the operation generic information. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\GenaiTuningService::initOnce(); + parent::__construct($data); + } + + /** + * The common part of the operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + * @return \Google\Cloud\AIPlatform\V1\GenericOperationMetadata|null + */ + public function getGenericMetadata() + { + return $this->generic_metadata; + } + + public function hasGenericMetadata() + { + return isset($this->generic_metadata); + } + + public function clearGenericMetadata() + { + unset($this->generic_metadata); + } + + /** + * The common part of the operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + * @param \Google\Cloud\AIPlatform\V1\GenericOperationMetadata $var + * @return $this + */ + public function setGenericMetadata($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\GenericOperationMetadata::class); + $this->generic_metadata = $var; + + return $this; + } + +} + diff --git a/AiPlatform/src/V1/RebaseTunedModelRequest.php b/AiPlatform/src/V1/RebaseTunedModelRequest.php new file mode 100644 index 000000000000..0270af7491c9 --- /dev/null +++ b/AiPlatform/src/V1/RebaseTunedModelRequest.php @@ -0,0 +1,267 @@ +google.cloud.aiplatform.v1.RebaseTunedModelRequest + */ +class RebaseTunedModelRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the Location into which to rebase the Model. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $parent = ''; + /** + * Required. TunedModel reference to retrieve the legacy model information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TunedModelRef tuned_model_ref = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $tuned_model_ref = null; + /** + * Optional. The TuningJob to be updated. Users can use this TuningJob field + * to overwrite tuning configs. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TuningJob tuning_job = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $tuning_job = null; + /** + * Optional. The Google Cloud Storage location to write the artifacts. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GcsDestination artifact_destination = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $artifact_destination = null; + /** + * Optional. By default, bison to gemini migration will always create new + * model/endpoint, but for gemini-1.0 to gemini-1.5 migration, we default + * deploy to the same endpoint. See details in this Section. + * + * Generated from protobuf field bool deploy_to_same_endpoint = 5 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $deploy_to_same_endpoint = false; + + /** + * @param string $parent Required. The resource name of the Location into which to rebase the Model. + * Format: `projects/{project}/locations/{location}` + * Please see {@see GenAiTuningServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\AIPlatform\V1\TunedModelRef $tunedModelRef Required. TunedModel reference to retrieve the legacy model information. + * + * @return \Google\Cloud\AIPlatform\V1\RebaseTunedModelRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\AIPlatform\V1\TunedModelRef $tunedModelRef): self + { + return (new self()) + ->setParent($parent) + ->setTunedModelRef($tunedModelRef); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The resource name of the Location into which to rebase the Model. + * Format: `projects/{project}/locations/{location}` + * @type \Google\Cloud\AIPlatform\V1\TunedModelRef $tuned_model_ref + * Required. TunedModel reference to retrieve the legacy model information. + * @type \Google\Cloud\AIPlatform\V1\TuningJob $tuning_job + * Optional. The TuningJob to be updated. Users can use this TuningJob field + * to overwrite tuning configs. + * @type \Google\Cloud\AIPlatform\V1\GcsDestination $artifact_destination + * Optional. The Google Cloud Storage location to write the artifacts. + * @type bool $deploy_to_same_endpoint + * Optional. By default, bison to gemini migration will always create new + * model/endpoint, but for gemini-1.0 to gemini-1.5 migration, we default + * deploy to the same endpoint. See details in this Section. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\GenaiTuningService::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the Location into which to rebase the Model. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The resource name of the Location into which to rebase the Model. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * Required. TunedModel reference to retrieve the legacy model information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TunedModelRef tuned_model_ref = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\AIPlatform\V1\TunedModelRef|null + */ + public function getTunedModelRef() + { + return $this->tuned_model_ref; + } + + public function hasTunedModelRef() + { + return isset($this->tuned_model_ref); + } + + public function clearTunedModelRef() + { + unset($this->tuned_model_ref); + } + + /** + * Required. TunedModel reference to retrieve the legacy model information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TunedModelRef tuned_model_ref = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\AIPlatform\V1\TunedModelRef $var + * @return $this + */ + public function setTunedModelRef($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\TunedModelRef::class); + $this->tuned_model_ref = $var; + + return $this; + } + + /** + * Optional. The TuningJob to be updated. Users can use this TuningJob field + * to overwrite tuning configs. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TuningJob tuning_job = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\TuningJob|null + */ + public function getTuningJob() + { + return $this->tuning_job; + } + + public function hasTuningJob() + { + return isset($this->tuning_job); + } + + public function clearTuningJob() + { + unset($this->tuning_job); + } + + /** + * Optional. The TuningJob to be updated. Users can use this TuningJob field + * to overwrite tuning configs. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.TuningJob tuning_job = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\TuningJob $var + * @return $this + */ + public function setTuningJob($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\TuningJob::class); + $this->tuning_job = $var; + + return $this; + } + + /** + * Optional. The Google Cloud Storage location to write the artifacts. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GcsDestination artifact_destination = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\GcsDestination|null + */ + public function getArtifactDestination() + { + return $this->artifact_destination; + } + + public function hasArtifactDestination() + { + return isset($this->artifact_destination); + } + + public function clearArtifactDestination() + { + unset($this->artifact_destination); + } + + /** + * Optional. The Google Cloud Storage location to write the artifacts. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GcsDestination artifact_destination = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\GcsDestination $var + * @return $this + */ + public function setArtifactDestination($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\GcsDestination::class); + $this->artifact_destination = $var; + + return $this; + } + + /** + * Optional. By default, bison to gemini migration will always create new + * model/endpoint, but for gemini-1.0 to gemini-1.5 migration, we default + * deploy to the same endpoint. See details in this Section. + * + * Generated from protobuf field bool deploy_to_same_endpoint = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getDeployToSameEndpoint() + { + return $this->deploy_to_same_endpoint; + } + + /** + * Optional. By default, bison to gemini migration will always create new + * model/endpoint, but for gemini-1.0 to gemini-1.5 migration, we default + * deploy to the same endpoint. See details in this Section. + * + * Generated from protobuf field bool deploy_to_same_endpoint = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setDeployToSameEndpoint($var) + { + GPBUtil::checkBool($var); + $this->deploy_to_same_endpoint = $var; + + return $this; + } + +} + diff --git a/AiPlatform/src/V1/SupervisedTuningSpec.php b/AiPlatform/src/V1/SupervisedTuningSpec.php index cf73588008b6..debce9c23a3c 100644 --- a/AiPlatform/src/V1/SupervisedTuningSpec.php +++ b/AiPlatform/src/V1/SupervisedTuningSpec.php @@ -9,7 +9,7 @@ use Google\Protobuf\Internal\GPBUtil; /** - * Tuning Spec for Supervised Tuning. + * Tuning Spec for Supervised Tuning for first party models. * * Generated from protobuf message google.cloud.aiplatform.v1.SupervisedTuningSpec */ diff --git a/AiPlatform/src/V1/TunedModelRef.php b/AiPlatform/src/V1/TunedModelRef.php new file mode 100644 index 000000000000..7b9f8eaca715 --- /dev/null +++ b/AiPlatform/src/V1/TunedModelRef.php @@ -0,0 +1,147 @@ +google.cloud.aiplatform.v1.TunedModelRef + */ +class TunedModelRef extends \Google\Protobuf\Internal\Message +{ + protected $tuned_model_ref; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $tuned_model + * Support migration from model registry. + * @type string $tuning_job + * Support migration from tuning job list page, from gemini-1.0-pro-002 + * to 1.5 and above. + * @type string $pipeline_job + * Support migration from tuning job list page, from bison model to gemini + * model. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\TuningJob::initOnce(); + parent::__construct($data); + } + + /** + * Support migration from model registry. + * + * Generated from protobuf field string tuned_model = 1 [(.google.api.resource_reference) = { + * @return string + */ + public function getTunedModel() + { + return $this->readOneof(1); + } + + public function hasTunedModel() + { + return $this->hasOneof(1); + } + + /** + * Support migration from model registry. + * + * Generated from protobuf field string tuned_model = 1 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setTunedModel($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * Support migration from tuning job list page, from gemini-1.0-pro-002 + * to 1.5 and above. + * + * Generated from protobuf field string tuning_job = 2 [(.google.api.resource_reference) = { + * @return string + */ + public function getTuningJob() + { + return $this->readOneof(2); + } + + public function hasTuningJob() + { + return $this->hasOneof(2); + } + + /** + * Support migration from tuning job list page, from gemini-1.0-pro-002 + * to 1.5 and above. + * + * Generated from protobuf field string tuning_job = 2 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setTuningJob($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Support migration from tuning job list page, from bison model to gemini + * model. + * + * Generated from protobuf field string pipeline_job = 3 [(.google.api.resource_reference) = { + * @return string + */ + public function getPipelineJob() + { + return $this->readOneof(3); + } + + public function hasPipelineJob() + { + return $this->hasOneof(3); + } + + /** + * Support migration from tuning job list page, from bison model to gemini + * model. + * + * Generated from protobuf field string pipeline_job = 3 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setPipelineJob($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(3, $var); + + return $this; + } + + /** + * @return string + */ + public function getTunedModelRef() + { + return $this->whichOneof("tuned_model_ref"); + } + +} + diff --git a/AiPlatform/src/V1/gapic_metadata.json b/AiPlatform/src/V1/gapic_metadata.json index 563d20931549..7cb6d4941f23 100644 --- a/AiPlatform/src/V1/gapic_metadata.json +++ b/AiPlatform/src/V1/gapic_metadata.json @@ -751,6 +751,11 @@ "listTuningJobs" ] }, + "RebaseTunedModel": { + "methods": [ + "rebaseTunedModel" + ] + }, "GetLocation": { "methods": [ "getLocation" diff --git a/AiPlatform/src/V1/resources/gen_ai_tuning_service_client_config.json b/AiPlatform/src/V1/resources/gen_ai_tuning_service_client_config.json index ce8d374c8147..e42f4e7e0692 100644 --- a/AiPlatform/src/V1/resources/gen_ai_tuning_service_client_config.json +++ b/AiPlatform/src/V1/resources/gen_ai_tuning_service_client_config.json @@ -36,6 +36,11 @@ "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "RebaseTunedModel": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "GetLocation": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", diff --git a/AiPlatform/src/V1/resources/gen_ai_tuning_service_descriptor_config.php b/AiPlatform/src/V1/resources/gen_ai_tuning_service_descriptor_config.php index 5a2bd932cc3b..ea1261a576f4 100644 --- a/AiPlatform/src/V1/resources/gen_ai_tuning_service_descriptor_config.php +++ b/AiPlatform/src/V1/resources/gen_ai_tuning_service_descriptor_config.php @@ -23,6 +23,25 @@ return [ 'interfaces' => [ 'google.cloud.aiplatform.v1.GenAiTuningService' => [ + 'RebaseTunedModel' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\AIPlatform\V1\TuningJob', + 'metadataReturnType' => '\Google\Cloud\AIPlatform\V1\RebaseTunedModelOperationMetadata', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], 'CancelTuningJob' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Protobuf\GPBEmpty', @@ -157,6 +176,7 @@ 'endpoint' => 'projects/{project}/locations/{location}/endpoints/{endpoint}', 'location' => 'projects/{project}/locations/{location}', 'model' => 'projects/{project}/locations/{location}/models/{model}', + 'pipelineJob' => 'projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}', 'projectLocationEndpoint' => 'projects/{project}/locations/{location}/endpoints/{endpoint}', 'projectLocationPublisherModel' => 'projects/{project}/locations/{location}/publishers/{publisher}/models/{model}', 'tuningJob' => 'projects/{project}/locations/{location}/tuningJobs/{tuning_job}', diff --git a/AiPlatform/src/V1/resources/gen_ai_tuning_service_rest_client_config.php b/AiPlatform/src/V1/resources/gen_ai_tuning_service_rest_client_config.php index bcaa678393b2..4f45ce22ca84 100644 --- a/AiPlatform/src/V1/resources/gen_ai_tuning_service_rest_client_config.php +++ b/AiPlatform/src/V1/resources/gen_ai_tuning_service_rest_client_config.php @@ -69,6 +69,18 @@ ], ], ], + 'RebaseTunedModel' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{parent=projects/*/locations/*}/tuningJobs:rebaseTunedModel', + 'body' => '*', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], ], 'google.cloud.location.Locations' => [ 'GetLocation' => [ diff --git a/AiPlatform/tests/Unit/V1/Client/GenAiTuningServiceClientTest.php b/AiPlatform/tests/Unit/V1/Client/GenAiTuningServiceClientTest.php index 172464f55bc5..d7d4566492db 100644 --- a/AiPlatform/tests/Unit/V1/Client/GenAiTuningServiceClientTest.php +++ b/AiPlatform/tests/Unit/V1/Client/GenAiTuningServiceClientTest.php @@ -32,6 +32,8 @@ use Google\Cloud\AIPlatform\V1\GetTuningJobRequest; use Google\Cloud\AIPlatform\V1\ListTuningJobsRequest; use Google\Cloud\AIPlatform\V1\ListTuningJobsResponse; +use Google\Cloud\AIPlatform\V1\RebaseTunedModelRequest; +use Google\Cloud\AIPlatform\V1\TunedModelRef; use Google\Cloud\AIPlatform\V1\TuningJob; use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; @@ -42,6 +44,10 @@ use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\ListLocationsResponse; use Google\Cloud\Location\Location; +use Google\LongRunning\Client\OperationsClient; +use Google\LongRunning\GetOperationRequest; +use Google\LongRunning\Operation; +use Google\Protobuf\Any; use Google\Protobuf\GPBEmpty; use Google\Rpc\Code; use stdClass; @@ -359,6 +365,142 @@ public function listTuningJobsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function rebaseTunedModelTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/rebaseTunedModelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $baseModel = 'baseModel-480754629'; + $name = 'name3373707'; + $tunedModelDisplayName = 'tunedModelDisplayName358986993'; + $description = 'description-1724546052'; + $experiment = 'experiment-85337091'; + $expectedResponse = new TuningJob(); + $expectedResponse->setBaseModel($baseModel); + $expectedResponse->setName($name); + $expectedResponse->setTunedModelDisplayName($tunedModelDisplayName); + $expectedResponse->setDescription($description); + $expectedResponse->setExperiment($experiment); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/rebaseTunedModelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $tunedModelRef = new TunedModelRef(); + $request = (new RebaseTunedModelRequest())->setParent($formattedParent)->setTunedModelRef($tunedModelRef); + $response = $gapicClient->rebaseTunedModel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.aiplatform.v1.GenAiTuningService/RebaseTunedModel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getTunedModelRef(); + $this->assertProtobufEquals($tunedModelRef, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/rebaseTunedModelTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function rebaseTunedModelExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/rebaseTunedModelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $tunedModelRef = new TunedModelRef(); + $request = (new RebaseTunedModelRequest())->setParent($formattedParent)->setTunedModelRef($tunedModelRef); + $response = $gapicClient->rebaseTunedModel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/rebaseTunedModelTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + /** @test */ public function getLocationTest() {