Skip to content

Commit feea47a

Browse files
vertex-mg-botcopybara-github
authored andcommitted
Enable the use of dedicated Endpoints in instructpix2pix notebook
PiperOrigin-RevId: 751641417
1 parent f4b1b27 commit feea47a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

notebooks/community/model_garden/model_garden_pytorch_instructpix2pix.ipynb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@
178178
"# The machine and accelerator specs for model deployment.\n",
179179
"accelerator_type = \"NVIDIA_L4\"\n",
180180
"machine_type = \"g2-standard-12\"\n",
181-
"accelerator_count = 1"
181+
"accelerator_count = 1\n",
182+
"\n",
183+
"# @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",
184+
"use_dedicated_endpoint = True # @param {type:\"boolean\"}"
182185
]
183186
},
184187
{
@@ -200,6 +203,7 @@
200203
" machine_type=machine_type,\n",
201204
" accelerator_type=accelerator_type,\n",
202205
" accelerator_count=accelerator_count,\n",
206+
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
203207
" accept_eula=True, # Accept the End User License Agreement (EULA) on the model card before deploy. Otherwise, the deployment will be forbidden.\n",
204208
")"
205209
]
@@ -226,9 +230,13 @@
226230
" machine_type: str,\n",
227231
" accelerator_type: str,\n",
228232
" accelerator_count: int,\n",
233+
" use_dedicated_endpoint: bool = False,\n",
229234
"):\n",
230235
" model_name = \"instruct-pix2pix\"\n",
231-
" endpoint = aiplatform.Endpoint.create(display_name=f\"{model_name}-endpoint\")\n",
236+
" endpoint = aiplatform.Endpoint.create(\n",
237+
" display_name=f\"{model_name}-endpoint\",\n",
238+
" dedicated_endpoint_enabled=use_dedicated_endpoint,\n",
239+
" )\n",
232240
" serving_env = {\n",
233241
" \"MODEL_ID\": model_id,\n",
234242
" \"TASK\": task,\n",
@@ -272,6 +280,7 @@
272280
" machine_type=machine_type,\n",
273281
" accelerator_type=accelerator_type,\n",
274282
" accelerator_count=accelerator_count,\n",
283+
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
275284
")"
276285
]
277286
},
@@ -302,7 +311,9 @@
302311
" \"num_inference_steps\": num_inference_steps,\n",
303312
" },\n",
304313
"]\n",
305-
"response = endpoints[LABEL].predict(instances=instances)\n",
314+
"response = endpoints[LABEL].predict(\n",
315+
" instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n",
316+
")\n",
306317
"images = [common_util.base64_to_image(image) for image in response.predictions]\n",
307318
"common_util.image_grid([init_image, images[0]], rows=1, cols=2)"
308319
]

0 commit comments

Comments
 (0)