Enable the use of dedicated Endpoints in instructpix2pix notebook

PiperOrigin-RevId: 751641417
This commit is contained in:
Vertex MG Team
2025-04-25 19:45:08 -07:00
committed by Copybara-Service
parent f4b1b277cf
commit feea47a206
@@ -178,7 +178,10 @@
"# The machine and accelerator specs for model deployment.\n",
"accelerator_type = \"NVIDIA_L4\"\n",
"machine_type = \"g2-standard-12\"\n",
"accelerator_count = 1"
"accelerator_count = 1\n",
"\n",
"# @markdown Set use_dedicated_endpoint to False if you don't want to use [dedicated endpoint](https://cloud.google.com/vertex-ai/docs/general/deployment#create-dedicated-endpoint). Note that [dedicated endpoint does not support VPC Service Controls](https://cloud.google.com/vertex-ai/docs/predictions/choose-endpoint-type), uncheck the box if you are using VPC-SC.\n",
"use_dedicated_endpoint = True # @param {type:\"boolean\"}"
]
},
{
@@ -200,6 +203,7 @@
" machine_type=machine_type,\n",
" accelerator_type=accelerator_type,\n",
" accelerator_count=accelerator_count,\n",
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
" accept_eula=True, # Accept the End User License Agreement (EULA) on the model card before deploy. Otherwise, the deployment will be forbidden.\n",
")"
]
@@ -226,9 +230,13 @@
" machine_type: str,\n",
" accelerator_type: str,\n",
" accelerator_count: int,\n",
" use_dedicated_endpoint: bool = False,\n",
"):\n",
" model_name = \"instruct-pix2pix\"\n",
" endpoint = aiplatform.Endpoint.create(display_name=f\"{model_name}-endpoint\")\n",
" endpoint = aiplatform.Endpoint.create(\n",
" display_name=f\"{model_name}-endpoint\",\n",
" dedicated_endpoint_enabled=use_dedicated_endpoint,\n",
" )\n",
" serving_env = {\n",
" \"MODEL_ID\": model_id,\n",
" \"TASK\": task,\n",
@@ -272,6 +280,7 @@
" machine_type=machine_type,\n",
" accelerator_type=accelerator_type,\n",
" accelerator_count=accelerator_count,\n",
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
")"
]
},
@@ -302,7 +311,9 @@
" \"num_inference_steps\": num_inference_steps,\n",
" },\n",
"]\n",
"response = endpoints[LABEL].predict(instances=instances)\n",
"response = endpoints[LABEL].predict(\n",
" instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n",
")\n",
"images = [common_util.base64_to_image(image) for image in response.predictions]\n",
"common_util.image_grid([init_image, images[0]], rows=1, cols=2)"
]