Skip to content

Commit 7d4fb0f

Browse files
vertex-mg-botcopybara-github
authored andcommitted
Formatting and refactoring
PiperOrigin-RevId: 767152796
1 parent a6e69a4 commit 7d4fb0f

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

notebooks/community/model_garden/model_garden_pytorch_owlvit.ipynb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
"\n",
150150
"models, endpoints = {}, {}\n",
151151
"\n",
152+
"# @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",
153+
"use_dedicated_endpoint = True # @param {type:\"boolean\"}\n",
154+
"\n",
152155
"# @markdown Click \"Show Code\" to see more details."
153156
]
154157
},
@@ -185,9 +188,19 @@
185188
"ACCELERATOR_COUNT = 1\n",
186189
"\n",
187190
"\n",
188-
"def deploy_model(model_id, task, accelerator_type, machine_type, accelerator_count):\n",
191+
"def deploy_model(\n",
192+
" model_id: str,\n",
193+
" task: str,\n",
194+
" machine_type: str = \"n1-standard-8\",\n",
195+
" accelerator_type: str = \"NVIDIA_TESLA_T4\",\n",
196+
" accelerator_count: int = 1,\n",
197+
" use_dedicated_endpoint: bool = False,\n",
198+
"):\n",
189199
" model_name = \"owl-vit\"\n",
190-
" endpoint = aiplatform.Endpoint.create(display_name=f\"{model_name}-endpoint\")\n",
200+
" endpoint = aiplatform.Endpoint.create(\n",
201+
" display_name=f\"{model_name}-endpoint\",\n",
202+
" dedicated_endpoint_enabled=use_dedicated_endpoint,\n",
203+
" )\n",
191204
" serving_env = {\n",
192205
" \"MODEL_ID\": model_id,\n",
193206
" \"TASK\": task,\n",
@@ -225,14 +238,19 @@
225238
")\n",
226239
"\n",
227240
"\n",
228-
"models[\"model\"], endpoints[\"endpoint\"] = deploy_model(\n",
241+
"LABEL = \"owl-vit\"\n",
242+
"models[LABEL], endpoints[LABEL] = deploy_model(\n",
229243
" model_id=\"google/owlvit-base-patch32\",\n",
230244
" task=\"zero-shot-object-detection\",\n",
231-
" accelerator_type=ACCELERATOR_TYPE,\n",
232245
" machine_type=MACHINE_TYPE,\n",
246+
" accelerator_type=ACCELERATOR_TYPE,\n",
233247
" accelerator_count=ACCELERATOR_COUNT,\n",
248+
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
234249
")\n",
235250
"\n",
251+
"endpoint = endpoints[LABEL]\n",
252+
"model = models[LABEL]\n",
253+
"\n",
236254
"# @markdown Click \"Show Code\" to see more details."
237255
]
238256
},
@@ -266,7 +284,9 @@
266284
"instances = [\n",
267285
" {\"image\": common_util.image_to_base64(image), \"text\": text},\n",
268286
"]\n",
269-
"preds = endpoints[\"endpoint\"].predict(instances=instances).predictions\n",
287+
"preds = endpoint.predict(\n",
288+
" instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n",
289+
").predictions\n",
270290
"\n",
271291
"\n",
272292
"def draw_image_with_boxes(image, boxes):\n",

0 commit comments

Comments
 (0)