From 7de40f33a4feba27b479f1a9b359058e839b34a2 Mon Sep 17 00:00:00 2001 From: Hu Ye Date: Fri, 7 Jul 2023 11:10:27 +0800 Subject: [PATCH 1/4] Update pipeline_stable_diffusion_xl.py fix a bug --- .../stable_diffusion_xl/pipeline_stable_diffusion_xl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py index 142aac94b99d..02c7032de99d 100644 --- a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +++ b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py @@ -749,15 +749,15 @@ def __call__( # make sure the VAE is in float32 mode, as it overflows in float16 self.vae.to(dtype=torch.float32) - use_torch_2_0_or_xformers = self.vae.decoder.mid_block.attentions[0].processor in [ + use_torch_2_0_or_xformers = isinstance(self.vae.decoder.mid_block.attentions[0].processor, ( AttnProcessor2_0, XFormersAttnProcessor, LoRAXFormersAttnProcessor, LoRAAttnProcessor2_0, - ] + )) # if xformers or torch_2_0 is used attention block does not need # to be in float32 which can save lots of memory - if not use_torch_2_0_or_xformers: + if use_torch_2_0_or_xformers: self.vae.post_quant_conv.to(latents.dtype) self.vae.decoder.conv_in.to(latents.dtype) self.vae.decoder.mid_block.to(latents.dtype) From 7b4d457a941de381d8be1cbc9a529767dc3cc6bf Mon Sep 17 00:00:00 2001 From: Hu Ye Date: Fri, 7 Jul 2023 11:12:08 +0800 Subject: [PATCH 2/4] Update pipeline_stable_diffusion_xl_img2img.py --- .../pipeline_stable_diffusion_xl_img2img.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py index f699e2331027..83109c6a5dd9 100644 --- a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py @@ -845,15 +845,15 @@ def __call__( # make sure the VAE is in float32 mode, as it overflows in float16 self.vae.to(dtype=torch.float32) - use_torch_2_0_or_xformers = self.vae.decoder.mid_block.attentions[0].processor in [ + use_torch_2_0_or_xformers = isinstance(self.vae.decoder.mid_block.attentions[0].processor in ( AttnProcessor2_0, XFormersAttnProcessor, LoRAXFormersAttnProcessor, LoRAAttnProcessor2_0, - ] + )) # if xformers or torch_2_0 is used attention block does not need # to be in float32 which can save lots of memory - if not use_torch_2_0_or_xformers: + if use_torch_2_0_or_xformers: self.vae.post_quant_conv.to(latents.dtype) self.vae.decoder.conv_in.to(latents.dtype) self.vae.decoder.mid_block.to(latents.dtype) From 13835048653c2f77b3bfc6e76b18a8ffb5e6edef Mon Sep 17 00:00:00 2001 From: Hu Ye Date: Fri, 7 Jul 2023 11:13:43 +0800 Subject: [PATCH 3/4] Update pipeline_stable_diffusion_xl_img2img.py --- .../stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py index 83109c6a5dd9..792b0bb90959 100644 --- a/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py @@ -845,7 +845,7 @@ def __call__( # make sure the VAE is in float32 mode, as it overflows in float16 self.vae.to(dtype=torch.float32) - use_torch_2_0_or_xformers = isinstance(self.vae.decoder.mid_block.attentions[0].processor in ( + use_torch_2_0_or_xformers = isinstance(self.vae.decoder.mid_block.attentions[0].processor, ( AttnProcessor2_0, XFormersAttnProcessor, LoRAXFormersAttnProcessor, From e507361d8d1aae7533739eaedf39a715d32c6b89 Mon Sep 17 00:00:00 2001 From: Hu Ye Date: Sat, 8 Jul 2023 13:34:36 +0800 Subject: [PATCH 4/4] Update pipeline_stable_diffusion_upscale.py --- .../stable_diffusion/pipeline_stable_diffusion_upscale.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py index 48283bf31156..1a7832030b46 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py @@ -748,12 +748,13 @@ def __call__( # make sure the VAE is in float32 mode, as it overflows in float16 self.vae.to(dtype=torch.float32) - use_torch_2_0_or_xformers = self.vae.decoder.mid_block.attentions[0].processor in [ + use_torch_2_0_or_xformers = isinstance(self.vae.decoder.mid_block.attentions[0].processor, ( AttnProcessor2_0, XFormersAttnProcessor, LoRAXFormersAttnProcessor, LoRAAttnProcessor2_0, - ] + )) + # if xformers or torch_2_0 is used attention block does not need # to be in float32 which can save lots of memory if not use_torch_2_0_or_xformers: