Skip to content

Commit 58dbe0c

Browse files
committed
finimsh the quickstart!
1 parent 9aaec5b commit 58dbe0c

2 files changed

Lines changed: 723 additions & 235 deletions

File tree

docs/source/en/modular_diffusers/developer_guide.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Let's see how this works with the Differential Diffusion example.
3939
Differential diffusion (https://differential-diffusion.github.io/) is an image-to-image workflow, so it makes sense for us to start with the preset of pipeline blocks used to build img2img pipeline (`IMAGE2IMAGE_BLOCKS`) and see how we can build this new pipeline with them.
4040

4141
```py
42-
>>> IMAGE2IMAGE_BLOCKS = InsertableOrderedDict([
42+
>>> IMAGE2IMAGE_BLOCKS = InsertableDict([
4343
... ("text_encoder", StableDiffusionXLTextEncoderStep),
4444
... ("image_encoder", StableDiffusionXLVaeEncoderStep),
4545
... ("input", StableDiffusionXLInputStep),
@@ -64,7 +64,7 @@ StableDiffusionXLDenoiseLoop(
6464
6565
Description: Denoise step that iteratively denoise the latents.
6666
Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method
67-
At each iteration, it runs blocks defined in `blocks` sequencially:
67+
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
6868
- `StableDiffusionXLLoopBeforeDenoiser`
6969
- `StableDiffusionXLLoopDenoiser`
7070
- `StableDiffusionXLLoopAfterDenoiser`
@@ -78,13 +78,13 @@ StableDiffusionXLDenoiseLoop(
7878
7979
Blocks:
8080
[0] before_denoiser (StableDiffusionXLLoopBeforeDenoiser)
81-
Description: step within the denoising loop that prepare the latent input for the denoiser. This block should be used to compose the `blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
81+
Description: step within the denoising loop that prepare the latent input for the denoiser. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
8282
8383
[1] denoiser (StableDiffusionXLLoopDenoiser)
84-
Description: Step within the denoising loop that denoise the latents with guidance. This block should be used to compose the `blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
84+
Description: Step within the denoising loop that denoise the latents with guidance. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
8585
8686
[2] after_denoiser (StableDiffusionXLLoopAfterDenoiser)
87-
Description: step within the denoising loop that update the latents. This block should be used to compose the `blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
87+
Description: step within the denoising loop that update the latents. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)
8888
8989
)
9090
```
@@ -223,7 +223,7 @@ This is the modified `StableDiffusionXLImg2ImgPrepareLatentsStep` we ended up wi
223223
]
224224

225225
@property
226-
def intermediates_inputs(self) -> List[InputParam]:
226+
def intermediate_inputs(self) -> List[InputParam]:
227227
return [
228228
InputParam("generator"),
229229
- InputParam("latent_timestep", required=True, type_hint=torch.Tensor, description="The timestep that represents the initial noise level for image-to-image/inpainting generation. Can be generated in set_timesteps step."),
@@ -232,7 +232,7 @@ This is the modified `StableDiffusionXLImg2ImgPrepareLatentsStep` we ended up wi
232232
]
233233

234234
@property
235-
def intermediates_outputs(self) -> List[OutputParam]:
235+
def intermediate_outputs(self) -> List[OutputParam]:
236236
return [
237237
+ OutputParam("original_latents", type_hint=torch.Tensor, description="The initial latents to use for the denoising process"),
238238
+ OutputParam("diffdiff_masks", type_hint=torch.Tensor, description="The masks used for the differential diffusion denoising process"),
@@ -295,7 +295,7 @@ class SDXLDiffDiffLoopBeforeDenoiser(PipelineBlock):
295295
+ ]
296296

297297
@property
298-
def intermediates_inputs(self) -> List[str]:
298+
def intermediate_inputs(self) -> List[str]:
299299
return [
300300
InputParam(
301301
"latents",
@@ -393,7 +393,7 @@ SequentialPipelineBlocks(
393393
Description: Step that prepares the additional conditioning for the image-to-image/inpainting generation process
394394
395395
[6] denoise (SDXLDiffDiffDenoiseLoop)
396-
Description: Pipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `blocks` attributes
396+
Description: Pipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `sub_blocks` attributes
397397
398398
[7] decode (StableDiffusionXLDecodeStep)
399399
Description: Step that decodes the denoised latents into images
@@ -447,10 +447,10 @@ It has 4 components: `unet` and `guider` are already used in diff-diff, but it a
447447
)
448448
```
449449

