@@ -1773,7 +1773,7 @@ def denoising_value_valid(dnv):
1773
1773
f"Incorrect configuration settings! The config of `pipeline.unet`: { self .unet .config } expects"
1774
1774
f" { self .unet .config .in_channels } but received `num_channels_latents`: { num_channels_latents } +"
1775
1775
f" `num_channels_mask`: { num_channels_mask } + `num_channels_masked_image`: { num_channels_masked_image } "
1776
- f" = { num_channels_latents + num_channels_masked_image + num_channels_mask } . Please verify the config of"
1776
+ f" = { num_channels_latents + num_channels_masked_image + num_channels_mask } . Please verify the config of"
1777
1777
" `pipeline.unet` or your `mask_image` or `image` input."
1778
1778
)
1779
1779
elif num_channels_unet != 4 :
@@ -1924,7 +1924,22 @@ def denoising_value_valid(dnv):
1924
1924
self .upcast_vae ()
1925
1925
latents = latents .to (next (iter (self .vae .post_quant_conv .parameters ())).dtype )
1926
1926
1927
- image = self .vae .decode (latents / self .vae .config .scaling_factor , return_dict = False )[0 ]
1927
+ # unscale/denormalize the latents
1928
+ # denormalize with the mean and std if available and not None
1929
+ has_latents_mean = hasattr (self .vae .config , "latents_mean" ) and self .vae .config .latents_mean is not None
1930
+ has_latents_std = hasattr (self .vae .config , "latents_std" ) and self .vae .config .latents_std is not None
1931
+ if has_latents_mean and has_latents_std :
1932
+ latents_mean = (
1933
+ torch .tensor (self .vae .config .latents_mean ).view (1 , 4 , 1 , 1 ).to (latents .device , latents .dtype )
1934
+ )
1935
+ latents_std = (
1936
+ torch .tensor (self .vae .config .latents_std ).view (1 , 4 , 1 , 1 ).to (latents .device , latents .dtype )
1937
+ )
1938
+ latents = latents * latents_std / self .vae .config .scaling_factor + latents_mean
1939
+ else :
1940
+ latents = latents / self .vae .config .scaling_factor
1941
+
1942
+ image = self .vae .decode (latents , return_dict = False )[0 ]
1928
1943
1929
1944
# cast back to fp16 if needed
1930
1945
if needs_upcasting :
0 commit comments