🔥Diffusers++🔥 构建于 HuggingFace Diffusers 之上,确保包含与图像和视频生成相关的最新最先进模型。🔥Diffusers++🔥 是用于生成图像、音频甚至分子 3D 结构的最新最先进预训练扩散模型的首选库。无论您是寻找简单的推理解决方案还是训练自己的扩散模型,🔥Diffusers++🔥 都是一个支持两者的模块化工具箱。我们的库设计侧重于可用性优于性能、简单优于容易,以及可定制性优于抽象。
Diffusers++ 提供三个核心组件:
-
Plus Pipelines 和 Plus Models 包含了 CHAMP、ELLA 和 FIFO-Diffusion 等最新进展。我们致力于将图像和音频领域的最新进展纳入其中,以确保我们的库保持前沿地位。此外,我们提供最先进的 diffusion pipelines,只需几行代码即可在推理中运行。
-
可互换的噪声 schedulers,适用于不同的扩散速度和输出质量。
-
预训练的 models,可作为构建模块使用,并与 schedulers 结合,用于创建您自己的端到端扩散系统。此外,Plus Models 复制了一些最新进展,包括 CHAMP 和 ELLA,以提供最先进的性能。
Installation
我们建议在虚拟环境中从 PyPI 或 Conda 安装 Diffusers++。有关安装 PyTorch 的更多详细信息,请参阅其官方文档。
Diffusers++
目前,可以通过克隆仓库来安装 Diffusers++:
git clone https://github.com/ModelsLab/diffusers_plus_plus.git
cd diffusers_plus_plus
python -m pip install -e
Apple Silicon (M1/M2) 支持
请参阅 如何在 Apple Silicon 上使用 Stable Diffusion 指南。
快速入门
使用 Diffusers++ 生成输出非常简单。要从文本生成图像,请使用 from_pretrained 方法加载任何预训练的扩散模型(在 Hub 中浏览 25.000+ 个检查点):
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
您还可以深入挖掘模型和调度器工具箱,以构建自己的扩散系统:
from diffusers import DDPMScheduler, UNet2DModel
from PIL import Image
import torch
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
scheduler.set_timesteps(50)
sample_size = model.config.sample_size
noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
input = noise
for t in scheduler.timesteps:
with torch.no_grad():
noisy_residual = model(input, t).sample
prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
input = prev_noisy_sample
image = (input / 2 + 0.5).clamp(0, 1)
image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
image = Image.fromarray((image * 255).round().astype("uint8"))
image
查看 快速入门,立即开启你的扩散之旅!
如何浏览文档
| 文档 | 我能学到什么? |
|---|---|
| 教程 | 学习如何使用该库最重要的功能(如使用模型和调度器构建自己的扩散系统,以及训练自己的扩散模型)的基础速成课程。 |
| 加载 | 关于如何加载和配置该库的所有组件(管道、模型和调度器)的指南,以及如何使用不同的调度器。 |
| 用于推理的管道 | 关于如何使用管道执行不同的推理任务、批量生成、控制生成输出和随机性,以及如何向该库贡献管道的指南。 |
| 优化 | 关于如何优化扩散模型以加快运行速度并减少内存占用的指南。 |
| 训练 | 关于如何使用不同的训练技术针对不同任务训练扩散模型的指南。 |
贡献
我们 ❤️ 来自开源社区的贡献! 如果您想为本库做出贡献,请查阅我们的贡献指南。 您可以关注您想要解决的问题,以向该库做出贡献。
- 查看适合初学者的问题,了解一般的贡献机会。
- 查看新模型/流水线,以贡献令人兴奋的新扩散模型/扩散流水线。
- 查看新调度器。
- 查看缺陷,如果某些功能无法正常工作。
- 查看文档,以改进或补充文档。
- 查看重复,如果该问题或拉取请求已经存在。
- 查看增强,以提出新功能或请求。
- 查看需要帮助,如果需要额外关注。
- 查看无效,如果某些内容似乎不正确。
- 查看问题,如果需要进一步的信息。
此外,请在我们的公共 Discord 频道中打个招呼 。我们讨论关于扩散模型的最新趋势,互相帮助进行贡献、个人项目,或者只是放松一下 🔥。
热门任务与 Plus 流水线
| 任务 | 流水线 | 🔥Diffusers++🔥 Hub |
|---|---|---|
| 从文本生成无限视频(即将推出) | FIFO-Diffusion | dummy/dummy-pipeline |
| 文本生成图像 | ELLA | dummy/dummy-pipeline |
| 基于潜在扩散的参数化 3D 人体动画 | CHAMP | dummy/dummy-pipeline |
使用 🧨 Diffusers 的流行库
- https://github.com/ModelsLab/diffusers_plus_plus
- https://github.com/microsoft/TaskMatrix
- https://github.com/invoke-ai/InvokeAI
- https://github.com/apple/ml-stable-diffusion
- https://github.com/Sanster/lama-cleaner
- https://github.com/IDEA-Research/Grounded-Segment-Anything
- https://github.com/ashawkey/stable-dreamfusion
- https://github.com/deep-floyd/IF
- https://github.com/bentoml/BentoML
- https://github.com/bmaltais/kohya_ss
- +11,000 其他出色的 GitHub 仓库 💪
感谢您使用我们 ❤️。
致谢
本库具体化了许多不同作者之前的工作,如果没有他们出色的研究和实现,本库是不可能存在的。我们特别感谢以下实现,它们帮助了我们的开发,没有它们,今天的 API 不可能如此完善:
- @CompVis 的 latent diffusion models 库,可在此处
- @hojonathanho 的原始 DDPM 实现,可在此处,以及 @pesser 极其有用的 PyTorch 翻译,可在此处
- @ermongroup 的 DDIM 实现,可在此处
- @yang-song 的 Score-VE 和 Score-VP 实现,可在此处
我们努力添加最新的文本到图像和文本到视频流水线,以确保我们的库保持前沿和多功能。我们的团队致力于集成最先进的模型,并为所有用户提供强大且用户友好的 API。
我们也想感谢 @heejkoo 提供的关于扩散模型的论文、代码和资源的非常有益的概述,可在此处 找到,以及感谢 @crowsonkb 和 @rromb 提供的有用讨论和见解。
Citation
@misc{von-platen-etal-2022-diffusers,
author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Dhruv Nair and Sayak Paul and William Berman and Yiyi Xu and Steven Liu and Thomas Wolf},
title = {Diffusers: State-of-the-art diffusion models},
year = {2022},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/huggingface/diffusers}}
}