diffusers 0.23.1__py3-none-any.whl → 0.25.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. diffusers/__init__.py +26 -2
  2. diffusers/commands/fp16_safetensors.py +10 -11
  3. diffusers/configuration_utils.py +13 -8
  4. diffusers/dependency_versions_check.py +0 -1
  5. diffusers/dependency_versions_table.py +5 -5
  6. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  7. diffusers/image_processor.py +463 -51
  8. diffusers/loaders/__init__.py +82 -0
  9. diffusers/loaders/ip_adapter.py +159 -0
  10. diffusers/loaders/lora.py +1553 -0
  11. diffusers/loaders/lora_conversion_utils.py +284 -0
  12. diffusers/loaders/single_file.py +637 -0
  13. diffusers/loaders/textual_inversion.py +455 -0
  14. diffusers/loaders/unet.py +828 -0
  15. diffusers/loaders/utils.py +59 -0
  16. diffusers/models/__init__.py +26 -9
  17. diffusers/models/activations.py +9 -6
  18. diffusers/models/attention.py +301 -29
  19. diffusers/models/attention_flax.py +9 -1
  20. diffusers/models/attention_processor.py +378 -6
  21. diffusers/models/autoencoders/__init__.py +5 -0
  22. diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +17 -12
  23. diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +47 -23
  24. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +402 -0
  25. diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +24 -28
  26. diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +51 -44
  27. diffusers/models/{vae.py → autoencoders/vae.py} +71 -17
  28. diffusers/models/controlnet.py +59 -39
  29. diffusers/models/controlnet_flax.py +19 -18
  30. diffusers/models/downsampling.py +338 -0
  31. diffusers/models/embeddings.py +112 -29
  32. diffusers/models/embeddings_flax.py +2 -0
  33. diffusers/models/lora.py +131 -1
  34. diffusers/models/modeling_flax_utils.py +14 -8
  35. diffusers/models/modeling_outputs.py +17 -0
  36. diffusers/models/modeling_utils.py +37 -29
  37. diffusers/models/normalization.py +110 -4
  38. diffusers/models/resnet.py +299 -652
  39. diffusers/models/transformer_2d.py +22 -5
  40. diffusers/models/transformer_temporal.py +183 -1
  41. diffusers/models/unet_2d_blocks_flax.py +5 -0
  42. diffusers/models/unet_2d_condition.py +46 -0
  43. diffusers/models/unet_2d_condition_flax.py +13 -13
  44. diffusers/models/unet_3d_blocks.py +957 -173
  45. diffusers/models/unet_3d_condition.py +16 -8
  46. diffusers/models/unet_kandinsky3.py +535 -0
  47. diffusers/models/unet_motion_model.py +48 -33
  48. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  49. diffusers/models/upsampling.py +454 -0
  50. diffusers/models/uvit_2d.py +471 -0
  51. diffusers/models/vae_flax.py +7 -0
  52. diffusers/models/vq_model.py +12 -3
  53. diffusers/optimization.py +16 -9
  54. diffusers/pipelines/__init__.py +137 -76
  55. diffusers/pipelines/amused/__init__.py +62 -0
  56. diffusers/pipelines/amused/pipeline_amused.py +328 -0
  57. diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
  58. diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
  59. diffusers/pipelines/animatediff/pipeline_animatediff.py +66 -8
  60. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  61. diffusers/pipelines/auto_pipeline.py +23 -13
  62. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  63. diffusers/pipelines/controlnet/pipeline_controlnet.py +238 -35
  64. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +148 -37
  65. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +155 -41
  66. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +123 -43
  67. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +216 -39
  68. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +106 -34
  69. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  70. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  71. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  72. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  73. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  74. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  75. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  76. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  77. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  78. diffusers/pipelines/deprecated/__init__.py +153 -0
  79. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
  80. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +177 -34
  81. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +182 -37
  82. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
  83. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
  84. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
  85. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
  86. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
  87. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
  88. diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
  89. diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
  90. diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
  91. diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
  92. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
  93. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +5 -4
  94. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
  95. diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
  96. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
  97. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
  98. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +8 -7
  99. diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
  100. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +34 -13
  101. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +7 -6
  102. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +12 -11
  103. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +17 -11
  104. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +11 -10
  105. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +14 -13
  106. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
  107. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
  108. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
  109. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +83 -51
  110. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
  111. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +7 -6
  112. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +7 -6
  113. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +7 -6
  114. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
  115. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
  116. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  117. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  118. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  119. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  120. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  121. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  122. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  123. diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
  124. diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +589 -0
  125. diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +654 -0
  126. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +111 -11
  127. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +102 -9
  128. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  129. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  130. diffusers/pipelines/onnx_utils.py +8 -5
  131. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  132. diffusers/pipelines/pipeline_flax_utils.py +11 -8
  133. diffusers/pipelines/pipeline_utils.py +63 -42
  134. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +247 -38
  135. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
  136. diffusers/pipelines/stable_diffusion/__init__.py +37 -65
  137. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +75 -78
  138. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  139. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  140. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  141. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +174 -11
  142. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  143. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  144. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +178 -11
  145. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +224 -13
  146. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +74 -20
  147. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -0
  148. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +7 -0
  149. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
  150. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
  151. diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
  152. diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +6 -2
  153. diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
  154. diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +3 -3
  155. diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
  156. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +3 -2
  157. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +4 -3
  158. diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
  159. diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +7 -1
  160. diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
  161. diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +51 -7
  162. diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
  163. diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +57 -8
  164. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
  165. diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
  166. diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +68 -10
  167. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +194 -17
  168. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +205 -16
  169. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +206 -17
  170. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +23 -17
  171. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  172. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +652 -0
  173. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  174. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +115 -14
  175. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  176. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +6 -0
  177. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +23 -3
  178. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +334 -10
  179. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +1331 -0
  180. diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
  181. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
  182. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  183. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  184. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  185. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  186. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  187. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +5 -1
  188. diffusers/schedulers/__init__.py +4 -4
  189. diffusers/schedulers/deprecated/__init__.py +50 -0
  190. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  191. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  192. diffusers/schedulers/scheduling_amused.py +162 -0
  193. diffusers/schedulers/scheduling_consistency_models.py +2 -0
  194. diffusers/schedulers/scheduling_ddim.py +1 -3
  195. diffusers/schedulers/scheduling_ddim_inverse.py +2 -7
  196. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  197. diffusers/schedulers/scheduling_ddpm.py +47 -3
  198. diffusers/schedulers/scheduling_ddpm_parallel.py +47 -3
  199. diffusers/schedulers/scheduling_deis_multistep.py +28 -6
  200. diffusers/schedulers/scheduling_dpmsolver_multistep.py +28 -6
  201. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +28 -6
  202. diffusers/schedulers/scheduling_dpmsolver_sde.py +3 -3
  203. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +28 -6
  204. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +59 -3
  205. diffusers/schedulers/scheduling_euler_discrete.py +102 -16
  206. diffusers/schedulers/scheduling_heun_discrete.py +17 -5
  207. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +17 -5
  208. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +17 -5
  209. diffusers/schedulers/scheduling_lcm.py +123 -29
  210. diffusers/schedulers/scheduling_lms_discrete.py +3 -3
  211. diffusers/schedulers/scheduling_pndm.py +1 -3
  212. diffusers/schedulers/scheduling_repaint.py +1 -3
  213. diffusers/schedulers/scheduling_unipc_multistep.py +28 -6
  214. diffusers/schedulers/scheduling_utils.py +3 -1
  215. diffusers/schedulers/scheduling_utils_flax.py +3 -1
  216. diffusers/training_utils.py +1 -1
  217. diffusers/utils/__init__.py +1 -2
  218. diffusers/utils/constants.py +10 -12
  219. diffusers/utils/dummy_pt_objects.py +75 -0
  220. diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
  221. diffusers/utils/dynamic_modules_utils.py +18 -22
  222. diffusers/utils/export_utils.py +8 -3
  223. diffusers/utils/hub_utils.py +24 -36
  224. diffusers/utils/logging.py +11 -11
  225. diffusers/utils/outputs.py +5 -5
  226. diffusers/utils/peft_utils.py +88 -44
  227. diffusers/utils/state_dict_utils.py +8 -0
  228. diffusers/utils/testing_utils.py +199 -1
  229. diffusers/utils/torch_utils.py +4 -4
  230. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/METADATA +86 -69
  231. diffusers-0.25.0.dist-info/RECORD +360 -0
  232. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/WHEEL +1 -1
  233. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/entry_points.txt +0 -1
  234. diffusers/loaders.py +0 -3336
  235. diffusers-0.23.1.dist-info/RECORD +0 -323
  236. /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
  237. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/LICENSE +0 -0
  238. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/top_level.txt +0 -0
