Skip to content

Commit ba0e732

Browse files
[Modular] Consolidate load_default_components into load_components (#12217)
* update * Apply style fixes * update * update --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b2da59b commit ba0e732

File tree

11 files changed

+59
-66
lines changed

11 files changed

+59
-66
lines changed

docs/source/en/modular_diffusers/components_manager.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ t2i_pipeline = t2i_blocks.init_pipeline(modular_repo_id, components_manager=comp
5151
</hfoption>
5252
</hfoptions>
5353

54-
Components are only loaded and registered when using [`~ModularPipeline.load_components`] or [`~ModularPipeline.load_default_components`]. The example below uses [`~ModularPipeline.load_default_components`] to create a second pipeline that reuses all the components from the first one, and assigns it to a different collection
54+
Components are only loaded and registered when using [`~ModularPipeline.load_components`] or [`~ModularPipeline.load_components`]. The example below uses [`~ModularPipeline.load_components`] to create a second pipeline that reuses all the components from the first one, and assigns it to a different collection
5555

5656
```py
57-
pipe.load_default_components()
57+
pipe.load_components()
5858
pipe2 = ModularPipeline.from_pretrained("YiYiXu/modular-demo-auto", components_manager=comp, collection="test2")
5959
```
6060

@@ -187,4 +187,4 @@ comp.enable_auto_cpu_offload(device="cuda")
187187

188188
All models begin on the CPU and [`ComponentsManager`] moves them to the appropriate device right before they're needed, and moves other models back to the CPU when GPU memory is low.
189189

190-
You can set your own rules for which models to offload first.
190+
You can set your own rules for which models to offload first.

docs/source/en/modular_diffusers/guiders.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ Guiders that are already saved on the Hub with a `modular_model_index.json` file
7575
}
7676
```
7777

78-
The guider is only created after calling [`~ModularPipeline.load_default_components`] based on the loading specification in `modular_model_index.json`.
78+
The guider is only created after calling [`~ModularPipeline.load_components`] based on the loading specification in `modular_model_index.json`.
7979

8080
```py
8181
t2i_pipeline = t2i_blocks.init_pipeline("YiYiXu/modular-doc-guider")
8282
# not created during init
8383
assert t2i_pipeline.guider is None
84-
t2i_pipeline.load_default_components()
84+
t2i_pipeline.load_components()
8585
# loaded as PAG guider
8686
t2i_pipeline.guider
8787
```
@@ -172,4 +172,4 @@ t2i_pipeline.push_to_hub("YiYiXu/modular-doc-guider")
172172
```
173173

174174
</hfoption>
175-
</hfoptions>
175+
</hfoptions>

docs/source/en/modular_diffusers/modular_pipeline.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(TEXT2IMAGE_BLOCKS)
2929
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
3030
pipeline = blocks.init_pipeline(modular_repo_id)
3131

32-
pipeline.load_default_components(torch_dtype=torch.float16)
32+
pipeline.load_components(torch_dtype=torch.float16)
3333
pipeline.to("cuda")
3434

3535
image = pipeline(prompt="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", output="images")[0]
@@ -49,7 +49,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(IMAGE2IMAGE_BLOCKS)
4949
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
5050
pipeline = blocks.init_pipeline(modular_repo_id)
5151

52-
pipeline.load_default_components(torch_dtype=torch.float16)
52+
pipeline.load_components(torch_dtype=torch.float16)
5353
pipeline.to("cuda")
5454

5555
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"
@@ -73,7 +73,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(INPAINT_BLOCKS)
7373
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
7474
pipeline = blocks.init_pipeline(modular_repo_id)
7575

76-
pipeline.load_default_components(torch_dtype=torch.float16)
76+
pipeline.load_components(torch_dtype=torch.float16)
7777
pipeline.to("cuda")
7878

7979
img_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"
@@ -176,15 +176,15 @@ diffdiff_pipeline = ModularPipeline.from_pretrained(modular_repo_id, trust_remot
176176

177177
## Loading components
178178

179-
A [`ModularPipeline`] doesn't automatically instantiate with components. It only loads the configuration and component specifications. You can load all components with [`~ModularPipeline.load_default_components`] or only load specific components with [`~ModularPipeline.load_components`].
179+
A [`ModularPipeline`] doesn't automatically instantiate with components. It only loads the configuration and component specifications. You can load all components with [`~ModularPipeline.load_components`] or only load specific components with [`~ModularPipeline.load_components`].
180180

181181
<hfoptions id="load">
182-
<hfoption id="load_default_components">
182+
<hfoption id="load_components">
183183

184184
```py
185185
import torch
186186

187-
t2i_pipeline.load_default_components(torch_dtype=torch.float16)
187+
t2i_pipeline.load_components(torch_dtype=torch.float16)
188188
t2i_pipeline.to("cuda")
189189
```
190190

@@ -355,4 +355,4 @@ The [config.json](https://huggingface.co/YiYiXu/modular-diffdiff-0704/blob/main/
355355
"ModularPipelineBlocks": "block.DiffDiffBlocks"
356356
}
357357
}
358-
```
358+
```

docs/source/en/modular_diffusers/quickstart.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ print(dd_blocks)
173173

174174
## ModularPipeline
175175

176-
Convert the [`SequentialPipelineBlocks`] into a [`ModularPipeline`] with the [`ModularPipeline.init_pipeline`] method. This initializes the expected components to load from a `modular_model_index.json` file. Explicitly load the components by calling [`ModularPipeline.load_default_components`].
176+
Convert the [`SequentialPipelineBlocks`] into a [`ModularPipeline`] with the [`ModularPipeline.init_pipeline`] method. This initializes the expected components to load from a `modular_model_index.json` file. Explicitly load the components by calling [`ModularPipeline.load_components`].
177177

178-
It is a good idea to initialize the [`ComponentManager`] with the pipeline to help manage the different components. Once you call [`~ModularPipeline.load_default_components`], the components are registered to the [`ComponentManager`] and can be shared between workflows. The example below uses the `collection` argument to assign the components a `"diffdiff"` label for better organization.
178+
It is a good idea to initialize the [`ComponentManager`] with the pipeline to help manage the different components. Once you call [`~ModularPipeline.load_components`], the components are registered to the [`ComponentManager`] and can be shared between workflows. The example below uses the `collection` argument to assign the components a `"diffdiff"` label for better organization.
179179

180180
```py
181181
from diffusers.modular_pipelines import ComponentsManager
@@ -209,11 +209,11 @@ Use the [`sub_blocks.insert`] method to insert it into the [`ModularPipeline`].
209209
dd_blocks.sub_blocks.insert("ip_adapter", ip_adapter_block, 0)
210210
```
211211

212-
Call [`~ModularPipeline.init_pipeline`] to initialize a [`ModularPipeline`] and use [`~ModularPipeline.load_default_components`] to load the model components. Load and set the IP-Adapter to run the pipeline.
212+
Call [`~ModularPipeline.init_pipeline`] to initialize a [`ModularPipeline`] and use [`~ModularPipeline.load_components`] to load the model components. Load and set the IP-Adapter to run the pipeline.
213213

214214
```py
215215
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
216-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
216+
dd_pipeline.load_components(torch_dtype=torch.float16)
217217
dd_pipeline.loader.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
218218
dd_pipeline.loader.set_ip_adapter_scale(0.6)
219219
dd_pipeline = dd_pipeline.to(device)
@@ -260,14 +260,14 @@ class SDXLDiffDiffControlNetDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
260260
controlnet_denoise_block = SDXLDiffDiffControlNetDenoiseStep()
261261
```
262262

263-
Insert the `controlnet_input` block and replace the `denoise` block with the new `controlnet_denoise_block`. Initialize a [`ModularPipeline`] and [`~ModularPipeline.load_default_components`] into it.
263+
Insert the `controlnet_input` block and replace the `denoise` block with the new `controlnet_denoise_block`. Initialize a [`ModularPipeline`] and [`~ModularPipeline.load_components`] into it.
264264

265265
```py
266266
dd_blocks.sub_blocks.insert("controlnet_input", control_input_block, 7)
267267
dd_blocks.sub_blocks["denoise"] = controlnet_denoise_block
268268

269269
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
270-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
270+
dd_pipeline.load_components(torch_dtype=torch.float16)
271271
dd_pipeline = dd_pipeline.to(device)
272272

273273
control_image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_tomato_canny.jpeg")
@@ -320,7 +320,7 @@ Call [`SequentialPipelineBlocks.from_blocks_dict`] to create a [`SequentialPipel
320320
```py
321321
dd_auto_blocks = SequentialPipelineBlocks.from_blocks_dict(DIFFDIFF_AUTO_BLOCKS)
322322
dd_pipeline = dd_auto_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
323-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
323+
dd_pipeline.load_components(torch_dtype=torch.float16)
324324
```
325325

326326
## Share
@@ -340,5 +340,5 @@ from diffusers.modular_pipelines import ModularPipeline, ComponentsManager
340340
components = ComponentsManager()
341341

342342
diffdiff_pipeline = ModularPipeline.from_pretrained("YiYiXu/modular-diffdiff-0704", trust_remote_code=True, components_manager=components, collection="diffdiff")
343-
diffdiff_pipeline.load_default_components(torch_dtype=torch.float16)
344-
```
343+
diffdiff_pipeline.load_components(torch_dtype=torch.float16)
344+
```

docs/source/zh/modular_diffusers/components_manager.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ t2i_pipeline = t2i_blocks.init_pipeline(modular_repo_id, components_manager=comp
4848
</hfoption>
4949
</hfoptions>
5050

51-
组件仅在调用 [`~ModularPipeline.load_components`][`~ModularPipeline.load_default_components`] 时加载和注册。以下示例使用 [`~ModularPipeline.load_default_components`] 创建第二个管道,重用第一个管道的所有组件,并将其分配到不同的集合。
51+
组件仅在调用 [`~ModularPipeline.load_components`][`~ModularPipeline.load_components`] 时加载和注册。以下示例使用 [`~ModularPipeline.load_components`] 创建第二个管道,重用第一个管道的所有组件,并将其分配到不同的集合。
5252

5353
```py
54-
pipe.load_default_components()
54+
pipe.load_components()
5555
pipe2 = ModularPipeline.from_pretrained("YiYiXu/modular-demo-auto", components_manager=comp, collection="test2")
5656
```
5757

@@ -185,4 +185,4 @@ comp.enable_auto_cpu_offload(device="cuda")
185185

186186
所有模型开始时都在 CPU 上,[`ComponentsManager`] 在需要它们之前将它们移动到适当的设备,并在 GPU 内存不足时将其他模型移回 CPU。
187187

188-
您可以设置自己的规则来决定哪些模型要卸载。
188+
您可以设置自己的规则来决定哪些模型要卸载。

docs/source/zh/modular_diffusers/guiders.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ ComponentSpec(name='guider', type_hint=<class 'diffusers.guiders.perturbed_atten
7373
}
7474
```
7575

76-
引导器只有在调用 [`~ModularPipeline.load_default_components`] 之后才会创建,基于 `modular_model_index.json` 中的加载规范。
76+
引导器只有在调用 [`~ModularPipeline.load_components`] 之后才会创建,基于 `modular_model_index.json` 中的加载规范。
7777

7878
```py
7979
t2i_pipeline = t2i_blocks.init_pipeline("YiYiXu/modular-doc-guider")
8080
# 在初始化时未创建
8181
assert t2i_pipeline.guider is None
82-
t2i_pipeline.load_default_components()
82+
t2i_pipeline.load_components()
8383
# 加载为 PAG 引导器
8484
t2i_pipeline.guider
8585
```
@@ -170,4 +170,4 @@ t2i_pipeline.push_to_hub("YiYiXu/modular-doc-guider")
170170
```
171171

172172
</hfoption>
173-
</hfoptions>
173+
</hfoptions>

docs/source/zh/modular_diffusers/modular_pipeline.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(TEXT2IMAGE_BLOCKS)
2828
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
2929
pipeline = blocks.init_pipeline(modular_repo_id)
3030

31-
pipeline.load_default_components(torch_dtype=torch.float16)
31+
pipeline.load_components(torch_dtype=torch.float16)
3232
pipeline.to("cuda")
3333

3434
image = pipeline(prompt="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", output="images")[0]
@@ -48,7 +48,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(IMAGE2IMAGE_BLOCKS)
4848
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
4949
pipeline = blocks.init_pipeline(modular_repo_id)
5050

51-
pipeline.load_default_components(torch_dtype=torch.float16)
51+
pipeline.load_components(torch_dtype=torch.float16)
5252
pipeline.to("cuda")
5353

5454
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"
@@ -72,7 +72,7 @@ blocks = SequentialPipelineBlocks.from_blocks_dict(INPAINT_BLOCKS)
7272
modular_repo_id = "YiYiXu/modular-loader-t2i-0704"
7373
pipeline = blocks.init_pipeline(modular_repo_id)
7474

75-
pipeline.load_default_components(torch_dtype=torch.float16)
75+
pipeline.load_components(torch_dtype=torch.float16)
7676
pipeline.to("cuda")
7777

7878
img_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"
@@ -176,15 +176,15 @@ diffdiff_pipeline = ModularPipeline.from_pretrained(modular_repo_id, trust_remot
176176

177177
## 加载组件
178178

179-
一个[`ModularPipeline`]不会自动实例化组件。它只加载配置和组件规范。您可以使用[`~ModularPipeline.load_default_components`]加载所有组件,或仅使用[`~ModularPipeline.load_components`]加载特定组件。
179+
一个[`ModularPipeline`]不会自动实例化组件。它只加载配置和组件规范。您可以使用[`~ModularPipeline.load_components`]加载所有组件,或仅使用[`~ModularPipeline.load_components`]加载特定组件。
180180

181181
<hfoptions id="load">
182-
<hfoption id="load_default_components">
182+
<hfoption id="load_components">
183183

184184
```py
185185
import torch
186186

187-
t2i_pipeline.load_default_components(torch_dtype=torch.float16)
187+
t2i_pipeline.load_components(torch_dtype=torch.float16)
188188
t2i_pipeline.to("cuda")
189189
```
190190

docs/source/zh/modular_diffusers/quickstart.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ print(dd_blocks)
175175
[`SequentialPipelineBlocks`] 转换为 [`ModularPipeline`],使用 [`ModularPipeline.init_pipeline`] 方法。这会初始化从 `modular_model_index.json` 文件加载的预期组件。通过调用 [`ModularPipeline.load_defau
176176
lt_components`]
177177

178-
初始化[`ComponentManager`]时传入pipeline是一个好主意,以帮助管理不同的组件。一旦调用[`~ModularPipeline.load_default_components`],组件就会被注册到[`ComponentManager`]中,并且可以在工作流之间共享。下面的例子使用`collection`参数为组件分配了一个`"diffdiff"`标签,以便更好地组织。
178+
初始化[`ComponentManager`]时传入pipeline是一个好主意,以帮助管理不同的组件。一旦调用[`~ModularPipeline.load_components`],组件就会被注册到[`ComponentManager`]中,并且可以在工作流之间共享。下面的例子使用`collection`参数为组件分配了一个`"diffdiff"`标签,以便更好地组织。
179179

180180
```py
181181
from diffusers.modular_pipelines import ComponentsManager
@@ -209,11 +209,11 @@ ip_adapter_block = StableDiffusionXLAutoIPAdapterStep()
209209
dd_blocks.sub_blocks.insert("ip_adapter", ip_adapter_block, 0)
210210
```
211211

212-
调用[`~ModularPipeline.init_pipeline`]来初始化一个[`ModularPipeline`],并使用[`~ModularPipeline.load_default_components`]加载模型组件。加载并设置IP-Adapter以运行pipeline。
212+
调用[`~ModularPipeline.init_pipeline`]来初始化一个[`ModularPipeline`],并使用[`~ModularPipeline.load_components`]加载模型组件。加载并设置IP-Adapter以运行pipeline。
213213

214214
```py
215215
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
216-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
216+
dd_pipeline.load_components(torch_dtype=torch.float16)
217217
dd_pipeline.loader.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
218218
dd_pipeline.loader.set_ip_adapter_scale(0.6)
219219
dd_pipeline = dd_pipeline.to(device)
@@ -261,14 +261,14 @@ class SDXLDiffDiffControlNetDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
261261
controlnet_denoise_block = SDXLDiffDiffControlNetDenoiseStep()
262262
```
263263

264-
插入 `controlnet_input` 块并用新的 `controlnet_denoise_block` 替换 `denoise` 块。初始化一个 [`ModularPipeline`] 并将 [`~ModularPipeline.load_default_components`] 加载到其中。
264+
插入 `controlnet_input` 块并用新的 `controlnet_denoise_block` 替换 `denoise` 块。初始化一个 [`ModularPipeline`] 并将 [`~ModularPipeline.load_components`] 加载到其中。
265265

266266
```py
267267
dd_blocks.sub_blocks.insert("controlnet_input", control_input_block, 7)
268268
dd_blocks.sub_blocks["denoise"] = controlnet_denoise_block
269269

270270
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
271-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
271+
dd_pipeline.load_components(torch_dtype=torch.float16)
272272
dd_pipeline = dd_pipeline.to(device)
273273

274274
control_image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_tomato_canny.jpeg")
@@ -322,7 +322,7 @@ DIFFDIFF_AUTO_BLOCKS.insert("controlnet_input",StableDiffusionXLControlNetAutoIn
322322
```py
323323
dd_auto_blocks = SequentialPipelineBlocks.from_blocks_dict(DIFFDIFF_AUTO_BLOCKS)
324324
dd_pipeline = dd_auto_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
325-
dd_pipeline.load_default_components(torch_dtype=torch.float16)
325+
dd_pipeline.load_components(torch_dtype=torch.float16)
326326
```
327327

328328
## 分享
@@ -342,5 +342,5 @@ from diffusers.modular_pipelines import ModularPipeline, ComponentsManager
342342
components = ComponentsManager()
343343

344344
diffdiff_pipeline = ModularPipeline.from_pretrained("YiYiXu/modular-diffdiff-0704", trust_remote_code=True, components_manager=components, collection="diffdiff")
345-
diffdiff_pipeline.load_default_components(torch_dtype=torch.float16)
345+
diffdiff_pipeline.load_components(torch_dtype=torch.float16)
346346
```

0 commit comments

Comments
 (0)