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
d6f4774c
Unverified
Commit
d6f4774c
authored
Mar 31, 2025
by
hlky
Committed by
GitHub
Mar 31, 2025
Browse files
Add `latents_mean` and `latents_std` to `SDXLLongPromptWeightingPipeline` (#11034)
parent
eb50deff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
examples/community/lpw_stable_diffusion_xl.py
examples/community/lpw_stable_diffusion_xl.py
+17
-2
No files found.
examples/community/lpw_stable_diffusion_xl.py
View file @
d6f4774c
...
...
@@ -1773,7 +1773,7 @@ class SDXLLongPromptWeightingPipeline(
f
"Incorrect configuration settings! The config of `pipeline.unet`:
{
self
.
unet
.
config
}
expects"
f
"
{
self
.
unet
.
config
.
in_channels
}
but received `num_channels_latents`:
{
num_channels_latents
}
+"
f
" `num_channels_mask`:
{
num_channels_mask
}
+ `num_channels_masked_image`:
{
num_channels_masked_image
}
"
f
" =
{
num_channels_latents
+
num_channels_masked_image
+
num_channels_mask
}
. Please verify the config of"
f
" =
{
num_channels_latents
+
num_channels_masked_image
+
num_channels_mask
}
. Please verify the config of"
" `pipeline.unet` or your `mask_image` or `image` input."
)
elif
num_channels_unet
!=
4
:
...
...
@@ -1924,7 +1924,22 @@ class SDXLLongPromptWeightingPipeline(
self
.
upcast_vae
()
latents
=
latents
.
to
(
next
(
iter
(
self
.
vae
.
post_quant_conv
.
parameters
())).
dtype
)
image
=
self
.
vae
.
decode
(
latents
/
self
.
vae
.
config
.
scaling_factor
,
return_dict
=
False
)[
0
]
# unscale/denormalize the latents
# denormalize with the mean and std if available and not None
has_latents_mean
=
hasattr
(
self
.
vae
.
config
,
"latents_mean"
)
and
self
.
vae
.
config
.
latents_mean
is
not
None
has_latents_std
=
hasattr
(
self
.
vae
.
config
,
"latents_std"
)
and
self
.
vae
.
config
.
latents_std
is
not
None
if
has_latents_mean
and
has_latents_std
:
latents_mean
=
(
torch
.
tensor
(
self
.
vae
.
config
.
latents_mean
).
view
(
1
,
4
,
1
,
1
).
to
(
latents
.
device
,
latents
.
dtype
)
)
latents_std
=
(
torch
.
tensor
(
self
.
vae
.
config
.
latents_std
).
view
(
1
,
4
,
1
,
1
).
to
(
latents
.
device
,
latents
.
dtype
)
)
latents
=
latents
*
latents_std
/
self
.
vae
.
config
.
scaling_factor
+
latents_mean
else
:
latents
=
latents
/
self
.
vae
.
config
.
scaling_factor
image
=
self
.
vae
.
decode
(
latents
,
return_dict
=
False
)[
0
]
# cast back to fp16 if needed
if
needs_upcasting
:
...
...
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