Skip to content

Commit 5ba56df

Browse files
vertex-mg-botcopybara-github
authored andcommitted
Formatting and refactoring
PiperOrigin-RevId: 766516226
1 parent 4c04abe commit 5ba56df

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

notebooks/community/model_garden/model_garden_pytorch_biomedclip.ipynb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
" \"vertex-ai-samples.community-content.vertex_model_garden.model_oss.notebook_util.common_util\"\n",
140140
")\n",
141141
"\n",
142-
"LABEL = \"biomedclip_serve\"\n",
143142
"models, endpoints = {}, {}\n",
144143
"\n",
145144
"# Get the default cloud project id.\n",
@@ -216,6 +215,7 @@
216215
"source": [
217216
"# @title [Option 1] Deploy with Model Garden SDK\n",
218217
"\n",
218+
"LABEL = \"sdk-deploy\"\n",
219219
"# @markdown Deploy with Gen AI model-centric SDK. This section uploads the prebuilt model to Model Registry and deploys it to a Vertex AI Endpoint. It takes 15 minutes to 1 hour to finish depending on the size of the model. See [use open models with Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/open-models/use-open-models) for documentation on other use cases.\n",
220220
"from vertexai.preview import model_garden\n",
221221
"\n",
@@ -258,9 +258,13 @@
258258
" machine_type: str,\n",
259259
" accelerator_type: str,\n",
260260
" accelerator_count: int,\n",
261+
" use_dedicated_endpoint: bool = False,\n",
261262
") -> Tuple[aiplatform.Model, aiplatform.Endpoint]:\n",
262263
" \"\"\"Deploys trained models into Vertex AI.\"\"\"\n",
263-
" endpoint = aiplatform.Endpoint.create(display_name=f\"{model_name}-endpoint\")\n",
264+
" endpoint = aiplatform.Endpoint.create(\n",
265+
" display_name=f\"{model_name}-endpoint\",\n",
266+
" dedicated_endpoint_enabled=use_dedicated_endpoint,\n",
267+
" )\n",
264268
" serving_env = {\n",
265269
" \"MODEL\": model_id,\n",
266270
" \"TASK\": task,\n",
@@ -293,6 +297,8 @@
293297
" return model, endpoint\n",
294298
"\n",
295299
"\n",
300+
"LABEL = \"open-clip-deploy\"\n",
301+
"\n",
296302
"models[LABEL], endpoints[LABEL] = deploy_model(\n",
297303
" model_name=common_util.get_job_name_with_datetime(prefix=\"biomedclip-serve\"),\n",
298304
" model_id=model_id,\n",
@@ -301,7 +307,11 @@
301307
" machine_type=machine_type,\n",
302308
" accelerator_type=accelerator_type,\n",
303309
" accelerator_count=1,\n",
304-
")"
310+
" use_dedicated_endpoint=use_dedicated_endpoint,\n",
311+
")\n",
312+
"\n",
313+
"model = models[LABEL]\n",
314+
"endpoint = endpoints[LABEL]"
305315
]
306316
},
307317
{
@@ -364,7 +374,9 @@
364374
" {\"text\": \"This is a photo of hematoxylin and eosin histopathology\"},\n",
365375
" {\"text\": \"This is a photo of pie chart\"},\n",
366376
"]\n",
367-
"response = endpoints[LABEL].predict(instances=instances)\n",
377+
"response = endpoint.predict(\n",
378+
" instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n",
379+
")\n",
368380
"\n",
369381
"print(response.predictions)\n",
370382
"\n",

0 commit comments

Comments
 (0)