模型介绍
内容详情
替代品
模型简介
LCM-LoRA是一种通用稳定扩散加速模块,通过潜在一致性蒸馏技术显著减少生成图像所需的推理步骤,同时保持生成质量。
模型特点
高效推理
仅需2-8步即可完成高质量图像生成,相比原始模型大幅提升速度
模型兼容
可与Stable Diffusion XL基础模型无缝配合使用
多功能适配
支持文本生成图像、图像修复、ControlNet控制网络等多种应用场景
LoRA融合
可与其他风格化LoRA结合使用,实现少步骤风格化图像生成
模型能力
文本生成图像
图像修复
风格转换
边缘引导生成
快速推理
使用案例
艺术创作
概念艺术生成
快速生成高质量概念艺术图像
4步内生成8k分辨率艺术作品
图像编辑
图像修复
对图像缺失部分进行智能修复
5步内完成高质量修复
设计辅助
风格化设计
结合风格LoRA快速生成特定风格图像
混合LoRA实现4步风格转换
library_name: diffusers
base_model: stabilityai/stable-diffusion-xl-base-1.0
tags:
- lora
- text-to-image
license: openrail++
inference: false
潜在一致性模型(LCM) LoRA:SDXL版
潜在一致性模型(LCM) LoRA由Simian Luo、Yiqin Tan、Suraj Patil、Daniel Gu等在论文《LCM-LoRA:通用稳定扩散加速模块》中提出。
这是为stable-diffusion-xl-base-1.0
设计的蒸馏一致性适配器,可将推理步骤缩减至仅需2-8步。
模型 | 参数量/M |
---|---|
lcm-lora-sdv1-5 | 67.5 |
lcm-lora-ssd-1b | 105 |
lcm-lora-sdxl | 197M |
使用方法
LCM-LoRA从v0.23.0版本开始获得🤗 Hugging Face Diffusers库支持。运行前请先安装最新版Diffusers库及peft
、accelerate
、transformers
:
pip install --upgrade pip
pip install --upgrade diffusers transformers accelerate peft
注:完整用法示例请参阅官方LCM-LoRA文档
文生图
适配器需与基础模型stabilityai/stable-diffusion-xl-base-1.0
配合使用。需将调度器改为LCMScheduler
,并将推理步骤设为2-8步。注意需禁用guidance_scale
或将其值设为1.0-2.0之间。
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")
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda")
# 加载并融合LCM LoRA
pipe.load_lora_weights(adapter_id)
pipe.fuse_lora()
prompt = "自画像油画,一位金发机械美人,8K画质"
# 通过传入0禁用guidance_scale
image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0).images[0]
图像修复
LCM-LoRA同样支持修复任务:
import torch
from diffusers import AutoPipelineForInpainting, LCMScheduler
from diffusers.utils import load_image, make_image_grid
pipe = AutoPipelineForInpainting.from_pretrained(
"diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
torch_dtype=torch.float16,
variant="fp16",
).to("cuda")
# 设置调度器
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# 加载LCM-LoRA
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
pipe.fuse_lora()
# 加载底图与掩膜
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png").resize((1024, 1024))
mask_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png").resize((1024, 1024))
prompt = "山顶城堡,精细刻画,8K画质"
generator = torch.manual_seed(42)
image = pipe(
prompt=prompt,
image=init_image,
mask_image=mask_image,
generator=generator,
num_inference_steps=5,
guidance_scale=4,
).images[0]
make_image_grid([init_image, mask_image, image], rows=1, cols=3)
结合风格化LoRA
LCM-LoRA可与其他LoRA结合实现少步数(4-8步)风格化生成。以下示例将LCM-LoRA与剪纸风格LoRA结合使用。多LoRA组合方法详见本指南。
import torch
from diffusers import DiffusionPipeline, LCMScheduler
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
variant="fp16",
torch_dtype=torch.float16
).to("cuda")
# 设置调度器
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# 加载双LoRA
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl", adapter_name="lcm")
pipe.load_lora_weights("TheLastBen/Papercut_SDXL", weight_name="papercut.safetensors", adapter_name="papercut")
# 组合LoRA
pipe.set_adapters(["lcm", "papercut"], adapter_weights=[1.0, 0.8])
prompt = "剪纸风格,可爱狐狸"
generator = torch.manual_seed(0)
image = pipe(prompt, num_inference_steps=4, guidance_scale=1, generator=generator).images[0]
image
ControlNet控制生成
import torch
import cv2
import numpy as np
from PIL import Image
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel, LCMScheduler
from diffusers.utils import load_image
image = load_image(
"https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png"
).resize((1024, 1024))
image = np.array(image)
low_threshold = 100
high_threshold = 200
image = cv2.Canny(image, low_threshold, high_threshold)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
canny_image = Image.fromarray(image)
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0-small", torch_dtype=torch.float16, variant="fp16")
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
torch_dtype=torch.float16,
safety_checker=None,
variant="fp16"
).to("cuda")
# 设置调度器
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# 加载LCM-LoRA
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
pipe.fuse_lora()
generator = torch.manual_seed(0)
image = pipe(
"蒙娜丽莎画像",
image=canny_image,
num_inference_steps=5,
guidance_scale=1.5,
controlnet_conditioning_scale=0.5,
cross_attention_kwargs={"scale": 1},
generator=generator,
).images[0]
make_image_grid([canny_image, image], rows=1, cols=2)
<提示>
示例参数可能不适用于所有场景,建议尝试调整num_inference_steps
、guidance_scale
、controlnet_conditioning_scale
和cross_attention_kwargs
等参数。
</提示>
T2I适配器
本例展示LCM-LoRA与Canny T2I-Adapter及SDXL的配合使用:
import torch
import cv2
import numpy as np
from PIL import Image
from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, LCMScheduler
from diffusers.utils import load_image, make_image_grid
# 预处理图像(低分辨率检测边缘以避免高频细节)
image = load_image(
"https://huggingface.co/Adapter/t2iadapter/resolve/main/figs_SDXLV1.0/org_canny.jpg"
).resize((384, 384))
image = np.array(image)
low_threshold = 100
high_threshold = 200
image = cv2.Canny(image, low_threshold, high_threshold)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
canny_image = Image.fromarray(image).resize((1024, 1024))
# 加载适配器
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", torch_dtype=torch.float16, varient="fp16").to("cuda")
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
adapter=adapter,
torch_dtype=torch.float16,
variant="fp16",
).to("cuda")
# 设置调度器
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# 加载LCM-LoRA
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
prompt = "真实系魔法精灵,4K高清画质"
negative_prompt = "多余数字|缺数字|裁剪|低质量|画面故障|畸形|丑陋|扭曲"
generator = torch.manual_seed(0)
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
image=canny_image,
num_inference_steps=4,
guidance_scale=1.5,
adapter_conditioning_scale=0.8,
adapter_conditioning_factor=1,
generator=generator,
).images[0]
make_image_grid([canny_image, image], rows=1, cols=2)
速度基准测试
待补充
训练方案
待补充
Stable Diffusion V1 5
Openrail
稳定扩散是一种潜在的文本到图像扩散模型,能够根据任何文本输入生成逼真的图像。
图像生成
S
stable-diffusion-v1-5
3.7M
518
Stable Diffusion Inpainting
Openrail
基于稳定扩散的文本到图像生成模型,具备图像修复能力
图像生成
S
stable-diffusion-v1-5
3.3M
56
Stable Diffusion Xl Base 1.0
SDXL 1.0是基于扩散的文本生成图像模型,采用专家集成的潜在扩散流程,支持高分辨率图像生成
图像生成
S
stabilityai
2.4M
6,545
Stable Diffusion V1 4
Openrail
稳定扩散是一种潜在文本到图像扩散模型,能够根据任意文本输入生成逼真图像。
图像生成
S
CompVis
1.7M
6,778
Stable Diffusion Xl Refiner 1.0
SD-XL 1.0优化器模型是Stability AI开发的图像生成模型,专为提升SDXL基础模型生成的图像质量而设计,特别擅长最终去噪步骤处理。
图像生成
S
stabilityai
1.1M
1,882
Stable Diffusion 2 1
基于扩散的文本生成图像模型,支持通过文本提示生成和修改图像
图像生成
S
stabilityai
948.75k
3,966
Stable Diffusion Xl 1.0 Inpainting 0.1
基于Stable Diffusion XL的潜在文本到图像扩散模型,具备通过遮罩进行图像修复的功能
图像生成
S
diffusers
673.14k
334
Stable Diffusion 2 Base
基于扩散的文生图模型,可根据文本提示生成高质量图像
图像生成
S
stabilityai
613.60k
349
Playground V2.5 1024px Aesthetic
其他
开源文生图模型,能生成1024x1024分辨率及多种纵横比的美学图像,在美学质量上处于开源领域领先地位。
图像生成
P
playgroundai
554.94k
723
Sd Turbo
SD-Turbo是一款高速文本生成图像模型,仅需单次网络推理即可根据文本提示生成逼真图像。
图像生成
S
stabilityai
502.82k
380
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文