Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/source/zh/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
- local: optimization/xformers
title: xFormers

- title: Modular Diffusers
isExpanded: false
sections:
- local: modular_diffusers/overview
title: Overview
- local: modular_diffusers/quickstart
title: Quickstart
- local: modular_diffusers/modular_diffusers_states
title: States
- local: modular_diffusers/pipeline_block
title: ModularPipelineBlocks
- local: modular_diffusers/sequential_pipeline_blocks
title: SequentialPipelineBlocks
- local: modular_diffusers/loop_sequential_pipeline_blocks
title: LoopSequentialPipelineBlocks
- local: modular_diffusers/auto_pipeline_blocks
title: AutoPipelineBlocks
- local: modular_diffusers/modular_pipeline
title: ModularPipeline

- title: Training
isExpanded: false
Expand Down Expand Up @@ -63,6 +82,8 @@
sections:
- title: Task recipes
sections:
- local: community_projects
title: Projects built with Diffusers
- local: conceptual/philosophy
title: Philosophy
- local: conceptual/contribution
Expand Down
89 changes: 89 additions & 0 deletions docs/source/zh/community_projects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--版权 2025 The HuggingFace Team。保留所有权利。

根据Apache许可证,版本2.0("许可证")授权;除非符合许可证,否则不得使用此文件。您可以在

http://www.apache.org/licenses/LICENSE-2.0

获取许可证的副本。

除非适用法律要求或书面同意,根据许可证分发的软件是按"原样"分发的,没有任何形式的明示或暗示的担保或条件。有关许可证的特定语言,请参阅许可证。
-->

# 社区项目

欢迎来到社区项目。这个空间致力于展示我们充满活力的社区使用`diffusers`库创建的令人难以置信的工作和创新应用。

本节旨在:

- 突出使用`diffusers`构建的多样化和鼓舞人心的项目
- 促进我们社区内的知识共享
- 提供如何利用`diffusers`的实际例子

探索愉快,感谢您成为Diffusers社区的一部分!

<table>
<tr>
<th>项目名称</th>
<th>描述</th>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/carson-katri/dream-textures"> dream-textures </a></td>
<td>Stable Diffusion内置到Blender</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/megvii-research/HiDiffusion"> HiDiffusion </a></td>
<td>仅通过添加一行代码即可提高扩散模型的分辨率和速度</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/lllyasviel/IC-Light"> IC-Light </a></td>
<td>IC-Light是一个用于操作图像照明的项目</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/InstantID/InstantID"> InstantID </a></td>
<td>InstantID:零样本身份保留生成在几秒钟内</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/Sanster/IOPaint"> IOPaint </a></td>
<td>由SOTA AI模型驱动的图像修复工具。从您的图片中移除任何不需要的物体、缺陷、人物,或擦除并替换(由stable_diffusion驱动)图片上的任何内容。</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/bmaltais/kohya_ss"> Kohya </a></td>
<td>Kohya的Stable Diffusion训练器的Gradio GUI</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/magic-research/magic-animate"> MagicAnimate </a></td>
<td>MagicAnimate:使用扩散模型进行时间一致的人体图像动画</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/levihsu/OOTDiffusion"> OOTDiffusion </a></td>
<td>基于潜在扩散的虚拟试穿控制</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/vladmandic/automatic"> SD.Next </a></td>
<td>SD.Next: Stable Diffusion 和其他基于Diffusion的生成图像模型的高级实现</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/ashawkey/stable-dreamfusion"> stable-dreamfusion </a></td>
<td>使用 NeRF + Diffusion 进行文本到3D & 图像到3D & 网格导出</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/HVision-NKU/StoryDiffusion"> StoryDiffusion </a></td>
<td>StoryDiffusion 可以通过生成一致的图像和视频来创造一个神奇的故事。</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/cumulo-autumn/StreamDiffusion"> StreamDiffusion </a></td>
<td>实时交互生成的管道级解决方案</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/Netwrck/stable-diffusion-server"> Stable Diffusion Server </a></td>
<td>配置用于使用一个 stable diffusion 模型进行修复/生成/img2img 的服务器</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/suzukimain/auto_diffusers"> Model Search </a></td>
<td>在 Civitai 和 Hugging Face 上搜索模型</td>
</tr>
<tr style="border-top: 2px solid black">
<td><a href="https://github.com/beinsezii/skrample"> Skrample </a></td>
<td>完全模块化的调度器功能,具有一流的 diffusers 集成。</td>
</tr>
</table>
156 changes: 156 additions & 0 deletions docs/source/zh/modular_diffusers/auto_pipeline_blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!--版权所有 2025 The HuggingFace Team。保留所有权利。

