Skip to content

Commit 4c04abe

Browse files
vertex-mg-botcopybara-github
authored andcommitted
Formatting and refactoring
PiperOrigin-RevId: 766506385
1 parent 67a2f84 commit 4c04abe

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

notebooks/community/model_garden/model_garden_pytorch_sam.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
"! pip3 install --upgrade --quiet 'google-cloud-aiplatform==1.93.1'\n",
117117
"! git clone https://github.com/GoogleCloudPlatform/vertex-ai-samples.git\n",
118118
"\n",
119+
"! pip install --quiet pycocotools\n",
120+
"\n",
119121
"import importlib\n",
120122
"import os\n",
121123
"\n",
@@ -133,7 +135,6 @@
133135
")\n",
134136
"\n",
135137
"models, endpoints = {}, {}\n",
136-
"LABEL = \"sam_model\"\n",
137138
"\n",
138139
"\n",
139140
"# Get the default cloud project id.\n",
@@ -198,7 +199,8 @@
198199
" task, display_name, model_id, machine_type, accelerator_type, accelerator_count\n",
199200
"):\n",
200201
" endpoint = aiplatform.Endpoint.create(\n",
201-
" display_name=common_util.get_job_name_with_datetime(prefix=task)\n",
202+
" display_name=common_util.get_job_name_with_datetime(prefix=task),\n",
203+
" dedicated_endpoint_enabled=use_dedicated_endpoint,\n",
202204
" )\n",
203205
" serving_env = {\n",
204206
" \"MODEL_ID\": model_id,\n",
@@ -239,6 +241,7 @@
239241
"source": [
240242
"# @title [Option 1] Deploy with Model Garden SDK\n",
241243
"\n",
244+
"LABEL = \"sdk-deploy\"\n",
242245
"# @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",
243246
"from vertexai.preview import model_garden\n",
244247
"\n",
@@ -277,14 +280,18 @@
277280
" is_for_training=False,\n",
278281
")\n",
279282
"\n",
280-
"models[\"sam_model\"], endpoints[\"sam_endpoint\"] = deploy_model(\n",
283+
"LABEL = \"custom-deploy\"\n",
284+
"models[LABEL], endpoints[LABEL] = deploy_model(\n",
281285
" task=task,\n",
282286
" display_name=common_util.get_job_name_with_datetime(prefix=task),\n",
283287
" model_id=\"facebook/sam-vit-large\",\n",
284288
" machine_type=machine_type,\n",
285289
" accelerator_type=accelerator_type,\n",
286290
" accelerator_count=1,\n",
287-
")"
291+
")\n",
292+
"\n",
293+
"model = models[LABEL]\n",
294+
"endpoint = endpoints[LABEL]"
288295
]
289296
},
290297
{
@@ -347,7 +354,9 @@
347354
" {\"image\": common_util.image_to_base64(image2)},\n",
348355
"]\n",
349356
"\n",
350-
"preds = endpoints[\"sam_endpoint\"].predict(instances=instances).predictions\n",
357+
"preds = endpoint.predict(\n",
358+
" instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n",
359+
").predictions\n",
351360
"show_predictions(preds)"
352361
]
353362
},

0 commit comments

Comments
 (0)