CoolFace
Modelpublic

nota-ai/bk-sdm-v2-tiny

sourceHugging Facecreativeml-openrail-mupdated 2y agoView on Hugging Face
2likes255downloads
Model Card

BK-SDM-v2 Model Card

BK-SDM-{**v2-Base**, **v2-Small**, **v2-Tiny**} are obtained by compressing SD-v2.1-base.

  • Block-removed Knowledge-distilled Stable Diffusion Models (BK-SDMs) are developed for efficient text-to-image (T2I) synthesis:
  • Certain residual & attention blocks are eliminated from the U-Net of SD.
  • Despite the use of very limited data, distillation retraining remains surprisingly effective.
  • Resources for more information: Paper, GitHub.

Examples with 🤗Diffusers library.

An inference code with the default PNDM scheduler and 50 denoising steps is as follows.

python
import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("nota-ai/bk-sdm-v2-tiny", torch_dtype=torch.float16)
pipe = pipe.to("cuda")

prompt = "a black vase holding a bouquet of roses"
image = pipe(prompt).images[0]  
    
image.save("example.png")

Compression Method

Based on the U-Net architecture and distillation retraining of BK-SDM, a reduced batch size (from 256 to 128) is used in BK-SDM-v2 for faster training speeds.

  • Training Data: 212,776 image-text pairs (i.e., 0.22M pairs) from LAION-Aesthetics V2 6.5+.
  • Hardware: A single NVIDIA A100 80GB GPU
  • Gradient Accumulations: 4
  • Batch: 128 (=4×32)
  • Optimizer: AdamW
  • Learning Rate: a constant learning rate of 5e-5 for 50K-iteration retraining

Experimental Results

The following table shows the zero-shot results on 30K samples from the MS-COCO validation split. After generating 512×512 images with the PNDM scheduler and 25 denoising steps, we downsampled them to 256×256 for evaluating generation scores.

  • Our models were drawn at the 50K-th training iteration.
Compression of SD-v2.1-base
ModelFID↓IS↑CLIP Score↑<br>(ViT-g/14)# Params,<br>U-Net# Params,<br>Whole SDM
Stable Diffusion v2.1-base13.9335.930.30750.87B1.26B
BK-SDM-v2-Base (Ours)15.8531.700.28680.59B0.98B
BK-SDM-v2-Small (Ours)16.6131.730.29010.49B0.88B
BK-SDM-v2-Tiny (Ours)15.6831.640.28970.33B0.72B
Compression of SD-v1.4
ModelFID↓IS↑CLIP Score↑<br>(ViT-g/14)# Params,<br>U-Net# Params,<br>Whole SDM
Stable Diffusion v1.413.0536.760.29580.86B1.04B
BK-SDM-Base (Ours)15.7633.790.28780.58B0.76B
BK-SDM-Base-2M (Ours)14.8134.170.28830.58B0.76B
BK-SDM-Small (Ours)16.9831.680.26770.49B0.66B
BK-SDM-Small-2M (Ours)17.0533.100.27340.49B0.66B
BK-SDM-Tiny (Ours)17.1230.090.26530.33B0.50B
BK-SDM-Tiny-2M (Ours)17.5331.320.26900.33B0.50B
Visual Analysis: Image Areas Affected By Each Word

KD enables our models to mimic the SDM, yielding similar per-word attribution maps. The model without KD behaves differently, causing dissimilar maps and inaccurate generation (e.g., two sheep and unusual bird shapes).

<center> <img alt="cross-attn-maps" img src="https://netspresso-research-code-release.s3.us-east-2.amazonaws.com/assets-bk-sdm/figcross-attn-mapsbk-sd-v2.png" width="100%"> </center>

Uses

Please follow the usage guidelines of Stable Diffusion v1.

Acknowledgments

Citation

bibtex
@article{kim2023architectural,
  title={BK-SDM: A Lightweight, Fast, and Cheap Version of Stable Diffusion},
  author={Kim, Bo-Kyeong and Song, Hyoung-Kyu and Castells, Thibault and Choi, Shinkook},
  journal={arXiv preprint arXiv:2305.15798},
  year={2023},
  url={https://arxiv.org/abs/2305.15798}
}
bibtex
@article{kim2023bksdm,
  title={BK-SDM: Architecturally Compressed Stable Diffusion for Efficient Text-to-Image Generation},
  author={Kim, Bo-Kyeong and Song, Hyoung-Kyu and Castells, Thibault and Choi, Shinkook},
  journal={ICML Workshop on Efficient Systems for Foundation Models (ES-FoMo)},
  year={2023},
  url={https://openreview.net/forum?id=bOVydU0XKC}
}

This model card is based on the [Stable Diffusion v1 model card]( https://huggingface.co/CompVis/stable-diffusion-v1-4).