-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Add ability to mix usage of T2I-Adapter(s) and ControlNet(s). #5362
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
Add ability to mix usage of T2I-Adapter(s) and ControlNet(s). #5362
Conversation
Previously, UNet2DConditional implemnetation onloy allowed use of one or the other. Adds new forward() arg down_intrablock_additional_residuals specifically for T2I-Adapters. If down_intrablock_addtional_residuals is not used, maintains backward compatibility with prior usage of only T2I-Adapter or ControlNet but not both
…ss_attention_controlled_conditioning() to reflect changes to T2I-Adapter implementation to allow usage of T2I-Adapter and ControlNet at the same time. Also, the PREVIOUS commit (@8d3885d, which was already pushed to github repo) was wrongly commented, but too late to fix without a force push or other mucking that I'm reluctant to do. That commit is actually the one that has all the changes to diffusers_pipeline.py to use additional arg down_intrablock_additional_residuals (introduced in diffusers PR huggingface/diffusers#5362) to detangle T2I-Adapter from ControlNet inputs to main UNet.
…n.py Co-authored-by: psychedelicious <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change makes sense to me - we should try to keep UNet2D as general as possible to allow for such use cases.
Before merging it would be good to:
- 1.) Adapt all T2I pipelines to pass
down_intrablock_additional_residuals
instead ofdown_block_additional_residuals
- 2.) Add a test that makes sure that the legacy format is still supported.
Also I'd very much like to get a review from @williamberman here
@@ -778,6 +778,7 @@ def forward( | |||
added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None, | |||
down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None, | |||
mid_block_additional_residual: Optional[torch.Tensor] = None, | |||
down_intrablock_additional_residuals: Optional[Tuple[torch.Tensor]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for me! Think it's indeed a good idea to cleanly separate ControlNet and T2I here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this, down_intrablock_additional_residuals
is a bit of a wonky name so if there is a better name we can come up with (I can't think of one), that would be great but if not lgtm
… T2I-Adapter (intrablock residuals) Co-authored-by: Patrick von Platen <[email protected]>
…/diffusers into mix-controlnet-and-t2iadapter
…rg for T2I-Adapter residuals.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
Tests are passing, PR is a nice refactor that disentangles two concepts that used the same function input. Will fix quality test directly on main. |
Thanks all for the quick reviews and feedback! |
…ss_attention_controlled_conditioning() to reflect changes to T2I-Adapter implementation to allow usage of T2I-Adapter and ControlNet at the same time. Also, the PREVIOUS commit (@8d3885d, which was already pushed to github repo) was wrongly commented, but too late to fix without a force push or other mucking that I'm reluctant to do. That commit is actually the one that has all the changes to diffusers_pipeline.py to use additional arg down_intrablock_additional_residuals (introduced in diffusers PR huggingface/diffusers#5362) to detangle T2I-Adapter from ControlNet inputs to main UNet.
…ss_attention_controlled_conditioning() to reflect changes to T2I-Adapter implementation to allow usage of T2I-Adapter and ControlNet at the same time. Also, the PREVIOUS commit (@8d3885d, which was already pushed to github repo) was wrongly commented, but too late to fix without a force push or other mucking that I'm reluctant to do. That commit is actually the one that has all the changes to diffusers_pipeline.py to use additional arg down_intrablock_additional_residuals (introduced in diffusers PR huggingface/diffusers#5362) to detangle T2I-Adapter from ControlNet inputs to main UNet.
…gface#5362) * Add ability to mix usage of T2I-Adapter(s) and ControlNet(s). Previously, UNet2DConditional implemnetation onloy allowed use of one or the other. Adds new forward() arg down_intrablock_additional_residuals specifically for T2I-Adapters. If down_intrablock_addtional_residuals is not used, maintains backward compatibility with prior usage of only T2I-Adapter or ControlNet but not both * Improving forward() arg docs in src/diffusers/models/unet_2d_condition.py Co-authored-by: psychedelicious <[email protected]> * Add deprecation warning if down_block_additional_residues is used for T2I-Adapter (intrablock residuals) Co-authored-by: Patrick von Platen <[email protected]> * Oops my bad, fixing last commit. * Added import of diffusers utils.deprecate * Conform to max line length * Modifying T2I-Adapter pipelines to reflect change to UNet forward() arg for T2I-Adapter residuals. --------- Co-authored-by: psychedelicious <[email protected]> Co-authored-by: Patrick von Platen <[email protected]>
…gface#5362) * Add ability to mix usage of T2I-Adapter(s) and ControlNet(s). Previously, UNet2DConditional implemnetation onloy allowed use of one or the other. Adds new forward() arg down_intrablock_additional_residuals specifically for T2I-Adapters. If down_intrablock_addtional_residuals is not used, maintains backward compatibility with prior usage of only T2I-Adapter or ControlNet but not both * Improving forward() arg docs in src/diffusers/models/unet_2d_condition.py Co-authored-by: psychedelicious <[email protected]> * Add deprecation warning if down_block_additional_residues is used for T2I-Adapter (intrablock residuals) Co-authored-by: Patrick von Platen <[email protected]> * Oops my bad, fixing last commit. * Added import of diffusers utils.deprecate * Conform to max line length * Modifying T2I-Adapter pipelines to reflect change to UNet forward() arg for T2I-Adapter residuals. --------- Co-authored-by: psychedelicious <[email protected]> Co-authored-by: Patrick von Platen <[email protected]>
What does this PR do?
Adds ability to mix usage of T2I-Adapter(s) and ControlNet(s). Previously, UNet2DConditional implementation only allowed use of one or the other. Adds new forward() arg
down_intrablock_additional_residuals
specifically for T2I-Adapters. Ifdown_intrablock_addtional_residuals
is not used, maintains backward compatibility with prior usage of only T2I-Adapter or ControlNet but not both, viadown_block_additional_residuals
andmid_block_additional_residual args
.Here's an example of mixing T2I-Adapter and ControNets with this fix, (in an InvokeAI dev branch). From left to right: original image, then inference with prompt "old man" and same seed -- ControlNet Canny, T2I-Adapter Color, both applied together.

Fixes # (issue)
Before submitting
The problem with combined use of T2I-Adapter and ControlNet was mentioned during initial discussions of diffusers T2I-Adapter implementation
I added documentation for UNet2DConditional.forward() existing args
down_block_additional_residuals
andmid_block_additional_residual
and new argdown_intrablock_additional_residuals
Who can review?
@patrickvonplaten
@sayakpaul
@williamberman