|
178 | 178 | "# The machine and accelerator specs for model deployment.\n", |
179 | 179 | "accelerator_type = \"NVIDIA_L4\"\n", |
180 | 180 | "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\"}" |
182 | 185 | ] |
183 | 186 | }, |
184 | 187 | { |
|
200 | 203 | " machine_type=machine_type,\n", |
201 | 204 | " accelerator_type=accelerator_type,\n", |
202 | 205 | " accelerator_count=accelerator_count,\n", |
| 206 | + " use_dedicated_endpoint=use_dedicated_endpoint,\n", |
203 | 207 | " accept_eula=True, # Accept the End User License Agreement (EULA) on the model card before deploy. Otherwise, the deployment will be forbidden.\n", |
204 | 208 | ")" |
205 | 209 | ] |
|
226 | 230 | " machine_type: str,\n", |
227 | 231 | " accelerator_type: str,\n", |
228 | 232 | " accelerator_count: int,\n", |
| 233 | + " use_dedicated_endpoint: bool = False,\n", |
229 | 234 | "):\n", |
230 | 235 | " 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", |
232 | 240 | " serving_env = {\n", |
233 | 241 | " \"MODEL_ID\": model_id,\n", |
234 | 242 | " \"TASK\": task,\n", |
|
272 | 280 | " machine_type=machine_type,\n", |
273 | 281 | " accelerator_type=accelerator_type,\n", |
274 | 282 | " accelerator_count=accelerator_count,\n", |
| 283 | + " use_dedicated_endpoint=use_dedicated_endpoint,\n", |
275 | 284 | ")" |
276 | 285 | ] |
277 | 286 | }, |
|
302 | 311 | " \"num_inference_steps\": num_inference_steps,\n", |
303 | 312 | " },\n", |
304 | 313 | "]\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", |
306 | 317 | "images = [common_util.base64_to_image(image) for image in response.predictions]\n", |
307 | 318 | "common_util.image_grid([init_image, images[0]], rows=1, cols=2)" |
308 | 319 | ] |
|
0 commit comments