8000 The Modular Diffusers by yiyixuxu · Pull Request #9672 · huggingface/diffusers · GitHub
[go: up one dir, main page]

Skip to content

The Modular Diffusers #9672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 188 commits into from
Jul 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
33f85fa
add
yiyixuxu Oct 14, 2024
52a7f1c
add dataflow info for each block in builder _repr_
yiyixuxu Oct 16, 2024
e8d0980
add img2img support - output does not match with non-modular pipeline…
yiyixuxu Oct 16, 2024
ad3f9a2
update img2img, result match
yiyixuxu Oct 17, 2024
ddea157
add from_pipe + run_blocks
yiyixuxu Oct 17, 2024
af9572d
controlnet
yiyixuxu Oct 19, 2024
2b6dcbf
fix controlnet
yiyixuxu Oct 20, 2024
70272b1
combine controlnetstep into contronetdesnoisestep
yiyixuxu Oct 20, 2024
46ec174
refactor guider, remove prepareguidance step to be combinedd into den…
yiyixuxu Oct 23, 2024
f1b3036
update pag guider - draft
yiyixuxu Oct 23, 2024
540d303
refactor guider
yiyixuxu Oct 26, 2024
6742f16
up
yiyixuxu Oct 27, 2024
005195c
add
yiyixuxu Oct 27, 2024
024a9f5
fix so that run_blocks can work with inputs in the state
yiyixuxu Oct 27, 2024
37e8dc7
remove img2img blocksgit status consolidate text2img and img2img
yiyixuxu Oct 27, 2024
8000
8b811fe
refactor, from_pretrained, from_pipe, remove_blocks, replace_blocks
yiyixuxu Oct 30, 2024
c70a285
style
yiyixuxu Oct 30, 2024
ffc2992
add autostep (not complete)
yiyixuxu Nov 16, 2024
ace53e2
update/refactor
yiyixuxu Dec 10, 2024
a8df0f1
Modular APG (#10173)
hlky Dec 10, 2024
e50d614
only add model as expected_component when the model need to run for t…
yiyixuxu Dec 11, 2024
bc3d1c9
add model_cpu_offload_seq + _exlude_from_cpu_offload
yiyixuxu Dec 13, 2024
2b3cd2d
update
yiyixuxu Dec 14, 2024
b305c77
add offload support!
yiyixuxu Dec 14, 2024
0b90051
add vae encoder node
yiyixuxu Dec 19, 2024
806e8e6
Merge branch 'main' into modular-diffusers
yiyixuxu Dec 29, 2024
4fa85c7
add model_manager and global offloading method
yiyixuxu Dec 31, 2024
72d9a81
components manager
yiyixuxu Dec 31, 2024
10d4a77
style
yiyixuxu Dec 31, 2024
27dde51
add output arg to run_blocks
yiyixuxu Dec 31, 2024
8c02572
add memory_reserve_margin arg to auto offload
yiyixuxu Dec 31, 2024
a09ca7f
refactors: block __init__ no longer accept args. remove update_state…
yiyixuxu Jan 1, 2025
ed59f90
modular pipeline builder -> ModularPipeline
yiyixuxu Jan 1, 2025
72c5bf0
add a from_block class method to modular pipeline
yiyixuxu Jan 1, 2025
6c93626
remove run_blocks, just use __call__
yiyixuxu Jan 1, 2025
1d63306
make it work with lora
yiyixuxu Jan 3, 2025
2e0f5c8
start to add inpaint
yiyixuxu Jan 3, 2025
c12a05b
update to to not assume pipeline has hf_device_map
yiyixuxu Jan 3, 2025
54f410d
add inpaint
yiyixuxu Jan 6, 2025
6985906
controlnet input & remove the MultiPipelineBlocks class
yiyixuxu Jan 7, 2025
db94ca8
add controlnet inpaint + more refactor
yiyixuxu Jan 7, 2025
e973de6
fix contro;net inpaint preprocess
yiyixuxu Jan 8, 2025
7a34832
[modular] Stable Diffusion XL ControlNet Union (#10509)
hlky Jan 9, 2025
2220af6
refactor
yiyixuxu Jan 11, 2025
fb78f4f
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jan 11, 2025
0966663
adjust print
yiyixuxu Jan 11, 2025
7f897a9
fix
yiyixuxu Jan 12, 2025
a6804de
add controlnet union to auto & fix for pag
yiyixuxu Jan 12, 2025
7007f72
InputParam, OutputParam, get_auto_doc
yiyixuxu Jan 16, 2025
a226920
get_block_state make it less verbose
yiyixuxu Jan 17, 2025
77b5fa5
make it work with lora has both text_encoder & unet
yiyixuxu Jan 18, 2025
6e2fe26
fix more for lora
yiyixuxu Jan 18, 2025
68a5185
refactor more, ipadapter node, lora node
yiyixuxu Jan 20, 2025
d046cf7
block state + fix for num_images_per_prompt > 1 for denoise/controlne…
yiyixuxu Jan 22, 2025
71df158
Update src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_di…
yiyixuxu Jan 22, 2025
b3fb418
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jan 22, 2025
00cae4e
docstring doc doc doc
yiyixuxu Jan 23, 2025
ccb35ac
Merge branch 'main' into modular-diffusers
yiyixuxu Jan 23, 2025
00a3bc9
fix
yiyixuxu Jan 23, 2025
4bed3e3
up up
yiyixuxu Jan 26, 2025
c7020df
add model_info
yiyixuxu Jan 27, 2025
2c3e4ea
fix
yiyixuxu Jan 29, 2025
e5089d7
update
yiyixuxu Jan 31, 2025
8ddb20b
up
yiyixuxu Feb 1, 2025
cff0fd6
more refactor
yiyixuxu Feb 1, 2025
485f8d1
more refactor
yiyixuxu Feb 1, 2025
addaad0
more more more refactor
yiyixuxu Feb 3, 2025
12650e1
up
yiyixuxu Feb 4, 2025
96795af
Merge branch 'main' into modular-diffusers
yiyixuxu Apr 8, 2025
6a509ba
Merge branch 'main' into modular-diffusers
yiyixuxu May 1, 2025
a8e853b
[modular diffusers] more refactor (#11235)
yiyixuxu Jun 20, 2025
7ad01a6
rename modular_pipeline_block_mappings.py to modular_block_mapping
yiyixuxu Jun 20, 2025
5a8c1b5
add block mappings to modular_diffusers.stable_diffusion_xl.__init__
yiyixuxu Jun 20, 2025
8913d59
add to method to modular loader, copied from DiffusionPipeline, not t…
yiyixuxu Jun 20, 2025
45392cc
update the description of StableDiffusionXLDenoiseLoopWrapper
yiyixuxu Jun 20, 2025
9e58856
add __repr__ method for InsertableOrderedDict
yiyixuxu Jun 21, 2025
04c16d0
update
yiyixuxu Jun 21, 2025
083479c
ordereddict -> insertableOrderedDict; make sure loader to method works
yiyixuxu Jun 21, 2025
4751d45
shorten loop subblock name
yiyixuxu Jun 22, 2025
d12531d
lora: only remove hooks that we add back
yiyixuxu Jun 22, 2025
19545fd
update components manager __repr__
yiyixuxu Jun 22, 2025
78d2454
fix
yiyixuxu Jun 23, 2025
085ade0
add doc (developer guide)
yiyixuxu Jun 23, 2025
42c06e9
update doc
yiyixuxu Jun 23, 2025
1ae591e
update code format
yiyixuxu Jun 23, 2025
bb40443
up
yiyixuxu Jun 23, 2025
7c78fb1
add a overview doc page
yiyixuxu Jun 24, 2025
48e4ff5
update overview
yiyixuxu Jun 24, 2025
e49413d
update doc
yiyixuxu Jun 25, 2025
ffbaa89
move save_pretrained to the correct place
yiyixuxu Jun 25, 2025
cdaaa40
update ComponentSpec.from_component, only update config if it is crea…
yiyixuxu Jun 25, 2025
1c9f0a8
ujpdate toctree
yiyixuxu Jun 25, 2025
174628e
Merge branch 'main' into modular-diffusers
yiyixuxu Jun 25, 2025
c0327e4
update init
yiyixuxu Jun 25, 2025
5917d70
remove lora related changes
yiyixuxu Jun 25, 2025
8c038f0
Update src/diffusers/loaders/lora_base.py
yiyixuxu Jun 25, 2025
cb328d3
Apply suggestions from code review
yiyixuxu Jun 25, 2025
7d2a633
style
yiyixuxu Jun 25, 2025
74b908b
style
yiyixuxu Jun 25, 2025
9530245
correct code format
yiyixuxu Jun 25, 2025
c437ae7
copies
yiyixuxu Jun 25, 2025
f3453f0
copy
yiyixuxu Jun 25, 2025
a82e211
style
yiyixuxu Jun 25, 2025
a33206d
fix
yiyixuxu Jun 25, 2025
75e6238
revert changes in pipelines.stable_diffusion_xl folder, can seperate …
yiyixuxu Jun 25, 2025
129d658
oops, fix
yiyixuxu Jun 25, 2025
da4242d
use diffusers ModelHook, raise a import error for accelerate inside e…
yiyixuxu Jun 26, 2025
ab6d634
style
yiyixuxu Jun 26, 2025
7492e33
fix
yiyixuxu Jun 26, 2025
b92cda2
move quicktour to first page
yiyixuxu Jun 26, 2025
61772f0
updatee a comment
yiyixuxu Jun 26, 2025
9abac85
remove mapping file, move to preeset.py
yiyixuxu Jun 26, 2025
84f4b27
modular_pipeline_presets.py -> modular_blocks_presets.py
yiyixuxu Jun 26, 2025
449f299
move all the sequential pipelines & auto pipelines to the blocks_pres…
yiyixuxu Jun 26, 2025
7608d2e
style
yiyixuxu Jun 26, 2025
f63d62e
intermediates_inputs -> intermediate_inputs; component_manager -> com…
yiyixuxu Jun 27, 2025
655512e
components manager: change get -> search_models; add get_ids, get_com…
yiyixuxu Jun 28, 2025
885a596
blocks -> sub_blocks; will not by default load all; add load_default…
yiyixuxu Jun 28, 2025
b543bcc
docstring blocks -> sub_blocks
yiyixuxu Jun 28, 2025
75540f4
more blocks -> sub_blocks
yiyixuxu Jun 28, 2025
93760b1
InsertableOrderedDict -> InsertableDict
yiyixuxu Jun 28, 2025
9aaec5b
up
yiyixuxu Jun 28, 2025
58dbe0c
finimsh the quickstart!
yiyixuxu Jun 28, 2025
49ea4d1
style
yiyixuxu Jun 28, 2025
92b6b43
add some visuals
yiyixuxu Jun 28, 2025
8c680bc
up
yiyixuxu Jun 28, 2025
fedaa00
Merge branch 'main' into modular-diffusers
yiyixuxu Jun 29, 2025
fdd2bed
2024 -> 2025; fix a circular import
yiyixuxu Jun 29, 2025
3a3441c
start the write your own pipeline block tutorial
yiyixuxu Jun 30, 2025
9fae382
Apply suggestions from code review
yiyixuxu Jun 30, 2025
b43e703
Update docs/source/en/modular_diffusers/write_own_pipeline_block.md
yiyixuxu Jun 30, 2025
c75b88f
up
yiyixuxu Jun 30, 2025
285f877
make InsertableDict importable from modular_pipelines
yiyixuxu Jun 30, 2025
f09b1cc
start the section on sequential pipelines
yiyixuxu Jun 30, 2025
c5849ba
more
yiyixuxu Jun 30, 2025
363737e
add loop sequential blocks
yiyixuxu Jun 30, 2025
bbd9340
up
yiyixuxu Jun 30, 2025
0138e17
remove the get_exeuction_blocks rec from AutoPipelineBlocks repr
yiyixuxu Jun 30, 2025
db4b54c
finish the autopipelines section!
yiyixuxu Jun 30, 2025
abf28d5
update
yiyixuxu Jun 30, 2025
4b12a60
Merge branch 'main' into modular-diffusers
yiyixuxu Jun 30, 2025
f27fbce
more attemp to fix circular import
yiyixuxu Jun 30, 2025
98ea5c9
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jun 30, 2025
b5db8aa
developer_guide -> end-to-end guide
yiyixuxu Jul 1, 2025
4543d21
rename quick start- it is really not quick
yiyixuxu Jul 1, 2025
1987c07
update docstree
yiyixuxu Jul 1, 2025
2e20241
up up
yiyixuxu Jul 1, 2025
13fe248
add modularpipelineblocks to be pushtohub mixin
yiyixuxu Jul 1, 2025
8cb5b08
up upup
yiyixuxu Jul 1, 2025
3e46c86
fix links in the doc
yiyixuxu Jul 1, 2025
13c51bb
Modular PAG Guider (#11860)
a-r-r-o-w Jul 4, 2025
b750c69
Modular Guider ConfigMixin (#11862)
a-r-r-o-w Jul 5, 2025
284f827
Modular custom config object serialization (#11868)
a-r-r-o-w Jul 5, 2025
2c66fb3
Apply suggestions from code review
yiyixuxu Jul 6, 2025
63e94cb
resolve conflicnt
yiyixuxu Jul 6, 2025
4f8b6f5
style + copy
yiyixuxu Jul 6, 2025
23de59e
add sub_blocks for pipelineBlock
yiyixuxu Jul 6, 2025
7cea9a3
add a guider section on doc
yiyixuxu Jul 7, 2025
0a4819a
add sub_folder to save_pretrained() for config mixin
yiyixuxu Jul 7, 2025
229c4b3
add from_pretrained/save_pretrained for guider
yiyixuxu Jul 7, 2025
179d6d9
add subfolder to push_to_hub
yiyixuxu Jul 7, 2025
5af003a
update from_componeenet, update_component
yiyixuxu Jul 7, 2025
0fcdd69
style
yiyixuxu Jul 7, 2025
ceeb3c1
fix
yiyixuxu Jul 7, 2025
0fcce2a
Merge branch 'main' into modular-diffusers
yiyixuxu Jul 7, 2025
6521f59
make sure modularpipeline from_pretrained works without modular_model…
yiyixuxu Jul 7, 2025
e0083b2
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jul 7, 2025
863c7df
components manager: use shorter ID, display id instead of name
yiyixuxu Jul 8, 2025
a2da000
add a guide on components manager
yiyixuxu Jul 8, 2025
be5e10a
Copied-from implementation of PAG-guider (#11882)
a-r-r-o-w Jul 8, 2025
04171c7
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jul 8, 2025
e6ffde2
Apply suggestions from code review
yiyixuxu Jul 8, 2025
5f3ebef
update remove duplicated config for pag, and remove the description o…
yiyixuxu Jul 8, 2025
59abd95
add link to components manager doc
yiyixuxu Jul 8, 2025
f95c320
addreess more review comments
yiyixuxu Jul 8, 2025
79166dc
Merge branch 'main' into modular-diffusers
yiyixuxu Jul 8, 2025
cb9dca5
add experimental marks to all modular docs
yiyixuxu Jul 8, 2025
d27b654
add more docstrings + experimental marks
yiyixuxu Jul 8, 2025
595581d
style
yiyixuxu Jul 8, 2025
73c5fe8
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jul 8, 2025
de7cdf6
Merge modular diffusers with main (#11893)
a-r-r-o-w Jul 9, 2025
a935bea
big doc updategit status!
yiyixuxu Jul 9, 2025
2b006a2
Merge branch 'modular-diffusers' of github.com:huggingface/diffusers …
yiyixuxu Jul 9, 2025
9106f9c
Merge branch 'main' into modular-diffusers
a-r-r-o-w Jul 9, 2025
cf0f8e5
Merge branch 'main' into modular-diffusers
a-r-r-o-w Jul 9, 2025
2104bef
update more modular pipeline doc
yiyixuxu Jul 9, 2025
65ba892
update doc
yiyixuxu Jul 9, 2025
01300a3
up
yiyixuxu Jul 10, 2025
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
Prev Previous commit
Next Next commit
add dataflow info for each block in builder _repr_
  • Loading branch information
yiyixuxu committed Oct 16, 2024
commit 52a7f1cb971cd402721f8e11a45f6dbbd12fe42a
104 changes: 104 additions & 0 deletions src/diffusers/pipelines/custom_pipeline_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,94 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype
latents = latents * self.scheduler.init_noise_sigma
return latents

# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl_img2img.StableDiffusionXLImg2ImgPipeline.prepare_latents
def prepare_latents_img2img(
self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None, add_noise=True
):
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
raise ValueError(
f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
)

latents_mean = latents_std = None
if hasattr(self.vae.config, "latents_mean") and self.vae.config.latents_mean is not None:
latents_mean = torch.tensor(self.vae.config.latents_mean).view(1, 4, 1, 1)
if hasattr(self.vae.config, "latents_std") and self.vae.config.latents_std is not None:
latents_std = torch.tensor(self.vae.config.latents_std).view(1, 4, 1, 1)

# Offload text encoder if `enable_model_cpu_offload` was enabled
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
self.text_encoder_2.to("cpu")
torch.cuda.empty_cache()

image = image.to(device=device, dtype=dtype)

batch_size = batch_size * num_images_per_prompt

if image.shape[1] == 4:
init_latents = image

else:
# make sure the VAE is in float32 mode, as it overflows in float16
if self.vae.config.force_upcast:
image = image.float()
self.vae.to(dtype=torch.float32)

if isinstance(generator, list) and len(generator) != batch_size:
raise ValueError(
f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
f" size of {batch_size}. Make sure the batch size matches the length of the generators."
)

elif isinstance(generator, list):
if image.shape[0] < batch_size and batch_size % image.shape[0] == 0:
image = torch.cat([image] * (batch_size // image.shape[0]), dim=0)
elif image.shape[0] < batch_size and batch_size % image.shape[0] != 0:
raise ValueError(
f"Cannot duplicate `image` of batch size {image.shape[0]} to effective batch_size {batch_size} "
)

init_latents = [
retrieve_latents(self.vae.encode(image[i : i + 1]), generator=generator[i])
for i in range(batch_size)
]
init_latents = torch.cat(init_latents, dim=0)
else:
init_latents = retrieve_latents(self.vae.encode(image), generator=generator)

if self.vae.config.force_upcast:
self.vae.to(dtype)

init_latents = init_latents.to(dtype)
if latents_mean is not None and latents_std is not None:
latents_mean = latents_mean.to(device=device, dtype=dtype)
latents_std = latents_std.to(device=device, dtype=dtype)
init_latents = (init_latents - latents_mean) * self.vae.config.scaling_factor / latents_std
else:
init_latents = self.vae.config.scaling_factor * init_latents

if batch_size > init_latents.shape[0] and batch_size % init_latents.shape[0] == 0:
# expand init_latents for batch_size
additional_image_per_prompt = batch_size // init_latents.shape[0]
init_latents = torch.cat([init_latents] * additional_image_per_prompt, dim=0)
elif batch_size > init_latents.shape[0] and batch_size % init_latents.shape[0] != 0:
raise ValueError(
f"Cannot duplicate `image` of batch size {init_latents.shape[0]} to {batch_size} text prompts."
)
else:
init_latents = torch.cat([init_latents], dim=0)

if add_noise:
shape = init_latents.shape
noise = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
# get latents
init_latents = self.scheduler.add_noise(init_latents, noise, timestep)

latents = init_latents

return latents


# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs
def prepare_extra_step_kwargs(self, generator, eta):
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
Expand Down Expand Up @@ -1743,6 +1831,22 @@ def __repr__(self):
output += "----------------\n"
for i, block in enumerate(self.pipeline_blocks, 1):
output += f"{i}. {block.__class__.__name__}\n"

intermediates_str = ""
if hasattr(block, 'intermediates_inputs'):
intermediates_str += f"{', '.join(block.intermediates_inputs)}"

if hasattr(block, 'intermediates_outputs'):
if intermediates_str:
intermediates_str += " -> "
else:
intermediates_str += "-> "
intermediates_str += f"{', '.join(block.intermediates_outputs)}"

if intermediates_str:
output += f" {intermediates_str}\n"

output += "\n"
output += "\n"

# List the components registered in the pipeline
Expand Down
0