-
Couldn't load subscription status.
- Fork 6.5k
Improve control net block index for sd3 #9758
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
Changes from 14 commits
a0d199a
48b4b62
d1a1ebe
bd32b2b
a7ffec7
235b800
50b4db9
933ecf3
9d33417
cd3069c
e40bd61
4c1d293
d8006c3
b4983cb
5f560ca
570558b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| import torch | ||
| import torch.nn as nn | ||
| import numpy as np | ||
|
|
||
| from ...configuration_utils import ConfigMixin, register_to_config | ||
| from ...loaders import FromOriginalModelMixin, PeftAdapterMixin | ||
|
|
@@ -344,7 +345,8 @@ def custom_forward(*inputs): | |
|
|
||
| # controlnet residual | ||
| if block_controlnet_hidden_states is not None and block.context_pre_only is False: | ||
| interval_control = len(self.transformer_blocks) // len(block_controlnet_hidden_states) | ||
| interval_control = len(self.transformer_blocks) / len(block_controlnet_hidden_states) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we making this change? it is not the same so a breaking change, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yiyixuxu Good question. The revised code adapts the strategy used by ControlNet for Flux, introducing a significant improvement in flexibility. Here's why this change matters: In the old code, the number of transformer layers is divisible by the number of ControlNet layers. For example, with SD3.5 Large, which has 38 transformer layers, there were only two valid options for the number of ControlNet layers: 2 and 19. Setting the number of ControlNet layers to anything else, such as 5, would cause the old code to crash. However, the Flux ControlNet approach removes this restriction, allowing greater flexibility in choosing the number of layers. The revised logic essentially mirrors the Flux implementation, enabling more versatile configurations. Importantly, the new code maintains compatibility with existing setups. If the number of transformer layers is divisible by the number of ControlNet layers, the interval_control remains unchanged, ensuring all previous configurations continue to function seamlessly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! I think it's indeed better, I'm just wondering if it would cause issue for controlnet is trained with the current logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it will cause any issue with the trained controlnet using old code before this PR. The reason is that for the controlnet to be trained with the old code, the number of layers of the transformer has to be divisible by the number of layers of the controlnet, and the new logic after this PR does not change the behavior for the above scenario. |
||
| interval_control = int(np.ceil(interval_control)) | ||
| hidden_states = hidden_states + block_controlnet_hidden_states[index_block // interval_control] | ||
|
|
||
| hidden_states = self.norm_out(hidden_states, temb) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.