🚀 潜在一致性模型(Latent Consistency Models)
潜在一致性模型(Latent Consistency Models)是一个用于文本到图像生成的模型,它能在极短的推理时间内生成高质量图像,为图像生成领域带来了高效的解决方案。
🚀 快速开始
你可以直接在以下链接尝试潜在一致性模型:

若要自己运行该模型,可借助 🧨 Diffusers 库:
- 安装库:
pip install --upgrade diffusers # 确保使用至少 diffusers >= 0.22
pip install transformers accelerate
- 运行模型:
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("SimianLuo/LCM_Dreamshaper_v7")
pipe.to(torch_device="cuda", torch_dtype=torch.float32)
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
num_inference_steps = 4
images = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=8.0, lcm_origin_steps=50, output_type="pil").images
更多信息,请查看官方文档:
👉 https://huggingface.co/docs/diffusers/api/pipelines/latent_consistency_models#latent-consistency-models
✨ 主要特性
📚 详细文档
模型描述
该模型从 Dreamshaper v7 对 Stable-Diffusion v1 - 5 的微调版本中提炼而来,仅进行了 4000 次训练迭代(约 32 个 A100 GPU 小时)。
生成结果
通过将无分类器引导蒸馏到模型输入中,LCM 可以在极短的推理时间内生成高质量图像。我们在 768 x 768 分辨率、CFG 比例 w = 8、批量大小 = 4 的设置下,使用 A800 GPU 比较了推理时间。
旧版使用方法
- 安装库:
pip install diffusers transformers accelerate
- 运行模型:
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("SimianLuo/LCM_Dreamshaper_v7", custom_pipeline="latent_consistency_txt2img", custom_revision="main", revision="fb9c5d")
pipe.to(torch_device="cuda", torch_dtype=torch.float32)
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
num_inference_steps = 4
images = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=8.0, output_type="pil").images
📄 许可证
本项目采用 MIT 许可证。
📖 引用
@misc{luo2023latent,
title={Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference},
author={Simian Luo and Yiqin Tan and Longbo Huang and Jian Li and Hang Zhao},
year={2023},
eprint={2310.04378},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
项目链接