chore: revisions to Stable Diffusion and TorchServe nb

This commit is contained in:
Eric Schmidt
2023-02-15 02:32:02 +00:00
parent 909f771bfd
commit 36df462615
@@ -90,7 +90,7 @@
"\n",
"+ Create a `torchserve` handler for responding to prediction requests.\n",
"+ Upload a Stable Diffusion 1.5 model on a prebuilt PyTorch container in Vertex AI.\n",
"+ Deploy a custom model to a Vertex AI Endpoint.\n",
"+ Deploy a model to a Vertex AI Endpoint.\n",
"+ Send requests to the endpoint and parse the responses using Vertex AI Prediction service."
]
},
@@ -100,7 +100,7 @@
"id": "c6deba5a8557"
},
"source": [
"### Dataset\n",
"### Model\n",
"\n",
"This notebook uses a collection of model artifacts fine-tuned to generate images of a small dog. These are the same images used in the original [DreamBooth paper](https://dreambooth.github.io/)."
]
@@ -118,7 +118,7 @@
"* Vertex AI models\n",
"* Vertex AI endpoints\n",
"* Vertex AI prediction\n",
"* Google Cloud Storage\n",
"* Cloud Storage\n",
"* (Optionally) Vertex AI Workbench\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
@@ -420,7 +420,6 @@
"outputs": [],
"source": [
"import base64\n",
"import gc\n",
"import math\n",
"\n",
"import torch\n",
@@ -437,9 +436,9 @@
"id": "697566b5f660"
},
"source": [
"## View model inferences\n",
"## Optional: View model inferences\n",
"\n",
"Before uploading the model to Vertex AI, you can review the expected output from the model. The model used in this notebook is available for your use and can be downloaded from Google Cloud Storage. This download may take a few minutes to complete."
"Before uploading the model to Vertex AI, you can review the expected output from the model. The model used in this notebook is available for your use and can be downloaded from Cloud Storage. This download may take a few minutes to complete."
]
},
{
@@ -574,31 +573,6 @@
"grid"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cf8d545a135b"
},
"source": [
"### Re-training the model\n",
"\n",
"If you aren't satisfied with the inference outputs from the model, you can retrain it. Before you can do that, you might need to release the GPU memory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5621b7a927f8"
},
"outputs": [],
"source": [
"# Run this cell _only_ if you want to release the GPU memory.\n",
"pipe = None\n",
"gc.collect()\n",
"torch.cuda.empty_cache()"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -607,10 +581,10 @@
"source": [
"## Deploy the model to Vertex AI\n",
"\n",
"You can host your Stable Diffusion 2.0 model on a Vertex AI endpoint where you can get inferences from it online. Uploading your model is a four step process: \n",
"You can host your Stable Diffusion 1.5 model on a Vertex AI endpoint where you can get inferences from it online. Uploading your model is a four step process: \n",
"\n",
"1. Create a custom TorchServe handler.\n",
"1. Upload the model artifacts onto Google Cloud Storage.\n",
"1. Upload the model artifacts onto Cloud Storage.\n",
"2. Create a Vertex AI model with the model artifacts and a prebuilt PyTorch container image.\n",
"3. Deploy the Vertex AI model onto an endpoint."
]
@@ -740,9 +714,9 @@
"id": "ffab030f4bc8"
},
"source": [
"### Upload the model artifacts to Google Cloud Storage\n",
"### Upload the model artifacts to Cloud Storage\n",
"\n",
"Create a new folder in your Google Cloud Storage bucket to hold the model artifacts"
"Create a new folder in your Cloud Storage bucket to hold the model artifacts"
]
},
{
@@ -838,6 +812,16 @@
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_NAME)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "FAPoU8Sm5E6e"
},
"source": [
"<div style=\"background:#e3effe; padding:5px; color:#0000aa\">\n",
"<strong>Note:</strong> The next cell fails if you haven't <a href=\"https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com\"><u>enabled the Vertex API</u></a>.</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -907,7 +891,7 @@
"id": "c9fc560df0a9"
},
"source": [
"The previous cell, which deploys your model to the nedpoint, can take a while to complete. If the previous cell times out before returning, your endpoint might still be successfully deployed ot an end point. Check the [Cloud Console](https://console.cloud.google.com/vertex-ai/endpoints) to verify the results.\n",
"The previous cell, which deploys your model to the endpoint, can take a while to complete. If the previous cell times out before returning, your endpoint might still be successfully deployed to an endpoint. Check the [Cloud Console](https://console.cloud.google.com/vertex-ai/endpoints) to verify the results.\n",
"\n",
"You can also extend the time to wait for deployment by changing the `deploy_request_timeout` argument passed to `model.deploy()`."
]
@@ -920,7 +904,7 @@
"source": [
"## Get online predictions\n",
"\n",
"Finally, with your Stable Diffusion 2.0 model deployed to a Vertex AI endpoint, you can now get online predictions from it. Using the Vertex AI SDK, you only need a few lines of code to get an inference."
"Finally, with your Stable Diffusion 1.5 model deployed to a Vertex AI endpoint, you can now get online predictions from it. Using the Vertex AI SDK, you only need a few lines of code to get an inference."
]
},
{