@@ -76,6 +76,12 @@ class StableDiffusionUpscalePipeline(
76
76
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
77
77
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
78
78
 
79
+ The pipeline also inherits the following loading methods:
80
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
81
+ - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
82
+ - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
83
+ - [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
84
+
79
85
  Args:
80
86
  vae ([`AutoencoderKL`]):
81
87
  Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
@@ -92,6 +98,7 @@ class StableDiffusionUpscalePipeline(
92
98
  A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
93
99
  [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
94
100
  """
101
+
95
102
  model_cpu_offload_seq = "text_encoder->unet->vae"
96
103
  _optional_components = ["watermarker", "safety_checker", "feature_extractor"]
97
104
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -65,6 +65,11 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
65
65
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
66
66
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
67
67
 
68
+ The pipeline also inherits the following loading methods:
69
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
70
+ - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
71
+ - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
72
+
68
73
  Args:
69
74
  prior_tokenizer ([`CLIPTokenizer`]):
70
75
  A [`CLIPTokenizer`].
@@ -76,6 +76,11 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
76
76
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
77
77
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
78
78
 
79
+ The pipeline also inherits the following loading methods:
80
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
81
+ - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
82
+ - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
83
+
79
84
  Args:
80
85
  feature_extractor ([`CLIPImageProcessor`]):
81
86
  Feature extractor for image pre-processing before being encoded.
@@ -0,0 +1,48 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_torch_available,
9
+ is_transformers_available,
10
+ )
11
+
12
+
13
+ _dummy_objects = {}
14
+ _import_structure = {}
15
+
16
+
17
+ try:
18
+ if not (is_transformers_available() and is_torch_available()):
19
+ raise OptionalDependencyNotAvailable()
20
+ except OptionalDependencyNotAvailable:
21
+ from ...utils import dummy_torch_and_transformers_objects # noqa F403
22
+
23
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
24
+ else:
25
+ _import_structure["pipeline_stable_diffusion_attend_and_excite"] = ["StableDiffusionAttendAndExcitePipeline"]
26
+
27
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
28
+ try:
29
+ if not (is_transformers_available() and is_torch_available()):
30
+ raise OptionalDependencyNotAvailable()
31
+
32
+ except OptionalDependencyNotAvailable:
33
+ from ...utils.dummy_torch_and_transformers_objects import *
34
+ else:
35
+ from .pipeline_stable_diffusion_attend_and_excite import StableDiffusionAttendAndExcitePipeline
36
+
37
+ else:
38
+ import sys
39
+
40
+ sys.modules[__name__] = _LazyModule(
41
+ __name__,
42
+ globals()["__file__"],
43
+ _import_structure,
44
+ module_spec=__spec__,
45
+ )
46
+
47
+ for name, value in _dummy_objects.items():
48
+ setattr(sys.modules[__name__], name, value)
@@ -37,8 +37,8 @@ from ...utils import (
37
37
  )
38
38
  from ...utils.torch_utils import randn_tensor
39
39
  from ..pipeline_utils import DiffusionPipeline
40
- from . import StableDiffusionPipelineOutput
41
- from .safety_checker import StableDiffusionSafetyChecker
40
+ from ..stable_diffusion import StableDiffusionPipelineOutput
41
+ from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
42
42
 
43
43
 
44
44
  logger = logging.get_logger(__name__)
@@ -177,6 +177,9 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
177
177
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
178
178
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
179
179
 
180
+ The pipeline also inherits the following loading methods:
181
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
182
+
180
183
  Args:
181
184
  vae ([`AutoencoderKL`]):
182
185
  Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
@@ -196,6 +199,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
196
199
  feature_extractor ([`~transformers.CLIPImageProcessor`]):
197
200
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
198
201
  """
202
+
199
203
  model_cpu_offload_seq = "text_encoder->unet->vae"
200
204
  _optional_components = ["safety_checker", "feature_extractor"]
201
205
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -0,0 +1,48 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_torch_available,
9
+ is_transformers_available,
10
+ )
11
+
12
+
13
+ _dummy_objects = {}
14
+ _import_structure = {}
15
+
16
+
17
+ try:
18
+ if not (is_transformers_available() and is_torch_available()):
19
+ raise OptionalDependencyNotAvailable()
20
+ except OptionalDependencyNotAvailable:
21
+ from ...utils import dummy_torch_and_transformers_objects # noqa F403
22
+
23
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
24
+ else:
25
+ _import_structure["pipeline_stable_diffusion_diffedit"] = ["StableDiffusionDiffEditPipeline"]
26
+
27
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
28
+ try:
29
+ if not (is_transformers_available() and is_torch_available()):
30
+ raise OptionalDependencyNotAvailable()
31
+
32
+ except OptionalDependencyNotAvailable:
33
+ from ...utils.dummy_torch_and_transformers_objects import *
34
+ else:
35
+ from .pipeline_stable_diffusion_diffedit import StableDiffusionDiffEditPipeline
36
+
37
+ else:
38
+ import sys
39
+
40
+ sys.modules[__name__] = _LazyModule(
41
+ __name__,
42
+ globals()["__file__"],
43
+ _import_structure,
44
+ module_spec=__spec__,
45
+ )
46
+
47
+ for name, value in _dummy_objects.items():
48
+ setattr(sys.modules[__name__], name, value)
@@ -40,8 +40,8 @@ from ...utils import (
40
40
  )
41
41
  from ...utils.torch_utils import randn_tensor
42
42
  from ..pipeline_utils import DiffusionPipeline
43
- from . import StableDiffusionPipelineOutput
44
- from .safety_checker import StableDiffusionSafetyChecker
43
+ from ..stable_diffusion import StableDiffusionPipelineOutput
44
+ from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
45
45
 
46
46
 
47
47
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -273,6 +273,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
273
273
  feature_extractor ([`~transformers.CLIPImageProcessor`]):
274
274
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
275
275
  """
276
+
276
277
  model_cpu_offload_seq = "text_encoder->unet->vae"
277
278
  _optional_components = ["safety_checker", "feature_extractor", "inverse_scheduler"]
278
279
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -787,7 +788,6 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
787
788
  latents = latents * self.scheduler.init_noise_sigma
788
789
  return latents
789
790
 
790
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_pix2pix_zero.StableDiffusionPix2PixZeroPipeline.prepare_image_latents
791
791
  def prepare_image_latents(self, image, batch_size, dtype, device, generator=None):
792
792
  if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
793
793
  raise ValueError(
@@ -0,0 +1,50 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_torch_available,
9
+ is_transformers_available,
10
+ )
11
+
12
+
13
+ _dummy_objects = {}
14
+ _import_structure = {}
15
+
16
+
17
+ try:
18
+ if not (is_transformers_available() and is_torch_available()):
19
+ raise OptionalDependencyNotAvailable()
20
+ except OptionalDependencyNotAvailable:
21
+ from ...utils import dummy_torch_and_transformers_objects # noqa F403
22
+
23
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
24
+ else:
25
+ _import_structure["pipeline_stable_diffusion_gligen"] = ["StableDiffusionGLIGENPipeline"]
26
+ _import_structure["pipeline_stable_diffusion_gligen_text_image"] = ["StableDiffusionGLIGENTextImagePipeline"]
27
+
28
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
29
+ try:
30
+ if not (is_transformers_available() and is_torch_available()):
31
+ raise OptionalDependencyNotAvailable()
32
+
33
+ except OptionalDependencyNotAvailable:
34
+ from ...utils.dummy_torch_and_transformers_objects import *
35
+ else:
36
+ from .pipeline_stable_diffusion_gligen import StableDiffusionGLIGENPipeline
37
+ from .pipeline_stable_diffusion_gligen_text_image import StableDiffusionGLIGENTextImagePipeline
38
+
39
+ else:
40
+ import sys
41
+
42
+ sys.modules[__name__] = _LazyModule(
43
+ __name__,
44
+ globals()["__file__"],
45
+ _import_structure,
46
+ module_spec=__spec__,
47
+ )
48
+
49
+ for name, value in _dummy_objects.items():
50
+ setattr(sys.modules[__name__], name, value)
@@ -36,8 +36,8 @@ from ...utils import (
36
36
  )
37
37
  from ...utils.torch_utils import randn_tensor
38
38
  from ..pipeline_utils import DiffusionPipeline
39
- from . import StableDiffusionPipelineOutput
40
- from .safety_checker import StableDiffusionSafetyChecker
39
+ from ..stable_diffusion import StableDiffusionPipelineOutput
40
+ from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
41
41
 
42
42
 
43
43
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -125,6 +125,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
125
125
  feature_extractor ([`~transformers.CLIPImageProcessor`]):
126
126
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
127
127
  """
128
+
128
129
  _optional_components = ["safety_checker", "feature_extractor"]
129
130
  model_cpu_offload_seq = "text_encoder->unet->vae"
130
131
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -35,9 +35,9 @@ from ...schedulers import KarrasDiffusionSchedulers
35
35
  from ...utils import USE_PEFT_BACKEND, logging, replace_example_docstring, scale_lora_layers, unscale_lora_layers
36
36
  from ...utils.torch_utils import randn_tensor
37
37
  from ..pipeline_utils import DiffusionPipeline
38
- from . import StableDiffusionPipelineOutput
39
- from .clip_image_project_model import CLIPImageProjection
40
- from .safety_checker import StableDiffusionSafetyChecker
38
+ from ..stable_diffusion import StableDiffusionPipelineOutput
39
+ from ..stable_diffusion.clip_image_project_model import CLIPImageProjection
40
+ from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
41
41
 
42
42
 
43
43
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -177,6 +177,7 @@ class StableDiffusionGLIGENTextImagePipeline(DiffusionPipeline):
177
177
  feature_extractor ([`~transformers.CLIPImageProcessor`]):
178
178
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
179
179
  """
180
+
180
181
  model_cpu_offload_seq = "text_encoder->unet->vae"
181
182
  _optional_components = ["safety_checker", "feature_extractor"]
182
183
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -0,0 +1,60 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_k_diffusion_available,
9
+ is_k_diffusion_version,
10
+ is_torch_available,
11
+ is_transformers_available,
12
+ )
13
+
14
+
15
+ _dummy_objects = {}
16
+ _import_structure = {}
17
+
18
+
19
+ try:
20
+ if not (
21
+ is_transformers_available()
22
+ and is_torch_available()
23
+ and is_k_diffusion_available()
24
+ and is_k_diffusion_version(">=", "0.0.12")
25
+ ):
26
+ raise OptionalDependencyNotAvailable()
27
+ except OptionalDependencyNotAvailable:
28
+ from ...utils import dummy_torch_and_transformers_and_k_diffusion_objects # noqa F403
29
+
30
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_and_k_diffusion_objects))
31
+ else:
32
+ _import_structure["pipeline_stable_diffusion_k_diffusion"] = ["StableDiffusionKDiffusionPipeline"]
33
+
34
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
35
+ try:
36
+ if not (
37
+ is_transformers_available()
38
+ and is_torch_available()
39
+ and is_k_diffusion_available()
40
+ and is_k_diffusion_version(">=", "0.0.12")
41
+ ):
42
+ raise OptionalDependencyNotAvailable()
43
+
44
+ except OptionalDependencyNotAvailable:
45
+ from ...utils.dummy_torch_and_transformers_and_k_diffusion_objects import *
46
+ else:
47
+ from .pipeline_stable_diffusion_k_diffusion import StableDiffusionKDiffusionPipeline
48
+
49
+ else:
50
+ import sys
51
+
52
+ sys.modules[__name__] = _LazyModule(
53
+ __name__,
54
+ globals()["__file__"],
55
+ _import_structure,
56
+ module_spec=__spec__,
57
+ )
58
+
59
+ for name, value in _dummy_objects.items():
60
+ setattr(sys.modules[__name__], name, value)
@@ -27,7 +27,7 @@ from ...schedulers import LMSDiscreteScheduler
27
27
  from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
28
28
  from ...utils.torch_utils import randn_tensor
29
29
  from ..pipeline_utils import DiffusionPipeline
30
- from . import StableDiffusionPipelineOutput
30
+ from ..stable_diffusion import StableDiffusionPipelineOutput
31
31
 
32
32
 
33
33
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -54,6 +54,11 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
54
54
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
55
55
  library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
56
56
 
57
+ The pipeline also inherits the following loading methods:
58
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
59
+ - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
60
+ - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
61
+
57
62
  <Tip warning={true}>
58
63
 
59
64
  This is an experimental pipeline and is likely to change in the future.
@@ -80,6 +85,7 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
80
85
  feature_extractor ([`CLIPImageProcessor`]):
81
86
  Model that extracts features from generated images to be used as inputs for the `safety_checker`.
82
87
  """
88
+
83
89
  model_cpu_offload_seq = "text_encoder->unet->vae"
84
90
  _optional_components = ["safety_checker", "feature_extractor"]
85
91
  _exclude_from_cpu_offload = ["safety_checker"]
@@ -0,0 +1,48 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_torch_available,
9
+ is_transformers_available,
10
+ )
11
+
12
+
13
+ _dummy_objects = {}
14
+ _import_structure = {}
15
+
16
+
17
+ try:
18
+ if not (is_transformers_available() and is_torch_available()):
19
+ raise OptionalDependencyNotAvailable()
20
+ except OptionalDependencyNotAvailable:
21
+ from ...utils import dummy_torch_and_transformers_objects # noqa F403
22
+
23
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
24
+ else:
25
+ _import_structure["pipeline_stable_diffusion_ldm3d"] = ["StableDiffusionLDM3DPipeline"]
26
+
27
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
28
+ try:
29
+ if not (is_transformers_available() and is_torch_available()):
30
+ raise OptionalDependencyNotAvailable()
31
+
32
+ except OptionalDependencyNotAvailable:
33
+ from ...utils.dummy_torch_and_transformers_objects import *
34
+ else:
35
+ from .pipeline_stable_diffusion_ldm3d import StableDiffusionLDM3DPipeline
36
+
37
+ else:
38
+ import sys
39
+
40
+ sys.modules[__name__] = _LazyModule(
41
+ __name__,
42
+ globals()["__file__"],
43
+ _import_structure,
44
+ module_spec=__spec__,
45
+ )
46
+
47
+ for name, value in _dummy_objects.items():
48
+ setattr(sys.modules[__name__], name, value)
@@ -19,11 +19,11 @@ from typing import Any, Callable, Dict, List, Optional, Union
19
19
  import numpy as np
20
20
  import PIL.Image
21
21
  import torch
22
- from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
22
+ from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
23
23
 
24
- from ...image_processor import VaeImageProcessorLDM3D
25
- from ...loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
26
- from ...models import AutoencoderKL, UNet2DConditionModel
24
+ from ...image_processor import PipelineImageInput, VaeImageProcessorLDM3D
25
+ from ...loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
26
+ from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
27
27
  from ...models.lora import adjust_lora_scale_text_encoder
28
28
  from ...schedulers import KarrasDiffusionSchedulers
29
29
  from ...utils import (
@@ -37,7 +37,7 @@ from ...utils import (
37
37
  )
38
38
  from ...utils.torch_utils import randn_tensor
39
39
  from ..pipeline_utils import DiffusionPipeline
40
- from .safety_checker import StableDiffusionSafetyChecker
40
+ from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
41
41
 
42
42
 
43
43
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -82,7 +82,7 @@ class LDM3DPipelineOutput(BaseOutput):
82
82
 
83
83
 
84
84
  class StableDiffusionLDM3DPipeline(
85
- DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
85
+ DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin, FromSingleFileMixin
86
86
  ):
87
87
  r"""
88
88
  Pipeline for text-to-image and 3D generation using LDM3D.
@@ -95,6 +95,7 @@ class StableDiffusionLDM3DPipeline(
95
95
  - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
96
96
  - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
97
97
  - [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
98
+ - [`~loaders.IPAdapterMixin.load_ip_adapter`] for loading IP Adapters
98
99
 
99
100
  Args:
100
101
  vae ([`AutoencoderKL`]):
@@ -115,8 +116,9 @@ class StableDiffusionLDM3DPipeline(
115
116
  feature_extractor ([`~transformers.CLIPImageProcessor`]):
116
117
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
117
118
  """
119
+
118
120
  model_cpu_offload_seq = "text_encoder->unet->vae"
119
- _optional_components = ["safety_checker", "feature_extractor"]
121
+ _optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
120
122
  _exclude_from_cpu_offload = ["safety_checker"]
121
123
 
122
124
  def __init__(
@@ -128,6 +130,7 @@ class StableDiffusionLDM3DPipeline(
128
130
  scheduler: KarrasDiffusionSchedulers,
129
131
  safety_checker: StableDiffusionSafetyChecker,
130
132
  feature_extractor: CLIPImageProcessor,
133
+ image_encoder: Optional[CLIPVisionModelWithProjection],
131
134
  requires_safety_checker: bool = True,
132
135
  ):
133
136
  super().__init__()
@@ -156,6 +159,7 @@ class StableDiffusionLDM3DPipeline(
156
159
  scheduler=scheduler,
157
160
  safety_checker=safety_checker,
158
161
  feature_extractor=feature_extractor,
162
+ image_encoder=image_encoder,
159
163
  )
160
164
  self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
161
165
  self.image_processor = VaeImageProcessorLDM3D(vae_scale_factor=self.vae_scale_factor)
@@ -409,6 +413,31 @@ class StableDiffusionLDM3DPipeline(
409
413
 
410
414
  return prompt_embeds, negative_prompt_embeds
411
415
 
416
+ # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_image
417
+ def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
418
+ dtype = next(self.image_encoder.parameters()).dtype
419
+
420
+ if not isinstance(image, torch.Tensor):
421
+ image = self.feature_extractor(image, return_tensors="pt").pixel_values
422
+
423
+ image = image.to(device=device, dtype=dtype)
424
+ if output_hidden_states:
425
+ image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
426
+ image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
427
+ uncond_image_enc_hidden_states = self.image_encoder(
428
+ torch.zeros_like(image), output_hidden_states=True
429
+ ).hidden_states[-2]
430
+ uncond_image_enc_hidden_states = uncond_image_enc_hidden_states.repeat_interleave(
431
+ num_images_per_prompt, dim=0
432
+ )
433
+ return image_enc_hidden_states, uncond_image_enc_hidden_states
434
+ else:
435
+ image_embeds = self.image_encoder(image).image_embeds
436
+ image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
437
+ uncond_image_embeds = torch.zeros_like(image_embeds)
438
+
439
+ return image_embeds, uncond_image_embeds
440
+
412
441
  def run_safety_checker(self, image, device, dtype):
413
442
  if self.safety_checker is None:
414
443
  has_nsfw_concept = None
@@ -528,6 +557,7 @@ class StableDiffusionLDM3DPipeline(
528
557
  latents: Optional[torch.FloatTensor] = None,
529
558
  prompt_embeds: Optional[torch.FloatTensor] = None,
530
559
  negative_prompt_embeds: Optional[torch.FloatTensor] = None,
560
+ ip_adapter_image: Optional[PipelineImageInput] = None,
531
561
  output_type: Optional[str] = "pil",
532
562
  return_dict: bool = True,
533
563
  callback: Optional[Callable[[int, int, torch.FloatTensor], None]] = None,
@@ -572,6 +602,8 @@ class StableDiffusionLDM3DPipeline(
572
602
  negative_prompt_embeds (`torch.FloatTensor`, *optional*):
573
603
  Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
574
604
  not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
605
+ ip_adapter_image: (`PipelineImageInput`, *optional*):
606
+ Optional image input to work with IP Adapters.
575
607
  output_type (`str`, *optional*, defaults to `"pil"`):
576
608
  The output format of the generated image. Choose between `PIL.Image` or `np.array`.
577
609
  return_dict (`bool`, *optional*, defaults to `True`):
@@ -621,6 +653,14 @@ class StableDiffusionLDM3DPipeline(
621
653
  # corresponds to doing no classifier free guidance.
622
654
  do_classifier_free_guidance = guidance_scale > 1.0
623
655
 
656
+ if ip_adapter_image is not None:
657
+ output_hidden_state = False if isinstance(self.unet.encoder_hid_proj, ImageProjection) else True
658
+ image_embeds, negative_image_embeds = self.encode_image(
659
+ ip_adapter_image, device, num_images_per_prompt, output_hidden_state
660
+ )
661
+ if do_classifier_free_guidance:
662
+ image_embeds = torch.cat([negative_image_embeds, image_embeds])
663
+
624
664
  # 3. Encode input prompt
625
665
  prompt_embeds, negative_prompt_embeds = self.encode_prompt(
626
666
  prompt,
@@ -658,6 +698,9 @@ class StableDiffusionLDM3DPipeline(
658
698
  # 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
659
699
  extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
660
700
 
701
+ # 6.1 Add image embeds for IP-Adapter
702
+ added_cond_kwargs = {"image_embeds": image_embeds} if ip_adapter_image is not None else None
703
+
661
704
  # 7. Denoising loop
662
705
  num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
663
706
  with self.progress_bar(total=num_inference_steps) as progress_bar:
@@ -672,6 +715,7 @@ class StableDiffusionLDM3DPipeline(
672
715
  t,
673
716
  encoder_hidden_states=prompt_embeds,
674
717
  cross_attention_kwargs=cross_attention_kwargs,
718
+ added_cond_kwargs=added_cond_kwargs,
675
719
  return_dict=False,
676
720
  )[0]
677
721
 
@@ -0,0 +1,48 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_torch_available,
9
+ is_transformers_available,
10
+ )
11
+
12
+
13
+ _dummy_objects = {}
14
+ _import_structure = {}
15
+
16
+
17
+ try:
18
+ if not (is_transformers_available() and is_torch_available()):
19
+ raise OptionalDependencyNotAvailable()
20
+ except OptionalDependencyNotAvailable:
21
+ from ...utils import dummy_torch_and_transformers_objects # noqa F403
22
+
23
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
24
+ else:
25
+ _import_structure["pipeline_stable_diffusion_panorama"] = ["StableDiffusionPanoramaPipeline"]
26
+
27
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
28
+ try:
29
+ if not (is_transformers_available() and is_torch_available()):
30
+ raise OptionalDependencyNotAvailable()
31
+
32
+ except OptionalDependencyNotAvailable:
33
+ from ...utils.dummy_torch_and_transformers_objects import *
34
+ else:
35
+ from .pipeline_stable_diffusion_panorama import StableDiffusionPanoramaPipeline
36
+
37
+ else:
38
+ import sys
39
+
40
+ sys.modules[__name__] = _LazyModule(
41
+ __name__,
42
+ globals()["__file__"],
43
+ _import_structure,
44
+ module_spec=__spec__,
45
+ )
46
+
47
+ for name, value in _dummy_objects.items():
48
+ setattr(sys.modules[__name__], name, value)