How to run DreamBooth (Stable Diffusion) on Serverless GPUs
November 24, 2022Deprecated: This blog article is deprecated. We strive to rapidly improve our product and some of the information contained in this post may no longer be accurate or applicable. For the most current instructions on deploying a model like DreamBooth to Banana, please check our updated documentation.
In this article we'll outline how to deploy Dreambooth Stable Diffusion on serverless GPUs with Banana.
What is Dreambooth?
Dreambooth is a methodology developed by Google Research for "personalizing" text-to-image diffusion models. They key breakthrough with Dreambooth is the ability for you to mimic the appearance of a subject and reproduce this subject in different environments. Basically, you can upload 5-10 reference images of yourself, a dog, a cat, etc. and be able to put this subject in different scenes, poses, and lighting conditions that are vastly different than the reference images you provided.
It's important to make the distinction that this is not a machine learning model itself, but rather a technique that you pair with popular models like Imagen or Stable Diffusion to produce personalized, photo-realistic images of a subject.
Why use Dreambooth Stable Diffusion?
The most popular model to pair with Dreambooth is Stable Diffusion. You can find the GitHub repository for Dreambooth Stable Diffusion by XavierXiao here.
As a standalone model, Stable Diffusion is already a powerful text-to-image generation model that has many different use cases and has taken the ML community by storm. We even have a 1-click model of Stable Diffusion that you can deploy in ~10 seconds within Banana's serverless platform.
Applying Dreambooth to Stable Diffusion unlocks many other interesting use cases and business opportunities.
How to Deploy Dreambooth on Serverless GPUs
Less talk, more action! Let's dive in.
1. Training in Colab
Follow the instructions in this colab notebook to train Stable Diffusion on your images.
Once you have completed the training step, find the model.ckpt that was exported, and download it. Upload this to Amazon S3 cloud storage.
2. Fork Banana Serverless Framework Repo
Fork this repository to your own private repo. This repo is the Banana Serverless Framework setup for Dreambooth Stable Diffusion.
Note: if you want to better understand how the Banana Serverless Framework functions, review our docs on it here.
3. Make Changes in Your Repo
Open the download.py
file within the repo and make the following changes:
- Line 10: replace AWS_REGION to the region in which you have uploaded weights to in S3.
- Line 10: replace AWS_ACCESS_KEY to your actual key that you get within your AWS console.
- Line 10: replace AWS_SECRET_ACCESS_KEY your actual key that you get within your AWS console.
- Line 11: replace BUCKET_NAME with the name of the bucket on s3 that you uploaded the weights into.
- Line 12, 13: replace FOLDER_NAME with the folder name you uploaded to s3. For example, if training results were in a folder called “results/” and you uploaded this to s3, you’ll put “results/” here so the app knows which folder to download in the specific bucket.
Open the Dockerfile
and make this change:
- Add your HuggingFace auth token in the ENV HF_AUTH_TOKEN=your_token
4. Create Banana Account and Deploy Dreambooth
Login to your Banana Dashboard and click the "New Model" button.
A popup will appear looking like this:
Select "GitHub Repo", and choose the GitHub repository that you just made for Dreambooth. Click "Deploy" and the model will start to build.
The build process can take up to 1 hour so be patient, though it usually is much faster than that.
You'll see the Model Status change from "Building" to "Deployed" when it's ready to be called.
You can also monitor the status of your build in the Model Logs tab.
5. Call your Dreambooth Model!
Once your Dreambooth model is built, it's ready to use it in production! To call your model decide which Banana SDK you would like to use (Python, Node, Go).
Follow the instructions in the SDK docs on how to call it and you're all set!
Frequently Asked Questions:
Is there a way to do this on Banana programatically?
Not yet, but it's coming. We're working on this functionality and we'll let our Discord community know when it is ready (so make sure you join the Discord).
We've noticed that most people who want Dreambooth deployed are at the pre-launch stage of their project and don't have many users yet. Our suggestion is that you "do things that don't scale" (quoting the legend, Paul Graham) and upload these models manually until it starts getting out of control. Message us on Discord if you're at that stage and we'll make sure we get programatic functionality to you ASAP.
Does Banana have build arguments?
No, we'll have this released in the next few days.
Can I run my model training on Banana instead of Colab?
We don't recommend you do this currently....but stay tuned. 😉
Is there a limit to the number of models I can have in my Banana account?
No limit at this time. Go wild 😊
Can I delete models within my Banana account?
Yes, you can delete models when you are done with them. Banana also cleans up old models from accounts after 30 days of inactivity.