---
title: flash-sd3
canonical_url: "https://www.modelscope.cn/models/AI-ModelScope/flash-sd3"
md_url: "https://www.modelscope.cn/models/AI-ModelScope/flash-sd3.md"
repository: AI-ModelScope/flash-sd3
last_updated: 2024-07-26
license: cc-by-nc-4.0
base_model:
  - stabilityai/stable-diffusion-3-medium
base_model_relation: adapter
parameters: 87.6M
tensor_type:
  - F32
library_name:
  - pytorch
  - lora
  - safetensors
frameworks:
  - pytorch
downloads: 2654
stars: 0
tags:
  - lora
  - text-to-image
---

# flash-sd3

> flash-sd3 - AI-ModelScope 在 ModelScope 开源的模型。⚡ Flash Diffusion: FlashSD3 ⚡

AI-ModelScope/flash-sd3 是 ModelScope 魔搭社区上的 87.6M 参数机器学习模型，采用 cc-by-nc-4.0 许可，基于 stabilityai/stable-diffusion-3-medium 构建。

- **Repository**: AI-ModelScope/flash-sd3
- **License**: cc-by-nc-4.0
- **Parameters**: 87.6M
- **Base model**: stabilityai/stable-diffusion-3-medium
- **Tags**: lora, text-to-image
- **Downloads**: 2654
- **Stars**: 0
- **Last updated**: 2024-07-26

Source: https://www.modelscope.cn/models/AI-ModelScope/flash-sd3

---

# ⚡ Flash Diffusion: FlashSD3 ⚡


Flash Diffusion is a diffusion distillation method proposed in [Flash Diffusion: Accelerating Any Conditional
Diffusion Model for Few Steps Image Generation](http://arxiv.org/abs/2406.02347) *by Clément Chadebec, Onur Tasar, Eyal Benaroche, and Benjamin Aubin* from Jasper Research.
This model is a **90.4M** LoRA distilled version of [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium) model that is able to generate 1024x1024 images in **4 steps**.
See our [live demo](https://huggingface.co/spaces/jasperai/flash-sd3) and official [Github repo](https://github.com/gojasper/flash-diffusion).


<p align="center">
   <img style="width:700px;" src="assets/flash_sd3.png">
</p>

# How to use?

The model can be used using the `StableDiffusion3Pipeline` from `diffusers` library directly. It can allow reducing the number of required sampling steps to **4 steps**.

⚠️ First, you need to install a specific version of `diffusers` by running ⚠️

```bash
pip install git+https://github.com/initml/diffusers.git@clement/feature/flash_sd3
```

 Then, you can run the following to generate an image

```python
import torch
from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlashFlowMatchEulerDiscreteScheduler
from peft import PeftModel

# Load LoRA
transformer = SD3Transformer2DModel.from_pretrained(
    "stabilityai/stable-diffusion-3-medium-diffusers",
    subfolder="transformer",
    torch_dtype=torch.float16,
)
transformer = PeftModel.from_pretrained(transformer, "jasperai/flash-sd3")


# Pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
    "stabilityai/stable-diffusion-3-medium-diffusers",
    transformer=transformer,
    torch_dtype=torch.float16,
    text_encoder_3=None,
    tokenizer_3=None
)

# Scheduler
pipe.scheduler = FlashFlowMatchEulerDiscreteScheduler.from_pretrained(
  "stabilityai/stable-diffusion-3-medium-diffusers",
  subfolder="scheduler",
)

pipe.to("cuda")

prompt = "A raccoon trapped inside a glass jar full of colorful candies, the background is steamy with vivid colors."

image = pipe(prompt, num_inference_steps=4, guidance_scale=0).images[0]
```
<p align="center">
   <img style="width:400px;" src="assets/raccoon.png">
</p>


## Training details
The model was trained for ~50 hours on 2 H100 GPUs.

💡 Training Hint : Model could perform much better on text if distilled on dataset of images containing text, feel free to try it yourself.


## Citation
If you find this work useful or use it in your research, please consider citing us

```bibtex
@misc{chadebec2024flash,
      title={Flash Diffusion: Accelerating Any Conditional Diffusion Model for Few Steps Image Generation}, 
      author={Clement Chadebec and Onur Tasar and Eyal Benaroche and Benjamin Aubin},
      year={2024},
      eprint={2406.02347},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}
```

## License
This model is released under the the Creative Commons BY-NC license.
