From 55ac1dbdf2e77dcc93b0fa87d638d074219922e4 Mon Sep 17 00:00:00 2001 From: hlky Date: Fri, 27 Dec 2024 17:58:49 +0000 Subject: [PATCH] Default values in SD3 pipelines when submodules are not loaded (#10393) SD3 pipelines hasattr --- .../pipeline_stable_diffusion_3_img2img.py | 17 +++++++++++++---- .../pipeline_stable_diffusion_3_inpaint.py | 19 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py b/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py index c10401324430..77daf5b0b4e0 100644 --- a/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +++ b/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py @@ -226,12 +226,21 @@ def __init__( transformer=transformer, scheduler=scheduler, ) - self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) + self.vae_scale_factor = ( + 2 ** (len(self.vae.config.block_out_channels) - 1) if hasattr(self, "vae") and self.vae is not None else 8 + ) + latent_channels = self.vae.config.latent_channels if hasattr(self, "vae") and self.vae is not None else 16 self.image_processor = VaeImageProcessor( - vae_scale_factor=self.vae_scale_factor, vae_latent_channels=self.vae.config.latent_channels + vae_scale_factor=self.vae_scale_factor, vae_latent_channels=latent_channels + ) + self.tokenizer_max_length = ( + self.tokenizer.model_max_length if hasattr(self, "tokenizer") and self.tokenizer is not None else 77 + ) + self.default_sample_size = ( + self.transformer.config.sample_size + if hasattr(self, "transformer") and self.transformer is not None + else 128 ) - self.tokenizer_max_length = self.tokenizer.model_max_length - self.default_sample_size = self.transformer.config.sample_size self.patch_size = ( self.transformer.config.patch_size if hasattr(self, "transformer") and self.transformer is not None else 2 ) diff --git a/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py b/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py index ca32880d0df2..e1cfdb3e6e97 100644 --- a/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +++ b/src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py @@ -225,19 +225,28 @@ def __init__( transformer=transformer, scheduler=scheduler, ) - self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) + self.vae_scale_factor = ( + 2 ** (len(self.vae.config.block_out_channels) - 1) if hasattr(self, "vae") and self.vae is not None else 8 + ) + latent_channels = self.vae.config.latent_channels if hasattr(self, "vae") and self.vae is not None else 16 self.image_processor = VaeImageProcessor( - vae_scale_factor=self.vae_scale_factor, vae_latent_channels=self.vae.config.latent_channels + vae_scale_factor=self.vae_scale_factor, vae_latent_channels=latent_channels ) self.mask_processor = VaeImageProcessor( vae_scale_factor=self.vae_scale_factor, - vae_latent_channels=self.vae.config.latent_channels, + vae_latent_channels=latent_channels, do_normalize=False, do_binarize=True, do_convert_grayscale=True, ) - self.tokenizer_max_length = self.tokenizer.model_max_length - self.default_sample_size = self.transformer.config.sample_size + self.tokenizer_max_length = ( + self.tokenizer.model_max_length if hasattr(self, "tokenizer") and self.tokenizer is not None else 77 + ) + self.default_sample_size = ( + self.transformer.config.sample_size + if hasattr(self, "transformer") and self.transformer is not None + else 128 + ) self.patch_size = ( self.transformer.config.patch_size if hasattr(self, "transformer") and self.transformer is not None else 2 )