|
116 | 116 | "! pip3 install --upgrade --quiet 'google-cloud-aiplatform==1.93.1'\n", |
117 | 117 | "! git clone https://github.com/GoogleCloudPlatform/vertex-ai-samples.git\n", |
118 | 118 | "\n", |
| 119 | + "! pip install --quiet pycocotools\n", |
| 120 | + "\n", |
119 | 121 | "import importlib\n", |
120 | 122 | "import os\n", |
121 | 123 | "\n", |
|
133 | 135 | ")\n", |
134 | 136 | "\n", |
135 | 137 | "models, endpoints = {}, {}\n", |
136 | | - "LABEL = \"sam_model\"\n", |
137 | 138 | "\n", |
138 | 139 | "\n", |
139 | 140 | "# Get the default cloud project id.\n", |
|
198 | 199 | " task, display_name, model_id, machine_type, accelerator_type, accelerator_count\n", |
199 | 200 | "):\n", |
200 | 201 | " 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", |
202 | 204 | " )\n", |
203 | 205 | " serving_env = {\n", |
204 | 206 | " \"MODEL_ID\": model_id,\n", |
|
239 | 241 | "source": [ |
240 | 242 | "# @title [Option 1] Deploy with Model Garden SDK\n", |
241 | 243 | "\n", |
| 244 | + "LABEL = \"sdk-deploy\"\n", |
242 | 245 | "# @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", |
243 | 246 | "from vertexai.preview import model_garden\n", |
244 | 247 | "\n", |
|
277 | 280 | " is_for_training=False,\n", |
278 | 281 | ")\n", |
279 | 282 | "\n", |
280 | | - "models[\"sam_model\"], endpoints[\"sam_endpoint\"] = deploy_model(\n", |
| 283 | + "LABEL = \"custom-deploy\"\n", |
| 284 | + "models[LABEL], endpoints[LABEL] = deploy_model(\n", |
281 | 285 | " task=task,\n", |
282 | 286 | " display_name=common_util.get_job_name_with_datetime(prefix=task),\n", |
283 | 287 | " model_id=\"facebook/sam-vit-large\",\n", |
284 | 288 | " machine_type=machine_type,\n", |
285 | 289 | " accelerator_type=accelerator_type,\n", |
286 | 290 | " accelerator_count=1,\n", |
287 | | - ")" |
| 291 | + ")\n", |
| 292 | + "\n", |
| 293 | + "model = models[LABEL]\n", |
| 294 | + "endpoint = endpoints[LABEL]" |
288 | 295 | ] |
289 | 296 | }, |
290 | 297 | { |
|
347 | 354 | " {\"image\": common_util.image_to_base64(image2)},\n", |
348 | 355 | "]\n", |
349 | 356 | "\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", |
351 | 360 | "show_predictions(preds)" |
352 | 361 | ] |
353 | 362 | }, |
|
0 commit comments