Stability AI releases Stable Diffusion: the AI image generator that runs on your own computerIn April we talked about DALL·E 2, OpenAI's artificial intelligence capable of creating images from a description. It was impressive, but it had one limitation: it could only be used through OpenAI's platform, after getting through a waitlist. This Monday, August 22, the British startup Stability AI changed the rules of the game by publicly releasing Stable Diffusion, an image generation model that anyone can download and run on their own computer. The model was developed by the CompVis group at Ludwig Maximilian University of Munich and the company Runway, with compute support from Stability AI, and it was trained on images from the open LAION-5B dataset.
A futuristic city generated by Stable Diffusion. Image: CompVis / Stability AI.
What makes it special?
In terms of quality, Stable Diffusion is on par with the most advanced commercial systems. But its big difference is that it is open:
- The code and the model weights were published, that is, the file of a few gigabytes that contains everything the neural network "learned".
- It runs on a consumer graphics card: according to Stability AI, the released version uses about 6.9 GB of video memory (VRAM). For now NVIDIA cards are recommended, and the company promises optimized versions for AMD and for Macs with M1 and M2 chips.
- It is distributed under the CreativeML OpenRAIL-M license, which allows personal and commercial use but prohibits harmful or illegal uses.
- It includes a safety classifier that filters unwanted results, although it can be adjusted.
For those without a suitable graphics card, Stability AI also offers DreamStudio, a beta web app that lets you generate images from the browser.
Examples of images generated by Stable Diffusion from text. Images: CompVis / Stability AI.
How does it manage to run on a PC?
Like DALL·E 2, Stable Diffusion is based on diffusion: it starts from random noise and cleans it up step by step, guided by the description, until it forms an image. The difference is where that process happens. Instead of working directly on the pixels, Stable Diffusion uses a technique called latent diffusion, developed by the same CompVis group. First, an autoencoder compresses the image into a much smaller representation, the "latent space". Diffusion happens on that compressed version, which has about 48 times fewer values than the original image, and at the end a decoder turns it into the 512 × 512 pixel image. That greatly reduces the memory and computation needed, and it's what lets the model run on a home graphics card.
Stable Diffusion's latent diffusion process. Diagram: The Joy Robot.
More than text-to-image
Besides creating images from text, Stable Diffusion can take an existing image as a starting point (image-to-image). For example, we can make a very simple drawing with the shapes and colors we want, describe the scene and let the model generate an illustration that respects that composition.
A simple sketch turned into a landscape with the image-to-image feature. Images: CompVis / Stability AI.
Try it on your computer
The model weights (version 1.4) are distributed through Hugging Face, where you need to create an account and accept the license before downloading them. With Python and Hugging Face's diffusers library, generating an image takes just a few lines of code. First we install the dependencies and log in with our Hugging Face token:
|
| Terminal |
$ pip install diffusers transformers torch
$ huggingface-cli login |
|
|
Then, this script generates an image and saves it to a PNG file:
|
| Language: Python |
|
1 | import torch
2 | from diffusers import StableDiffusionPipeline
3 |
4 | pipe = StableDiffusionPipeline.from_pretrained(
5 | "CompVis/stable-diffusion-v1-4",
6 | revision="fp16",
7 | torch_dtype=torch.float16,
8 | use_auth_token=True
9 | ).to("cuda")
10 |
11 | image = pipe("a photograph of an astronaut riding a horse").images[0]
12 | image.save("astronaut.png")
|
|
|
The first time, it will download several gigabytes of data. Using 16-bit precision (float16) reduces video memory usage, which matters if our card has little VRAM.
Our take
If DALL·E 2 showed what generative AI could do, Stable Diffusion put it in everyone's hands. Because it's open, any developer can study it, modify it, integrate it into their own applications or train it on their own data. It's very likely that within a few weeks we'll see graphical interfaces, plugins for design programs and optimized versions created by the community. It's the same effect free software had in other areas, and it's exciting to see it in artificial intelligence. But that same openness makes the questions DALL·E 2 already raised more urgent. Since it doesn't depend on a central platform, nobody can fully control how it's used. And the questions about the rights of artists whose works are part of the training data remain open. We think we're going to hear a lot about this topic in the coming months.
|
|
|