Foundational models are trained on extensive unlabeled data and used for downstream generative AI tasks, such as text, images, and music generation. They are increasingly popular as businesses explore their potential to create new products and services. You can use foundational models for use cases like image generation. Diffusion models are generative models that have gained popularity over the past years because of the high-quality images they can generate. Stable Diffusion is a latent text-to-image diffusion model that researchers at CompVis, Stability AI, and LAION have developed.
Deploying large models, like Stable Diffusion, can be challenging and time-consuming. In this blog, we will show how you can streamline the deployment of a PyTorch Stable Diffusion model by leveraging Vertex AI. PyTorch is the framework used by Stability AI onStable Diffusion v1.5. Vertex AI is a fully-managed machine learning platform with tools and infrastructure designed to help ML practitioners accelerate and scale ML in production with the benefit of open-source frameworks like PyTorch. In four steps you can deploy a PyTorch Stable Diffusion model (v1.5).
Deploying your Stable Diffusion model on a Vertex AI Endpoint can be done in four steps:
Create a custom TorchServe handler.
Upload model artifacts to Google Cloud Storage (GCS).
Create a Vertex AI model with the model artifacts and a prebuilt PyTorch containerimage.
Deploy the Vertex AI model onto an endpoint.
Let’s have a look at each step in more detail. You can follow and implement the steps using the Notebook example.
TorchServe is an easy and flexible tool for serving PyTorch models. The model deployed to Vertex AI uses TorchServe to handle requests and return responses from the model. You must create a custom TorchServe handler to include in the model artifacts uploaded to Vertex AI. Include the handler file in the directory with the other model artifacts, like this: model_artifacts/handler.py
.
After creating the handler file, you must package the handler as a model archiver (MAR) file. The output file must be named model.mar
.
The next step is uploading model artifacts to GCS, like the model file or handler. The advantage of storing your artifacts on GCS is that you can track the artifacts in a central bucket.
Once you’ve uploaded the model artifacts into a GCS bucket, you can upload your PyTorch model to Vertex AI Model Registry. From the Vertex AI Model Registry, you have an overview of your models so you can better organize, track, and train new versions. For this you can use the Vertex AI SDK and our pre-built PyTorch container.
Once the model has been uploaded to Vertex AI Model Registry you can then take it and deploy it to an Vertex AI Endpoint. For this you can use the Console or the Vertex AI SDK. In this example you will deploy the model on a NVIDIA Tesla P100 GPU and n1-standard-8 machine. You can specify your machine type.
If you follow the notebook you can also get online predictions using the Vertex AI SDK.
To learn more about PyTorch on Vertex AI, take a look at the documentation, which explains Vertex AI’s PyTorch integrations and provides resources that show you how to use PyTorch on Vertex AI. You’ll see how easy it is to train, deploy, and orchestrate models in production using PyTorch and Vertex AI. You can also have a look at the notebook that deploys a text classification model.
TL;DR A conversation with 4o about the potential demise of companies like Anthropic. As artificial…
Whether a company begins with a proof-of-concept or live deployment, they should start small, test…
Digital tools are not always superior. Here are some WIRED-tested agendas and notebooks to keep…
Machine learning (ML) models are built upon data.
Editor’s note: This is the second post in a series that explores a range of…
David J. Berg*, David Casler^, Romain Cledat*, Qian Huang*, Rui Lin*, Nissan Pow*, Nurcan Sonmez*,…