根据Apache许可证2.0版("许可证")授权;除非符合许可证,否则不得使用此文件。您可以在

http://www.apache.org/licenses/LICENSE-2.0

获取许可证的副本。

除非适用法律要求或书面同意,根据许可证分发的软件按"原样"分发,无任何明示或暗示的担保或条件。有关许可证的特定语言管理权限和限制,请参阅许可证。
-->

# AutoPipelineBlocks

[`~modular_pipelines.AutoPipelineBlocks`] 是一种包含支持不同工作流程的块的多块类型。它根据运行时提供的输入自动选择要运行的子块。这通常用于将多个工作流程(文本到图像、图像到图像、修复)打包到一个管道中以便利。

本指南展示如何创建 [`~modular_pipelines.AutoPipelineBlocks`]。

创建三个 [`~modular_pipelines.ModularPipelineBlocks`] 用于文本到图像、图像到图像和修复。这些代表了管道中可用的不同工作流程。

<hfoptions id="auto">
<hfoption id="text-to-image">

```py
import torch
from diffusers.modular_pipelines import ModularPipelineBlocks, InputParam, OutputParam

class TextToImageBlock(ModularPipelineBlocks):
model_name = "text2img"

@property
def inputs(self):
return [InputParam(name="prompt")]

@property
def intermediate_outputs(self):
return []

@property
def description(self):
return "我是一个文本到图像的工作流程!"

def __call__(self, components, state):
block_state = self.get_block_state(state)
print("运行文本到图像工作流程")
# 在这里添加你的文本到图像逻辑
# 例如:根据提示生成图像
self.set_block_state(state, block_state)
return components, state
```


</hfoption>
<hfoption id="image-to-image">

```py
class ImageToImageBlock(ModularPipelineBlocks):
model_name = "img2img"

@property
def inputs(self):
return [InputParam(name="prompt"), InputParam(name="image")]

@property
def intermediate_outputs(self):
return []

@property
def description(self):
return "我是一个图像到图像的工作流程!"

def __call__(self, components, state):
block_state = self.get_block_state(state)
print("运行图像到图像工作流程")
# 在这里添加你的图像到图像逻辑
# 例如:根据提示转换输入图像
self.set_block_state(state, block_state)
return components, state
```


</hfoption>
<hfoption id="inpaint">

```py
class InpaintBlock(ModularPipelineBlocks):
model_name = "inpaint"

@property
def inputs(self):
return [InputParam(name="prompt"), InputParam(name="image"), InputParam(name="mask")]

@property

def intermediate_outputs(self):
return []

@property
def description(self):
return "我是一个修复工作流!"

def __call__(self, components, state):
block_state = self.get_block_state(state)
print("运行修复工作流")
# 在这里添加你的修复逻辑
# 例如:根据提示填充被遮罩的区域
self.set_block_state(state, block_state)
return components, state
```

</hfoption>
</hfoptions>

创建一个包含子块类及其对应块名称列表的[`~modular_pipelines.AutoPipelineBlocks`]类。

你还需要包括`block_trigger_inputs`,一个触发相应块的输入名称列表。如果在运行时提供了触发输入,则选择该块运行。使用`None`来指定如果未检测到触发输入时运行的默认块。

最后,重要的是包括一个`description`,清楚地解释哪些输入触发哪些工作流。这有助于用户理解如何运行特定的工作流。

```py
from diffusers.modular_pipelines import AutoPipelineBlocks

class AutoImageBlocks(AutoPipelineBlocks):
# 选择子块类的列表
block_classes = [block_inpaint_cls, block_i2i_cls, block_t2i_cls]
# 每个块的名称,顺序相同
block_names = ["inpaint", "img2img", "text2img"]
# 决定运行哪个块的触发输入
# - "mask" 触发修复工作流
# - "image" 触发img2img工作流(但仅在未提供mask时)
# - 如果以上都没有,运行text2img工作流(默认)
block_trigger_inputs = ["mask", "image", None]
# 对于AutoPipelineBlocks来说,描述极其重要

def description(self):
return (
"Pipeline generates images given different types of conditions!\n"
+ "This is an auto pipeline block that works for text2img, img2img and inpainting tasks.\n"
+ " - inpaint workflow is run when `mask` is provided.\n"
+ " - img2img workflow is run when `image` is provided (but only when `mask` is not provided).\n"
+ " - text2img workflow is run when neither `image` nor `mask` is provided.\n"
)
```

包含`description`以避免任何关于如何运行块和需要什么输入的混淆**非常**重要。虽然[`~modular_pipelines.AutoPipelineBlocks`]很方便,但如果它没有正确解释,其条件逻辑可能难以理解。

