From e4b788e0fb39d6197535aa05a5cae4eb605cf307 Mon Sep 17 00:00:00 2001 From: hectorlopezhernandez Date: Mon, 13 Nov 2023 10:25:44 -0800 Subject: [PATCH] bugfix: updated scaling factor for SDXL --- python_coreml_stable_diffusion/pipeline.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python_coreml_stable_diffusion/pipeline.py b/python_coreml_stable_diffusion/pipeline.py index c00a743..6a9a513 100644 --- a/python_coreml_stable_diffusion/pipeline.py +++ b/python_coreml_stable_diffusion/pipeline.py @@ -311,7 +311,14 @@ def run_safety_checker(self, image): return image, has_nsfw_concept def decode_latents(self, latents): - latents = 1 / 0.18215 * latents + + if self.xl: + scaling_factor =0.13025 + else: + scaling_factor = 0.18215 + + latents = 1 / scaling_factor * latents + dtype = self.vae_decoder.expected_inputs['z']['dtype'] image = self.vae_decoder(z=latents.astype(dtype))["image"] image = np.clip(image / 2 + 0.5, 0, 1)