Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
76a62ac9
Unverified
Commit
76a62ac9
authored
Jul 10, 2025
by
Álvaro Somoza
Committed by
GitHub
Jul 10, 2025
Browse files
[ControlnetUnion] Multiple Fixes (#11888)
fixes --------- Co-authored-by:
hlky
<
hlky@hlky.ac
>
parent
1c6ab9e9
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
223 additions
and
100 deletions
+223
-100
src/diffusers/models/controlnets/controlnet_union.py
src/diffusers/models/controlnets/controlnet_union.py
+4
-4
src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py
...nes/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py
+212
-93
src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py
...s/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py
+7
-3
No files found.
src/diffusers/models/controlnets/controlnet_union.py
View file @
76a62ac9
...
...
@@ -752,7 +752,7 @@ class ControlNetUnionModel(ModelMixin, ConfigMixin, FromOriginalModelMixin):
condition
=
self
.
controlnet_cond_embedding
(
cond
)
feat_seq
=
torch
.
mean
(
condition
,
dim
=
(
2
,
3
))
feat_seq
=
feat_seq
+
self
.
task_embedding
[
control_idx
]
if
from_multi
:
if
from_multi
or
len
(
control_type_idx
)
==
1
:
inputs
.
append
(
feat_seq
.
unsqueeze
(
1
))
condition_list
.
append
(
condition
)
else
:
...
...
@@ -772,7 +772,7 @@ class ControlNetUnionModel(ModelMixin, ConfigMixin, FromOriginalModelMixin):
for
(
idx
,
condition
),
scale
in
zip
(
enumerate
(
condition_list
[:
-
1
]),
conditioning_scale
):
alpha
=
self
.
spatial_ch_projs
(
x
[:,
idx
])
alpha
=
alpha
.
unsqueeze
(
-
1
).
unsqueeze
(
-
1
)
if
from_multi
:
if
from_multi
or
len
(
control_type_idx
)
==
1
:
controlnet_cond_fuser
+=
condition
+
alpha
else
:
controlnet_cond_fuser
+=
condition
+
alpha
*
scale
...
...
@@ -819,11 +819,11 @@ class ControlNetUnionModel(ModelMixin, ConfigMixin, FromOriginalModelMixin):
# 6. scaling
if
guess_mode
and
not
self
.
config
.
global_pool_conditions
:
scales
=
torch
.
logspace
(
-
1
,
0
,
len
(
down_block_res_samples
)
+
1
,
device
=
sample
.
device
)
# 0.1 to 1.0
if
from_multi
:
if
from_multi
or
len
(
control_type_idx
)
==
1
:
scales
=
scales
*
conditioning_scale
[
0
]
down_block_res_samples
=
[
sample
*
scale
for
sample
,
scale
in
zip
(
down_block_res_samples
,
scales
)]
mid_block_res_sample
=
mid_block_res_sample
*
scales
[
-
1
]
# last one
elif
from_multi
:
elif
from_multi
or
len
(
control_type_idx
)
==
1
:
down_block_res_samples
=
[
sample
*
conditioning_scale
[
0
]
for
sample
in
down_block_res_samples
]
mid_block_res_sample
=
mid_block_res_sample
*
conditioning_scale
[
0
]
...
...
src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py
View file @
76a62ac9
This diff is collapsed.
Click to expand it.
src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py
View file @
76a62ac9
...
...
@@ -1452,17 +1452,21 @@ class StableDiffusionXLControlNetUnionPipeline(
is_controlnet_compiled
=
is_compiled_module
(
self
.
controlnet
)
is_torch_higher_equal_2_1
=
is_torch_version
(
">="
,
"2.1"
)
control_type_repeat_factor
=
(
batch_size
*
num_images_per_prompt
*
(
2
if
self
.
do_classifier_free_guidance
else
1
)
)
if
isinstance
(
controlnet
,
ControlNetUnionModel
):
control_type
=
(
control_type
.
reshape
(
1
,
-
1
)
.
to
(
self
.
_execution_device
,
dtype
=
prompt_embeds
.
dtype
)
.
repeat
(
batch_size
*
num_images_per_prompt
*
2
,
1
)
.
repeat
(
control_type_repeat_factor
,
1
)
)
if
isinstance
(
controlnet
,
MultiControlNetUnionModel
):
el
if
isinstance
(
controlnet
,
MultiControlNetUnionModel
):
control_type
=
[
_control_type
.
reshape
(
1
,
-
1
)
.
to
(
self
.
_execution_device
,
dtype
=
prompt_embeds
.
dtype
)
.
repeat
(
batch_size
*
num_images_per_prompt
*
2
,
1
)
.
repeat
(
control_type_repeat_factor
,
1
)
for
_control_type
in
control_type
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment