Using Daft to Generate Images from Text with Stable Diffusion#
Run this tutorial on Google Colab
In this tutorial, we will be using the Stable Diffusion model to generate images from text. We will explore how to use GPUs with Daft to accelerate computations.
To run this tutorial, you will need access to a GPU. If you are on Google Colab, you may switch to a GPU runtime by going to the menu Runtime -> Change runtime type -> Hardware accelerator -> GPU -> Save.
Let's get started!
Setting Up#
First, let's install some dependencies.
1 2 | |
Next, let's load a Parquet file into Daft. This particular file is hosted in HuggingFace at a https URL.
1 2 3 4 5 6 7 8 9 10 | |
Let's go ahead and .collect() this DataFrame. This will download the Parquet file and materialize the data in memory so that all our subsequent operations will be cached!
1 2 | |
Downloading Images#
Like many datasets, instead of storing the actual images in the dataset's files it looks like the Dataset authors have instead opted to store a URL to the image.
Let's use Daft's builtin functionality to download the images and open them as PIL Images - all in just a few lines of code!
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Great! Now we have a pretty good idea of what our dataset looks like.
Running the Stable Diffusion model on a GPU using Daft UDFs#
Let's now run the Stable Diffusion model over the "TEXT" column, and generate images for those texts!
Using GPUs with Daft UDFs is simple. Just specify num_gpus=N, where N is the number of GPUs that your UDF is going to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |