Skip to content

Commit 21a03f9

Browse files
committed
update
1 parent a9cb08a commit 21a03f9

48 files changed

Lines changed: 1335 additions & 2065 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/community/lpw_stable_diffusion_xl.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
TextualInversionLoaderMixin,
3030
)
3131
from diffusers.models import AutoencoderKL, ImageProjection, UNet2DConditionModel
32-
from diffusers.models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
3332
from diffusers.models.lora import adjust_lora_scale_text_encoder
3433
from diffusers.pipelines.pipeline_utils import StableDiffusionMixin
3534
from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
@@ -1328,18 +1327,7 @@ def _get_add_time_ids(self, original_size, crops_coords_top_left, target_size, d
13281327

13291328
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
13301329
def upcast_vae(self):
1331-
dtype = self.vae.dtype
1332-
self.vae.to(dtype=torch.float32)
1333-
use_torch_2_0_or_xformers = isinstance(
1334-
self.vae.decoder.mid_block.attentions[0].processor,
1335-
(AttnProcessor2_0, XFormersAttnProcessor),
1336-
)
1337-
# if xformers or torch_2_0 is used attention block does not need
1338-
# to be in float32 which can save lots of memory
1339-
if use_torch_2_0_or_xformers:
1340-
self.vae.post_quant_conv.to(dtype)
1341-
self.vae.decoder.conv_in.to(dtype)
1342-
self.vae.decoder.mid_block.to(dtype)
1330+
deprecate("`upcast_vae` is deprecated")
13431331

13441332
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
13451333
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
@@ -1921,7 +1909,7 @@ def denoising_value_valid(dnv):
19211909
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
19221910

19231911
if needs_upcasting:
1924-
self.upcast_vae()
1912+
self.vae.to(torch.float32)
19251913
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
19261914

19271915
# unscale/denormalize the latents

examples/community/masked_stable_diffusion_xl_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def denoising_value_valid(dnv):
481481
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
482482

483483
if needs_upcasting:
484-
self.upcast_vae()
484+
self.vae.to(torch.float32)
485485
elif latents.dtype != self.vae.dtype:
486486
if torch.backends.mps.is_available():
487487
# some platforms (eg. apple mps) misbehave due to a pytorch bug: https://github.com/pytorch/pytorch/pull/99272

examples/community/mixture_tiling_sdxl.py

Lines changed: 1218 additions & 1237 deletions
Large diffs are not rendered by default.

examples/community/mod_controlnet_tile_sr_sdxl.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@
3939
MultiControlNetModel,
4040
UNet2DConditionModel,
4141
)
42-
from diffusers.models.attention_processor import (
43-
AttnProcessor2_0,
44-
XFormersAttnProcessor,
45-
)
4642
from diffusers.models.lora import adjust_lora_scale_text_encoder
4743
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
4844
from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
4945
from diffusers.schedulers import KarrasDiffusionSchedulers, LMSDiscreteScheduler
5046
from diffusers.utils import (
5147
USE_PEFT_BACKEND,
48+
deprecate,
5249
logging,
5350
replace_example_docstring,
5451
scale_lora_layers,
@@ -1222,21 +1219,7 @@ def prepare_tiles(
12221219

12231220
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
12241221
def upcast_vae(self):
1225-
dtype = self.vae.dtype
1226-
self.vae.to(dtype=torch.float32)
1227-
use_torch_2_0_or_xformers = isinstance(
1228-
self.vae.decoder.mid_block.attentions[0].processor,
1229-
(
1230-
AttnProcessor2_0,
1231-
XFormersAttnProcessor,
1232-
),
1233-
)
1234-
# if xformers or torch_2_0 is used attention block does not need
1235-
# to be in float32 which can save lots of memory
1236-
if use_torch_2_0_or_xformers:
1237-
self.vae.post_quant_conv.to(dtype)
1238-
self.vae.decoder.conv_in.to(dtype)
1239-
self.vae.decoder.mid_block.to(dtype)
1222+
deprecate("`upcast_vae` is deprecated")
12401223

12411224
@property
12421225
def guidance_scale(self):
@@ -1820,7 +1803,7 @@ def __call__(
18201803
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
18211804

18221805
if needs_upcasting:
1823-
self.upcast_vae()
1806+
self.vae.to(torch.float32)
18241807
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
18251808

18261809
# unscale/denormalize the latents

examples/community/pipeline_controlnet_xl_kolors.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
MultiControlNetModel,
4141
UNet2DConditionModel,
4242
)
43-
from diffusers.models.attention_processor import (
44-
AttnProcessor2_0,
45-
XFormersAttnProcessor,
46-
)
4743
from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer
4844
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
4945
from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
@@ -760,21 +756,7 @@ def _get_add_time_ids(
760756

761757
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
762758
def upcast_vae(self):
763-
dtype = self.vae.dtype
764-
self.vae.to(dtype=torch.float32)
765-
use_torch_2_0_or_xformers = isinstance(
766-
self.vae.decoder.mid_block.attentions[0].processor,
767-
(
768-
AttnProcessor2_0,
769-
XFormersAttnProcessor,
770-
),
771-
)
772-
# if xformers or torch_2_0 is used attention block does not need
773-
# to be in float32 which can save lots of memory
774-
if use_torch_2_0_or_xformers:
775-
self.vae.post_quant_conv.to(dtype)
776-
self.vae.decoder.conv_in.to(dtype)
777-
self.vae.decoder.mid_block.to(dtype)
759+
deprecate("`upcast_vae` is deprecated")
778760

779761
@property
780762
def guidance_scale(self):
@@ -1331,7 +1313,7 @@ def _cn_patch_forward(*args, **kwargs):
13311313
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
13321314

13331315
if needs_upcasting:
1334-
self.upcast_vae()
1316+
self.vae.to(torch.float32)
13351317
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
13361318

13371319
latents = latents / self.vae.config.scaling_factor

examples/community/pipeline_controlnet_xl_kolors_img2img.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
MultiControlNetModel,
4141
UNet2DConditionModel,
4242
)
43-
from diffusers.models.attention_processor import (
44-
AttnProcessor2_0,
45-
XFormersAttnProcessor,
46-
)
4743
from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer
4844
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
4945
from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
@@ -930,21 +926,7 @@ def _get_add_time_ids(
930926

931927
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
932928
def upcast_vae(self):
933-
dtype = self.vae.dtype
934-
self.vae.to(dtype=torch.float32)
935-
use_torch_2_0_or_xformers = isinstance(
936-
self.vae.decoder.mid_block.attentions[0].processor,
937-
(
938-
AttnProcessor2_0,
939-
XFormersAttnProcessor,
940-
),
941-
)
942-
# if xformers or torch_2_0 is used attention block does not need
943-
# to be in float32 which can save lots of memory
944-
if use_torch_2_0_or_xformers:
945-
self.vae.post_quant_conv.to(dtype)
946-
self.vae.decoder.conv_in.to(dtype)
947-
self.vae.decoder.mid_block.to(dtype)
929+
deprecate("`upcast_vae` is deprecated")
948930

949931
@property
950932
def guidance_scale(self):
@@ -1533,7 +1515,7 @@ def _cn_patch_forward(*args, **kwargs):
15331515
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
15341516

15351517
if needs_upcasting:
1536-
self.upcast_vae()
1518+
self.vae.to(torch.float32)
15371519
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
15381520

15391521
latents = latents / self.vae.config.scaling_factor

examples/community/pipeline_controlnet_xl_kolors_inpaint.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
MultiControlNetModel,
4040
UNet2DConditionModel,
4141
)
42-
from diffusers.models.attention_processor import (
43-
AttnProcessor2_0,
44-
XFormersAttnProcessor,
45-
)
4642
from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer
4743
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
4844
from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
@@ -1006,21 +1002,7 @@ def _get_add_time_ids(
10061002

10071003
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
10081004
def upcast_vae(self):
1009-
dtype = self.vae.dtype
1010-
self.vae.to(dtype=torch.float32)
1011-
use_torch_2_0_or_xformers = isinstance(
1012-
self.vae.decoder.mid_block.attentions[0].processor,
1013-
(
1014-
AttnProcessor2_0,
1015-
XFormersAttnProcessor,
1016-
),
1017-
)
1018-
# if xformers or torch_2_0 is used attention block does not need
1019-
# to be in float32 which can save lots of memory
1020-
if use_torch_2_0_or_xformers:
1021-
self.vae.post_quant_conv.to(dtype)
1022-
self.vae.decoder.conv_in.to(dtype)
1023-
self.vae.decoder.mid_block.to(dtype)
1005+
deprecate("`upcast_vae` is deprecated")
10241006

10251007
@property
10261008
def denoising_end(self):
@@ -1847,7 +1829,7 @@ def _cn_patch_forward(*args, **kwargs):
18471829
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
18481830

18491831
if needs_upcasting:
1850-
self.upcast_vae()
1832+
self.vae.to(torch.float32)
18511833
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
18521834

18531835
latents = latents / self.vae.config.scaling_factor

examples/community/pipeline_demofusion_sdxl.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
TextualInversionLoaderMixin,
1717
)
1818
from diffusers.models import AutoencoderKL, UNet2DConditionModel
19-
from diffusers.models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
2019
from diffusers.models.lora import adjust_lora_scale_text_encoder
2120
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
2221
from diffusers.schedulers import KarrasDiffusionSchedulers
2322
from diffusers.utils import (
23+
deprecate,
2424
is_accelerate_available,
2525
is_accelerate_version,
2626
is_invisible_watermark_available,
@@ -614,18 +614,7 @@ def tiled_decode(self, latents, current_height, current_width):
614614

615615
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
616616
def upcast_vae(self):
617-
dtype = self.vae.dtype
618-
self.vae.to(dtype=torch.float32)
619-
use_torch_2_0_or_xformers = isinstance(
620-
self.vae.decoder.mid_block.attentions[0].processor,
621-
(AttnProcessor2_0, XFormersAttnProcessor),
622-
)
623-
# if xformers or torch_2_0 is used attention block does not need
624-
# to be in float32 which can save lots of memory
625-
if use_torch_2_0_or_xformers:
626-
self.vae.post_quant_conv.to(dtype)
627-
self.vae.decoder.conv_in.to(dtype)
628-
self.vae.decoder.mid_block.to(dtype)
617+
deprecate("`upcast_vae` is deprecated")
629618

630619
@torch.no_grad()
631620
@replace_example_docstring(EXAMPLE_DOC_STRING)
@@ -997,7 +986,7 @@ def __call__(
997986
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
998987

999988
if needs_upcasting:
1000-
self.upcast_vae()
989+
self.vae.to(torch.float32)
1001990
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
1002991
print("### Phase 1 Decoding ###")
1003992
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
@@ -1257,7 +1246,7 @@ def __call__(
12571246
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
12581247

12591248
if needs_upcasting:
1260-
self.upcast_vae()
1249+
self.vae.to(torch.float32)
12611250
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
12621251

12631252
print("### Phase {} Decoding ###".format(current_scale_num))

examples/community/pipeline_faithdiff_stable_diffusion_xl.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
UNet2DConditionLoadersMixin,
4141
)
4242
from diffusers.models import AutoencoderKL
43-
from diffusers.models.attention_processor import (
44-
AttnProcessor2_0,
45-
FusedAttnProcessor2_0,
46-
LoRAAttnProcessor2_0,
47-
LoRAXFormersAttnProcessor,
48-
XFormersAttnProcessor,
49-
)
5043
from diffusers.models.lora import adjust_lora_scale_text_encoder
5144
from diffusers.models.unets.unet_2d_blocks import UNetMidBlock2D, get_down_block
5245
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
@@ -1637,24 +1630,7 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype
16371630
return latents
16381631

16391632
def upcast_vae(self):
1640-
dtype = self.vae.dtype
1641-
self.vae.to(dtype=torch.float32)
1642-
use_torch_2_0_or_xformers = isinstance(
1643-
self.vae.decoder.mid_block.attentions[0].processor,
1644-
(
1645-
AttnProcessor2_0,
1646-
XFormersAttnProcessor,
1647-
LoRAXFormersAttnProcessor,
1648-
LoRAAttnProcessor2_0,
1649-
FusedAttnProcessor2_0,
1650-
),
1651-
)
1652-
# if xformers or torch_2_0 is used attention block does not need
1653-
# to be in float32 which can save lots of memory
1654-
if use_torch_2_0_or_xformers:
1655-
self.vae.post_quant_conv.to(dtype)
1656-
self.vae.decoder.conv_in.to(dtype)
1657-
self.vae.decoder.mid_block.to(dtype)
1633+
deprecate("`upcast_vae` is deprecated")
16581634

16591635
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
16601636
def get_guidance_scale_embedding(
@@ -1782,7 +1758,7 @@ def prepare_image_latents(
17821758
# needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
17831759
# if needs_upcasting:
17841760
# image = image.float()
1785-
# self.upcast_vae()
1761+
# self.vae.to(torch.float32)
17861762
self.unet.denoise_encoder.to(device=image.device, dtype=image.dtype)
17871763
image_latents = self.unet.denoise_encoder(image)
17881764
self.unet.denoise_encoder.to("cpu")
@@ -2235,7 +2211,7 @@ def __call__(
22352211
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
22362212

22372213
if needs_upcasting:
2238-
self.upcast_vae()
2214+
self.vae.to(torch.float32)
22392215
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
22402216
elif latents.dtype != self.vae.dtype:
22412217
if torch.backends.mps.is_available():

examples/community/pipeline_kolors_differential_img2img.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
2323
from diffusers.loaders import IPAdapterMixin, StableDiffusionXLLoraLoaderMixin
2424
from diffusers.models import AutoencoderKL, ImageProjection, UNet2DConditionModel
25-
from diffusers.models.attention_processor import AttnProcessor2_0, FusedAttnProcessor2_0, XFormersAttnProcessor
2625
from diffusers.pipelines.kolors.pipeline_output import KolorsPipelineOutput
2726
from diffusers.pipelines.kolors.text_encoder import ChatGLMModel
2827
from diffusers.pipelines.kolors.tokenizer import ChatGLMTokenizer
2928
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, StableDiffusionMixin
3029
from diffusers.schedulers import KarrasDiffusionSchedulers
31-
from diffusers.utils import is_torch_xla_available, logging, replace_example_docstring
30+
from diffusers.utils import deprecate, is_torch_xla_available, logging, replace_example_docstring
3231
from diffusers.utils.torch_utils import randn_tensor
3332

3433

@@ -711,22 +710,7 @@ def _get_add_time_ids(
711710

712711
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.upcast_vae
713712
def upcast_vae(self):
714-
dtype = self.vae.dtype
715-
self.vae.to(dtype=torch.float32)
716-
use_torch_2_0_or_xformers = isinstance(
717-
self.vae.decoder.mid_block.attentions[0].processor,
718-
(
719-
AttnProcessor2_0,
720-
XFormersAttnProcessor,
721-
FusedAttnProcessor2_0,
722-
),
723-
)
724-
# if xformers or torch_2_0 is used attention block does not need
725-
# to be in float32 which can save lots of memory
726-
if use_torch_2_0_or_xformers:
727-
self.vae.post_quant_conv.to(dtype)
728-
self.vae.decoder.conv_in.to(dtype)
729-
self.vae.decoder.mid_block.to(dtype)
713+
deprecate("`upcast_vae` is deprecated")
730714

731715
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
732716
def get_guidance_scale_embedding(
@@ -1252,7 +1236,7 @@ def denoising_value_valid(dnv):
12521236
needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
12531237

12541238
if needs_upcasting:
1255-
self.upcast_vae()
1239+
self.vae.to(torch.float32)
12561240
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
12571241
elif latents.dtype != self.vae.dtype:
12581242
if torch.backends.mps.is_available():

0 commit comments

Comments
 (0)