---
title: lcm-lora-sdxl
canonical_url: "https://www.modelscope.cn/models/AI-ModelScope/lcm-lora-sdxl"
md_url: "https://www.modelscope.cn/models/AI-ModelScope/lcm-lora-sdxl.md"
repository: AI-ModelScope/lcm-lora-sdxl
last_updated: 2024-05-17
license: openrail++
pipeline_tag: text-to-image-synthesis
tasks:
  - text-to-image-synthesis
base_model:
  - stabilityai/stable-diffusion-xl-base-1.0
base_model_relation: adapter
parameters: 196.8M
tensor_type:
  - F16
library_name:
  - pytorch
  - lora
  - safetensors
frameworks:
  - pytorch
downloads: 1476
stars: 8
tags:
  - lora
  - text-to-image
---

# lcm-lora-sdxl

> lcm-lora-sdxl - AI-ModelScope 在 ModelScope 开源的模型。Latent Consistency Model (LCM) LoRA: SDXL

AI-ModelScope/lcm-lora-sdxl 是 ModelScope 魔搭社区上的 196.8M 参数text-to-image-synthesis模型，采用 openrail++ 许可，基于 stabilityai/stable-diffusion-xl-base-1.0 构建。

- **Repository**: AI-ModelScope/lcm-lora-sdxl
- **License**: openrail++
- **Tasks**: text-to-image-synthesis
- **Parameters**: 196.8M
- **Base model**: stabilityai/stable-diffusion-xl-base-1.0
- **Tags**: lora, text-to-image
- **Downloads**: 1476
- **Stars**: 8
- **Last updated**: 2024-05-17

Source: https://www.modelscope.cn/models/AI-ModelScope/lcm-lora-sdxl

---

# Latent Consistency Model (LCM) LoRA: SDXL

Latent Consistency Model (LCM) LoRA was proposed in [LCM-LoRA: A universal Stable-Diffusion Acceleration Module](https://arxiv.org/abs/2311.05556) 
by *Simian Luo, Yiqin Tan, Suraj Patil, Daniel Gu et al.*

It is a distilled consistency adapter for [`stable-diffusion-xl-base-1.0`](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) that allows
to reduce the number of inference steps to only between **2 - 8 steps**.

| Model                                                                      | Params / M | 
|----------------------------------------------------------------------------|------------|
| [lcm-lora-sdv1-5](https://huggingface.co/latent-consistency/lcm-lora-sdv1-5)   | 67.5        |
| [lcm-lora-ssd-1b](https://huggingface.co/latent-consistency/lcm-lora-ssd-1b)   | 105        |
| [**lcm-lora-sdxl**](https://huggingface.co/latent-consistency/lcm-lora-sdxl) | **197M**  |

## Usage

LCM-LoRA is supported in 🤗 Hugging Face Diffusers library from version v0.23.0 onwards. To run the model, first 
install the latest version of the Diffusers library as well as `peft`, `accelerate` and `transformers`.
audio dataset from the Hugging Face Hub:

```bash
pip install --upgrade pip
pip install --upgrade diffusers transformers accelerate peft
```

### Text-to-Image

The adapter can be loaded with it's base model `stabilityai/stable-diffusion-xl-base-1.0`. Next, the scheduler needs to be changed to [`LCMScheduler`](https://huggingface.co/docs/diffusers/v0.22.3/en/api/schedulers/lcm#diffusers.LCMScheduler) and we can reduce the number of inference steps to just 2 to 8 steps.
Please make sure to either disable `guidance_scale` or use values between 1.0 and 2.0.

```python
import torch
from diffusers import LCMScheduler, AutoPipelineForText2Image

model_id = "stabilityai/stable-diffusion-xl-base-1.0"
adapter_id = "latent-consistency/lcm-lora-sdxl"

# pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16")
from modelscope.hub.snapshot_download import snapshot_download
model_dir = snapshot_download(model_id)
pipe = AutoPipelineForText2Image.from_pretrained(model_dir, torch_dtype=torch.float16, variant="fp16")

pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda")

# load and fuse lcm lora
pipe.load_lora_weights(adapter_id)
pipe.fuse_lora()


prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"

# disable guidance_scale by passing 0
image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0).images[0]
```

![](./image.png)

### Image-to-Image

Works as well! TODO docs

### Inpainting

Works as well! TODO docs

### ControlNet

Works as well! TODO docs

### T2I Adapter

Works as well! TODO docs

## Speed Benchmark

TODO

## Training

TODO