450-
We can directly add the ip-adapter block instance to the `diffdiff_blocks` that we created before. The `blocks` attribute is a `InsertableOrderedDict`, so we're able to insert the it at specific position (index `0` here).
450+
We can directly add the ip-adapter block instance to the `diffdiff_blocks` that we created before. The `sub_blocks` attribute is a `InsertableDict`, so we're able to insert the it at specific position (index `0` here).
451451

452452
```py
453-
>>> dd_blocks.blocks.insert("ip_adapter", ip_adapter_block, 0)
453+
>>> dd_blocks.sub_blocks.insert("ip_adapter", ip_adapter_block, 0)
454454
```
455455

456456
Take a look at the new diff-diff pipeline with ip-adapter!
@@ -522,7 +522,7 @@ SequentialPipelineBlocks(
522522
Description: Step that prepares the additional conditioning for the image-to-image/inpainting generation process
523523
524524
[7] denoise (SDXLDiffDiffDenoiseLoop)
525-
Description: Pipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `blocks` attributes
525+
Description: Pipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `sub_blocks` attributes
526526
527527
[8] decode (StableDiffusionXLDecodeStep)
528528
Description: Step that decodes the denoised latents into images
@@ -535,10 +535,10 @@ Let's test it out. We used an orange image to condition the generation via ip-ad
535535

536536
```py
537537
>>> ip_adapter_block = StableDiffusionXLAutoIPAdapterStep()
538-
>>> dd_blocks.blocks.insert("ip_adapter", ip_adapter_block, 0)
538+
>>> dd_blocks.sub_blocks.insert("ip_adapter", ip_adapter_block, 0)
539539
>>>
540540
>>> dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
541-
>>> dd_pipeline.load_components(torch_dtype=torch.float16)
541+
>>> dd_pipeline.load_default_components(torch_dtype=torch.float16)
542542
>>> dd_pipeline.loader.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
543543
>>> dd_pipeline.loader.set_ip_adapter_scale(0.6)
544544
>>> dd_pipeline = dd_pipeline.to(device)
@@ -627,11 +627,11 @@ StableDiffusionXLControlNetAutoInput(
627627
Let's assemble the blocks and run an example using controlnet + differential diffusion. We used a tomato as `control_image`, so you can see that in the output, the right half that transformed into a pear had a tomato-like shape.
628628

629629
```py
630-
>>> dd_blocks.blocks.insert("controlnet_input", control_input_block, 7)
631-
>>> dd_blocks.blocks["denoise"] = controlnet_denoise_block
630+
>>> dd_blocks.sub_blocks.insert("controlnet_input", control_input_block, 7)
631+
>>> dd_blocks.sub_blocks["denoise"] = controlnet_denoise_block
632632
>>>
633633
>>> dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", collection="diffdiff")
634-
>>> dd_pipeline.load_components(torch_dtype=torch.float16)
634+
>>> dd_pipeline.load_default_components(torch_dtype=torch.float16)
635635
>>> dd_pipeline = dd_pipeline.to(device)
636636
>>>
637637
>>> control_image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_tomato_canny.jpeg")
@@ -709,8 +709,8 @@ With a modular repo, it is very easy for the community to use the workflow you j
709709
>>>
710710
>>> components = ComponentsManager()
711711
>>>
712-
>>> diffdiff_pipeline = ModularPipeline.from_pretrained(repo_id, trust_remote_code=True, component_manager=components, collection="diffdiff")
713-
>>> diffdiff_pipeline.loader.load(torch_dtype=torch.float16)
712+
>>> diffdiff_pipeline = ModularPipeline.from_pretrained(repo_id, trust_remote_code=True, components_manager=components, collection="diffdiff")
713+
>>> diffdiff_pipeline.load_default_components(torch_dtype=torch.float16)
714714
>>> components.enable_auto_cpu_offload()
715715
```
716716

0 commit comments

Comments
 (0)