From fd77968adb0ee3fb91413477bd33c2e7bc47960b Mon Sep 17 00:00:00 2001
From: Ivan Nardini <88703814+inardini@users.noreply.github.com>
Date: Tue, 8 Oct 2024 18:05:52 +0200
Subject: [PATCH] fix: Libraries import and quota banner (#1221)
# Description
A quick fix for libraries import and quota banner to prevent quota
error.
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make
sure it goes smoothly:
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/CONTRIBUTING.md).
- [x] You are listed as the author in your notebook or README file.
- [x] Your account is listed in
[`CODEOWNERS`](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/.github/CODEOWNERS)
for the file(s).
- [x] Make your Pull Request title in the
specification.
- [x] Ensure the tests and linter pass (Run `nox -s format` from the
repository root to format).
- [x] Appropriate docs were updated (if necessary)
---------
Co-authored-by: Owl Bot
---
.../vertex_ai_prompt_optimizer_sdk.ipynb | 31 ++++++++++---------
...i_prompt_optimizer_sdk_custom_metric.ipynb | 13 ++++++--
2 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb
index 762ec120c5..f1bd611ed3 100644
--- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb
+++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb
@@ -361,7 +361,9 @@
"- `Storage Object Admin` to read and write to your GCS bucket.\n",
"- `Artifact Registry Reader` to download the pipeline template from Artifact Registry.\n",
"\n",
- "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to know how to grant those permissions to a single service account.\n"
+ "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to know how to grant those permissions to a single service account. \n",
+ "\n",
+ "**Important**: If you run following commands using Vertex AI Workbench, please directly run in the terminal. "
]
},
{
@@ -383,17 +385,12 @@
},
"outputs": [],
"source": [
- "! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n",
- " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n",
- " --role=roles/aiplatform.user\n",
- "\n",
- "! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n",
- " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n",
- " --role=roles/storage.objectAdmin\n",
- "\n",
- "! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n",
- " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n",
- " --role=roles/artifactregistry.reader"
+ "for role in ['aiplatform.user', 'storage.objectAdmin', 'artifactregistry.reader']:\n",
+ " \n",
+ " ! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n",
+ " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n",
+ " --role=roles/{role} \\ \n",
+ " --condition=None"
]
},
{
@@ -480,7 +477,7 @@
"\n",
"from google.cloud import aiplatform\n",
"import pandas as pd\n",
- "from utils.helpers import (\n",
+ "from tutorial.utils.helpers import (\n",
" async_generate,\n",
" display_eval_report,\n",
" evaluate_task,\n",
@@ -908,7 +905,11 @@
"source": [
"#### Run the automatic prompt optimization job\n",
"\n",
- "Now you are ready to run your first Vertex AI Prompt Optimizer (Preview) job using the Vertex AI SDK for Python.\n"
+ "Now you are ready to run your first Vertex AI Prompt Optimizer (Preview) job using the Vertex AI SDK for Python.\n",
+ "\n",
+ "**Important:** Be sure you have provisioned enough queries per minute (QPM) quota and the recommended QPM for each model. If you configure the Vertex AI prompt optimizer with a QPM that is higher than the QPM than you have access to, the job will fail. \n",
+ "\n",
+ "[Check out](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer#before-you-begin) the documentation to know more. \n"
]
},
{
@@ -937,7 +938,7 @@
" worker_pool_specs=WORKER_POOL_SPECS,\n",
")\n",
"\n",
- "custom_job.run()"
+ "custom_job.run(service_account=SERVICE_ACCOUNT)"
]
},
{
diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb
index fa8b39fca6..3fbdbf2bac 100644
--- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb
+++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb
@@ -372,7 +372,9 @@
"- `Artifact Registry Reader` to download the pipeline template from Artifact Registry.\n",
"- `Cloud Run Developer` to deploy function on Cloud Run.\n",
"\n",
- "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to know how to grant those permissions to a single service account.\n"
+ "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to know how to grant those permissions to a single service account.\n",
+ "\n",
+ "**Important**: If you run following commands using Vertex AI Workbench, please directly run in the terminal. \n"
]
},
{
@@ -398,7 +400,8 @@
" \n",
" ! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n",
" --member=serviceAccount:{SERVICE_ACCOUNT} \\\n",
- " --role=roles/{role}"
+ " --role=roles/{role} \\ \n",
+ " --condition=None"
]
},
{
@@ -1146,7 +1149,11 @@
"source": [
"#### Run the automatic prompt optimization job\n",
"\n",
- "Now you are ready to run your first Vertex AI Prompt Optimizer (Preview) job using the Vertex AI SDK for Python.\n"
+ "Now you are ready to run your first Vertex AI Prompt Optimizer (Preview) job using the Vertex AI SDK for Python.\n",
+ "\n",
+ "**Important:** Be sure you have provisioned enough queries per minute (QPM) quota and the recommended QPM for each model. If you configure the Vertex AI prompt optimizer with a QPM that is higher than the QPM than you have access to, the job will fail. \n",
+ "\n",
+ "[Check out](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer#before-you-begin) the documentation to know more. "
]
},
{