models stabilityai stable diffusion 2 1 - Azure/azureml-assets GitHub Wiki

stabilityai-stable-diffusion-2-1

Overview

This stable-diffusion-2-1 model is fine-tuned from stable-diffusion-2 (768-v-ema.ckpt) with an additional 55k steps on the same dataset (with punsafe=0.1), and then fine-tuned for another 155k extra steps with punsafe=0.98.

The model is intended for research purposes only. Possible research areas and tasks include

  • Safe deployment of models which have 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.

Stable Diffusion DreamBooth Finetuning is now avalable for this model on AzureML. DreamBooth is a method for personalizing text-to-image models. It fine-tunes these models using 5-10 images of a specific subject, allowing them to generate personalized images based on textual prompts.

Training Details

Training Data

The model developers used the following dataset for training the model:

  • LAION-5B and subsets (details below). The training data is further filtered using LAION's NSFW detector, with a "p_unsafe" score of 0.1 (conservative). For more details, please refer to LAION-5B's NeurIPS 2022 paper and reviewer discussions on the topic.

Training Procedure

Stable Diffusion v2 is a latent diffusion model which combines an autoencoder with a diffusion model that is trained in the latent space of the autoencoder. During training,

  • Images are encoded through an encoder, which turns images into latent representations. The autoencoder uses a relative downsampling factor of 8 and maps images of shape H x W x 3 to latents of shape H/f x W/f x 4
  • Text prompts are encoded through the OpenCLIP-ViT/H text-encoder.
  • The 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 that was added to the latent and the prediction made by the UNet. We also use the so-called v-objective, see https://arxiv.org/abs/2202.00512.

We currently provide the following checkpoint:

  • 768-v-ema.ckpt: Resumed from 512-base-ema.ckpt and trained for 150k steps using a v-objective on the same dataset. Resumed for another 140k steps on a 768x768 subset of our dataset.

  • Hardware: 32 x 8 x A100 GPUs

  • Optimizer: AdamW

  • Gradient Accumulations: 1

  • Batch: 32 x 8 x 2 x 4 = 2048

  • Learning rate: warmup to 0.0001 for 10,000 steps and then kept constant

Limitations and Biases

Limitations

  • The model does not achieve perfect photorealism
  • The model cannot render legible text
  • The model does not perform well on more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere”
  • Faces and people in general may not be generated properly.
  • The model was trained mainly with English captions and will not work as well in other languages.
  • The autoencoding part of the model is lossy
  • The model was trained on a subset of the large-scale dataset LAION-5B, which contains adult, violent and sexual content. To partially mitigate this, we have filtered the dataset using LAION's NFSW detector (see Training section).

Bias

While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases. Stable Diffusion was primarily trained on subsets of LAION-2B(en), which consists of images that are limited to English descriptions. Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for. This affects the overall output of the model, as white and western cultures are often set as the default. Further, the ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts. Stable Diffusion v2 mirrors and exacerbates biases to such a degree that viewer discretion must be advised irrespective of the input or its intent.

The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.

Out-of-Scope Use

The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.

Misuse and Malicious Use

Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:

  • Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
  • Intentionally promoting or propagating discriminatory content or harmful stereotypes.
  • Impersonating individuals without their consent.
  • Sexual content without consent of the people who might see it.
  • Mis- and disinformation
  • Representations of egregious violence and gore
  • Sharing of 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.

License

CreativeML Open RAIL++-M License

DreamBooth Finetuning Samples

Task Use case Dataset Python sample (Notebook) CLI with YAML
Text-to-image Text-to-image dog-example diffusers-dreambooth-dog-text-to-image.ipynb diffusers-dreambooth-dog-text-to-image.sh

Inference Samples

Note: The inferencing script of this model is optimized for high-throughput, low latency using Deepspedd-mii library. Please use version 4 of this model for inferencing using default (FP32) diffusion pipeline implementation.

Inference type Python sample (Notebook) CLI with YAML
Real time text-to-image-online-endpoint.ipynb text-to-image-online-endpoint.sh
Batch text-to-image-batch-endpoint.ipynb text-to-image-batch-endpoint.sh

Inference with Azure AI Content Safety (AACS) samples

Inference type Python sample (Notebook)
Real time safe-text-to-image-online-deployment.ipynb
Batch safe-text-to-image-batch-endpoint.ipynb

Sample input and output

Supported Parameters

  • num_inference_steps: The number of de-noising steps. More de-noising steps usually lead to a higher quality image at the expense of slower inference, defaults to 50.
  • guidance_scale: A higher guidance scale value encourages the model to generate images closely linked to the text prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1, defaults to 7.5.

These parameters are optional inputs. If you need support for new parameters, please file a support ticket.

Sample input

{
   "input_data": {
        "columns": ["prompt"],
        "data": ["a photograph of an astronaut riding a horse"],
        "index": [0],
        "parameters": {
            "num_inference_steps": 50,
            "guidance_scale": 7.5
        }
    }
}

Sample output

[
    {
        "prompt": "a photograph of an astronaut riding a horse",
        "generated_image": "image",
        "nsfw_content_detected": null
    }
]

Note:

  • "image" string is in base64 format.
  • The stabilityai-stable-diffusion-2-1 model doesn't check for the NSFW content in generated image. We highly recommend to use the model with Azure AI Content Safety (AACS). Please refer sample online and batch notebooks for AACS integrated deployments.

Visualization for the prompt - "a photograph of an astronaut riding a horse"

stabilityai_stable_diffusion_2_1 visualization

Version: 12

Tags

SharedComputeCapacityEnabled license : creativeml-openrail++-m task : text-to-image hiddenlayerscanned huggingface_model_id : stabilityai/stable-diffusion-2-1 author : Stability AI training_dataset : LAION-5B inference_supported_envs : ['ds-mii'] inference_compute_allow_list : ['Standard_NC6s_v3', 'Standard_NC12s_v3', 'Standard_NC24s_v3', 'Standard_ND40rs_v2', 'Standard_ND96amsr_A100_v4', 'Standard_ND96asr_v4'] finetune_compute_allow_list : ['Standard_NC6s_v3', 'Standard_NC12s_v3', 'Standard_NC24s_v3', 'Standard_ND40rs_v2', 'Standard_ND96amsr_A100_v4', 'Standard_ND96asr_v4']

View in Studio: https://ml.azure.com/registries/azureml/models/stabilityai-stable-diffusion-2-1/version/12

License: creativeml-openrail++-m

Properties

SharedComputeCapacityEnabled: True

SHA: 5cae40e6a2745ae2b01ad92ae5043f95f23644d6

finetuning-tasks: text-to-image

finetune-min-sku-spec: 6|1|112|736

finetune-recommended-sku: Standard_NC6s_v3, Standard_NC12s_v3, Standard_NC24s_v3, Standard_ND40rs_v2, Standard_ND96amsr_A100_v4, Standard_ND96asr_v4

inference-min-sku-spec: 6|1|112|736

inference-recommended-sku: Standard_NC6s_v3, Standard_NC12s_v3, Standard_NC24s_v3, Standard_ND40rs_v2, Standard_ND96amsr_A100_v4, Standard_ND96asr_v4

⚠️ **GitHub.com Fallback** ⚠️