Model Overview
Model Features
Model Capabilities
Use Cases
🚀 Stable Diffusion v1-3 Model Card
Stable Diffusion is a latent text-to-image diffusion model that can generate photo-realistic images from any text input. For more details on how it works, check out 🤗's Stable Diffusion with D🧨iffusers blog.
The Stable-Diffusion-v1-3 checkpoint was initialized with the weights of Stable-Diffusion-v1-2 and then fine-tuned for 195,000 steps at a resolution of 512x512
on "laion-improved-aesthetics". A 10% drop of text-conditioning was applied to enhance classifier-free guidance sampling. For more information, refer to Training.
These weights are intended for use with the D🧨iffusers library. If you're looking for weights to load into the CompVis Stable Diffusion codebase, click here.
✨ Features
- Capable of generating photo-realistic images from text input.
- Fine-tuned to improve classifier-free guidance sampling.
- Can be used with the D🧨iffusers library for easy implementation.
📦 Installation
We recommend using 🤗's Diffusers library to run Stable Diffusion. Install the necessary packages with the following command:
pip install --upgrade diffusers transformers scipy
💻 Usage Examples
Basic Usage
Running the pipeline with the default PNDM scheduler:
import torch
from torch import autocast
from diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-3"
device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(model_id)
pipe = pipe.to(device)
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt, guidance_scale=7.5)["sample"][0]
image.save("astronaut_rides_horse.png")
Advanced Usage
Using float16 precision for limited GPU memory
If you have less than 10GB of GPU RAM, load the StableDiffusionPipeline
in float16 precision:
import torch
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to(device)
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt, guidance_scale=7.5)["sample"][0]
image.save("astronaut_rides_horse.png")
Swapping out the noise scheduler
To use a different noise scheduler, pass it to from_pretrained
:
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
model_id = "CompVis/stable-diffusion-v1-3"
# Use the K-LMS scheduler here instead
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
pipe = pipe.to("cuda")
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt, guidance_scale=7.5)["sample"][0]
image.save("astronaut_rides_horse.png")
📚 Documentation
Model Details
Property | Details |
---|---|
Developed by | Robin Rombach, Patrick Esser |
Model Type | Diffusion-based text-to-image generation model |
Language(s) | English |
License | The CreativeML OpenRAIL M license is an Open RAIL M license, adapted from the work that BigScience and the RAIL Initiative are jointly carrying in the area of responsible AI licensing. See also the article about the BLOOM Open RAIL license on which our license is based. |
Model Description | This is a model that can be used to generate and modify images based on text prompts. It is a Latent Diffusion Model that uses a fixed, pretrained text encoder (CLIP ViT-L/14) as suggested in the Imagen paper. |
Resources for more information | GitHub Repository, Paper. |
Cite as | @InProceedings{Rombach_2022_CVPR, author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj"orn}, title = {High-Resolution Image Synthesis With Latent Diffusion Models}, booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, month = {June}, year = {2022}, pages = {10684-10695} } |
Uses
Direct Use
The model is for research purposes only. Possible research areas and tasks include:
- Safe deployment of models with the potential to generate harmful content.
- Probing and understanding the limitations and biases of generative models.
- Generation of artworks and use in design and other artistic processes.
- Applications in educational or creative tools.
- Research on generative models.
Excluded uses are described below.
Misuse, Malicious Use, and Out-of-Scope Use
⚠️ Important Note
This section is taken from the DALLE-MINI model card, but applies equally to Stable Diffusion v1.
The model should not be used to intentionally create or spread images that create hostile or alienating environments for people. This includes generating disturbing, distressing, or offensive images, or content that propagates historical or current stereotypes.
Out-of-Scope Use
The model was not trained to provide factual or true representations of people or events. Using it to generate such content is beyond its capabilities.
Misuse and Malicious Use
Using the model to generate cruel content towards individuals is a misuse. This includes, but is not limited to:
- Generating demeaning, dehumanizing, or harmful representations of people, their environments, cultures, religions, etc.
- Intentionally promoting or spreading discriminatory content or harmful stereotypes.
- Impersonating individuals without consent.
- Sexual content without the consent of those who might see it.
- Mis- and disinformation
- Representations of egregious violence and gore
- Sharing copyrighted or licensed material in violation of its terms of use.
- Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
Limitations and Bias
Limitations
- The model doesn't achieve perfect photorealism.
- It can't render legible text.
- It performs poorly on more complex tasks involving compositionality, such as rendering an image of “A red cube on top of a blue sphere”.
- Faces and people may not be generated correctly.
- It was mainly trained with English captions and works less well in other languages.
- The autoencoding part of the model is lossy.
- It was trained on the large-scale dataset LAION-5B, which contains adult material and isn't suitable for product use without additional safety measures.
- No deduplication measures were applied to the dataset, resulting in some memorization of duplicated images in the training data. The training data can be searched at https://rom1504.github.io/clip-retrieval/ to help detect memorized images.
Bias
While image generation models are impressive, they can reinforce or exacerbate social biases. Stable Diffusion v1 was trained on subsets of LAION-2B(en), which mainly consists of images with English descriptions. Texts and images from non-English-speaking communities and cultures are likely underrepresented. This affects the model's output, as white and western cultures are often the default. Additionally, the model performs significantly worse with non-English prompts.
Training
Training Data
The model was trained on the following dataset:
- LAION-2B (en) and its subsets (see next section)
Training Procedure
Stable Diffusion v1-4 is a latent diffusion model that combines an autoencoder with a diffusion model trained in the autoencoder's latent space. During training:
- Images are encoded by an encoder into latent representations. The autoencoder uses a relative downsampling factor of 8, mapping images of shape H x W x 3 to latents of shape H/f x W/f x 4.
- Text prompts are encoded by a ViT-L/14 text-encoder.
- The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
- The loss is a reconstruction objective between the noise added to the latent and the prediction made by the UNet.
We currently offer four checkpoints, trained as follows:
stable-diffusion-v1-1
: 237,000 steps at resolution256x256
on laion2B-en. 194,000 steps at resolution512x512
on laion-high-resolution (170M examples from LAION-5B with resolution>= 1024x1024
).stable-diffusion-v1-2
: Resumed fromstable-diffusion-v1-1
. 515,000 steps at resolution512x512
on "laion-improved-aesthetics" (a subset of laion2B-en, filtered to images with an original size>= 512x512
, estimated aesthetics score> 5.0
, and an estimated watermark probability< 0.5
. The watermark estimate is from the LAION-5B metadata, and the aesthetics score is estimated using an improved aesthetics estimator).stable-diffusion-v1-3
: Resumed fromstable-diffusion-v1-2
. 195,000 steps at resolution512x512
on "laion-improved-aesthetics" and 10% dropping of the text-conditioning to improve classifier-free guidance sampling.stable-diffusion-v1-4
: Resumed fromstable-diffusion-v1-2
. 225,000 steps at resolution512x512
on "laion-aesthetics v2 5+" and 10% dropping of the text-conditioning to improve classifier-free guidance sampling.
Training details
- Hardware: 32 x 8 x A100 GPUs
- Optimizer: AdamW
- Gradient Accumulations: 2
- Batch: 32 x 8 x 2 x 4 = 2048
- Learning rate: Warmed up to 0.0001 for 10,000 steps and then kept constant
Evaluation Results
Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling steps show the relative improvements of the checkpoints:
Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, at a resolution of 512x512. Not optimized for FID scores.
Environmental Impact
Stable Diffusion v1 Estimated Emissions Based on the provided information, we estimate the following CO2 emissions using the Machine Learning Impact calculator presented in Lacoste et al. (2019)
📄 License
This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
The CreativeML OpenRAIL License specifies:
- You can't use the model to deliberately produce nor share illegal or harmful outputs or content.
- The authors claim no rights on the outputs you generate. You are free to use them but accountable for their use, which must not violate the license provisions.
- You may re-distribute the weights and use the model commercially and/or as a service. If you do, include the same use restrictions as in the license and share a copy of the CreativeML OpenRAIL-M with all your users (read the license thoroughly).
Please read the full license carefully here: https://huggingface.co/spaces/CompVis/stable-diffusion-license