diff --git a/generative_ai/model_tuning/supervised_advanced_example.py b/generative_ai/model_tuning/supervised_advanced_example.py deleted file mode 100644 index 9e0a7ef11c..0000000000 --- a/generative_ai/model_tuning/supervised_advanced_example.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -from vertexai.tuning import sft - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def gemini_tuning_advanced() -> sft.SupervisedTuningJob: - # [START generativeaionvertexai_tuning_advanced] - - import time - - import vertexai - from vertexai.tuning import sft - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - # Initialize Vertex AI with your service account for BYOSA (Bring Your Own Service Account). - # Uncomment the following and replace "your-service-account" - # vertexai.init(service_account="your-service-account") - - # Initialize Vertex AI with your CMEK (Customer-Managed Encryption Key). - # Un-comment the following line and replace "your-kms-key" - # vertexai.init(encryption_spec_key_name="your-kms-key") - - sft_tuning_job = sft.train( - source_model="gemini-2.0-flash-001", - # 1.5 and 2.0 models use the same JSONL format - train_dataset="gs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_train_data.jsonl", - # The following parameters are optional - validation_dataset="gs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_validation_data.jsonl", - tuned_model_display_name="tuned_gemini_2_0_flash", - # Advanced use only below. It is recommended to use auto-selection and leave them unset - # epochs=4, - # adapter_size=4, - # learning_rate_multiplier=1.0, - ) - - # Polling for job completion - while not sft_tuning_job.has_ended: - time.sleep(60) - sft_tuning_job.refresh() - - print(sft_tuning_job.tuned_model_name) - print(sft_tuning_job.tuned_model_endpoint_name) - print(sft_tuning_job.experiment) - # Example response: - # projects/123456789012/locations/us-central1/models/1234567890@1 - # projects/123456789012/locations/us-central1/endpoints/123456789012345 - # - - # [END generativeaionvertexai_tuning_advanced] - return sft_tuning_job - - -if __name__ == "__main__": - gemini_tuning_advanced() diff --git a/generative_ai/model_tuning/supervised_example.py b/generative_ai/model_tuning/supervised_example.py deleted file mode 100644 index f537a51bdb..0000000000 --- a/generative_ai/model_tuning/supervised_example.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -from vertexai.tuning import sft - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def gemini_tuning_basic() -> sft.SupervisedTuningJob: - # [START generativeaionvertexai_tuning_basic] - - import time - - import vertexai - from vertexai.tuning import sft - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - sft_tuning_job = sft.train( - source_model="gemini-2.0-flash-001", - # 1.5 and 2.0 models use the same JSONL format - train_dataset="gs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_train_data.jsonl", - ) - - # Polling for job completion - while not sft_tuning_job.has_ended: - time.sleep(60) - sft_tuning_job.refresh() - - print(sft_tuning_job.tuned_model_name) - print(sft_tuning_job.tuned_model_endpoint_name) - print(sft_tuning_job.experiment) - # Example response: - # projects/123456789012/locations/us-central1/models/1234567890@1 - # projects/123456789012/locations/us-central1/endpoints/123456789012345 - # - - # [END generativeaionvertexai_tuning_basic] - return sft_tuning_job - - -if __name__ == "__main__": - gemini_tuning_basic() diff --git a/generative_ai/model_tuning/supervised_get_example.py b/generative_ai/model_tuning/supervised_get_example.py deleted file mode 100644 index b1908c2bee..0000000000 --- a/generative_ai/model_tuning/supervised_get_example.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -from vertexai.tuning import sft - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -LOCATION = "us-central1" - - -def get_tuning_job() -> sft.SupervisedTuningJob: - # [START generativeaionvertexai_get_tuning_job] - import vertexai - from vertexai.tuning import sft - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # LOCATION = "us-central1" - vertexai.init(project=PROJECT_ID, location=LOCATION) - - tuning_job_id = "4982013113894174720" - response = sft.SupervisedTuningJob( - f"projects/{PROJECT_ID}/locations/{LOCATION}/tuningJobs/{tuning_job_id}" - ) - - print(response) - # Example response: - # - # resource name: projects/1234567890/locations/us-central1/tuningJobs/4982013113894174720 - - # [END generativeaionvertexai_get_tuning_job] - return response - - -if __name__ == "__main__": - get_tuning_job() diff --git a/generative_ai/model_tuning/supervised_list_example.py b/generative_ai/model_tuning/supervised_list_example.py deleted file mode 100644 index 9c882fb282..0000000000 --- a/generative_ai/model_tuning/supervised_list_example.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -from typing import List - -from vertexai.tuning import sft - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def list_tuning_jobs() -> List[sft.SupervisedTuningJob]: - # [START generativeaionvertexai_list_tuning_jobs] - import vertexai - from vertexai.tuning import sft - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - responses = sft.SupervisedTuningJob.list() - - for response in responses: - print(response) - # Example response: - # - # resource name: projects/12345678/locations/us-central1/tuningJobs/123456789012345 - - # [END generativeaionvertexai_list_tuning_jobs] - return responses - - -if __name__ == "__main__": - list_tuning_jobs()