创建`AutoImageBlocks`的一个实例。

```py
auto_blocks = AutoImageBlocks()
```

对于更复杂的组合,例如在更大的管道中作为子块使用的嵌套[`~modular_pipelines.AutoPipelineBlocks`]块,使用[`~modular_pipelines.SequentialPipelineBlocks.get_execution_blocks`]方法根据你的输入提取实际运行的块。

```py
auto_blocks.get_execution_blocks("mask")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--版权 2025 The HuggingFace Team。保留所有权利。

根据 Apache 许可证 2.0 版("许可证")授权;除非符合许可证,否则不得使用此文件。您可以在

http://www.apache.org/licenses/LICENSE-2.0

获取许可证的副本。

除非适用法律要求或书面同意,根据许可证分发的软件按"原样"分发,无任何明示或暗示的担保或条件。请参阅许可证了解
特定语言下的权限和限制。
-->

# LoopSequentialPipelineBlocks

[`~modular_pipelines.LoopSequentialPipelineBlocks`] 是一种多块类型,它将其他 [`~modular_pipelines.ModularPipelineBlocks`] 以循环方式组合在一起。数据循环流动,使用 `intermediate_inputs` 和 `intermediate_outputs`,并且每个块都是迭代运行的。这通常用于创建一个默认是迭代的去噪循环。

本指南向您展示如何创建 [`~modular_pipelines.LoopSequentialPipelineBlocks`]。

## 循环包装器

[`~modular_pipelines.LoopSequentialPipelineBlocks`],也被称为 *循环包装器*,因为它定义了循环结构、迭代变量和配置。在循环包装器内,您需要以下变量。

- `loop_inputs` 是用户提供的值,等同于 [`~modular_pipelines.ModularPipelineBlocks.inputs`]。
- `loop_intermediate_inputs` 是来自 [`~modular_pipelines.PipelineState`] 的中间变量,等同于 [`~modular_pipelines.ModularPipelineBlocks.intermediate_inputs`]。
- `loop_intermediate_outputs` 是由块创建并添加到 [`~modular_pipelines.PipelineState`] 的新中间变量。它等同于 [`~modular_pipelines.ModularPipelineBlocks.intermediate_outputs`]。
- `__call__` 方法定义了循环结构和迭代逻辑。

```py
import torch
from diffusers.modular_pipelines import LoopSequentialPipelineBlocks, ModularPipelineBlocks, InputParam, OutputParam

class LoopWrapper(LoopSequentialPipelineBlocks):
model_name = "test"
@property
def description(self):
return "I'm a loop!!"
@property
def loop_inputs(self):
return [InputParam(name="num_steps")]
@torch.no_grad()
def __call__(self, components, state):
block_state = self.get_block_state(state)
# 循环结构 - 可以根据您的需求定制
for i in range(block_state.num_steps):
# loop_step 按顺序执行所有注册的块
components, block_state = self.loop_step(components, block_state, i=i)
self.set_block_state(state, block_state)
return components, state
```

循环包装器可以传递额外的参数,如当前迭代索引,到循环块。

## 循环块

循环块是一个 [`~modular_pipelines.ModularPipelineBlocks`],但 `__call__` 方法的行为不同。

- 它从循环包装器。
- 它直接与[`~modular_pipelines.BlockState`]一起工作,而不是[`~modular_pipelines.PipelineState`]。
- 它不需要检索或更新[`~modular_pipelines.BlockState`]。

循环块共享相同的[`~modular_pipelines.BlockState`],以允许值在循环的每次迭代中累积和变化。

```py
class LoopBlock(ModularPipelineBlocks):
model_name = "test"
@property
def inputs(self):
return [InputParam(name="x")]
@property
def intermediate_outputs(self):
# 这个块产生的输出
return [OutputParam(name="x")]
@property
def description(self):
return "我是一个在`LoopWrapper`类内部使用的块"
def __call__(self, components, block_state, i: int):
block_state.x += 1
return components, block_state
```

## LoopSequentialPipelineBlocks

使用[`~modular_pipelines.LoopSequentialPipelineBlocks.from_blocks_dict`]方法将循环块添加到循环包装器中,以创建[`~modular_pipelines.LoopSequentialPipelineBlocks`]。

```py
loop = LoopWrapper.from_blocks_dict({"block1": LoopBlock})
```

添加更多的循环块以在每次迭代中运行,使用[`~modular_pipelines.LoopSequentialPipelineBlocks.from_blocks_dict`]。这允许您在不改变循环逻辑本身的情况下修改块。

```py
loop = LoopWrapper.from_blocks_dict({"block1": LoopBlock(), "block2": LoopBlock})
```
Loading