Skip to content

Commit 3be4b01

Browse files
committed
remove methods again
1 parent 16d67c4 commit 3be4b01

File tree

2 files changed

+6
-105
lines changed

2 files changed

+6
-105
lines changed

src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -309,98 +309,6 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype
309309
latents = latents * self.scheduler.init_noise_sigma
310310
return latents
311311

312-
def _get_add_time_ids(
313-
self, original_size, crops_coords_top_left, target_size, dtype, text_encoder_projection_dim=None
314-
):
315-
add_time_ids = list(original_size + crops_coords_top_left + target_size)
316-
317-
passed_add_embed_dim = (
318-
self.unet.config.addition_time_embed_dim * len(add_time_ids) + text_encoder_projection_dim
319-
)
320-
expected_add_embed_dim = self.unet.add_embedding.linear_1.in_features
321-
322-
if expected_add_embed_dim != passed_add_embed_dim:
323-
raise ValueError(
324-
f"Model expects an added time embedding vector of length {expected_add_embed_dim}, but a vector of {passed_add_embed_dim} was created. The model has an incorrect config. Please check `unet.config.time_embedding_type` and `text_encoder_2.config.projection_dim`."
325-
)
326-
327-
add_time_ids = torch.tensor([add_time_ids], dtype=dtype)
328-
return add_time_ids
329-
330-
def upcast_vae(self):
331-
deprecate(
332-
"upcast_vae",
333-
"1.0.0",
334-
"`upcast_vae` is deprecated. Please use `pipe.vae.to(torch.float32)`. For more details, please refer to: https://github.com/huggingface/diffusers/pull/12619#issue-3606633695.",
335-
)
336-
self.vae.to(dtype=torch.float32)
337-
338-
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
339-
def get_guidance_scale_embedding(
340-
self, w: torch.Tensor, embedding_dim: int = 512, dtype: torch.dtype = torch.float32
341-
) -> torch.Tensor:
342-
"""
343-
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
344-
345-
Args:
346-
w (`torch.Tensor`):
347-
Generate embedding vectors with a specified guidance scale to subsequently enrich timestep embeddings.
348-
embedding_dim (`int`, *optional*, defaults to 512):
349-
Dimension of the embeddings to generate.
350-
dtype (`torch.dtype`, *optional*, defaults to `torch.float32`):
351-
Data type of the generated embeddings.
352-
353-
Returns:
354-
`torch.Tensor`: Embedding vectors with shape `(len(w), embedding_dim)`.
355-
"""
356-
assert len(w.shape) == 1
357-
w = w * 1000.0
358-
359-
half_dim = embedding_dim // 2
360-
emb = torch.log(torch.tensor(10000.0)) / (half_dim - 1)
361-
emb = torch.exp(torch.arange(half_dim, dtype=dtype) * -emb)
362-
emb = w.to(dtype)[:, None] * emb[None, :]
363-
emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1)
364-
if embedding_dim % 2 == 1: # zero pad
365-
emb = torch.nn.functional.pad(emb, (0, 1))
366-
assert emb.shape == (w.shape[0], embedding_dim)
367-
return emb
368-
369-
@property
370-
def guidance_scale(self):
371-
return self._guidance_scale
372-
373-
@property
374-
def guidance_rescale(self):
375-
return self._guidance_rescale
376-
377-
@property
378-
def clip_skip(self):
379-
return self._clip_skip
380-
381-
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
382-
# of the Imagen paper: https://huggingface.co/papers/2205.11487 . `guidance_scale = 1`
383-
# corresponds to doing no classifier free guidance.
384-
@property
385-
def do_classifier_free_guidance(self):
386-
return self._guidance_scale > 1 and self.unet.config.time_cond_proj_dim is None
387-
388-
@property
389-
def cross_attention_kwargs(self):
390-
return self._cross_attention_kwargs
391-
392-
@property
393-
def denoising_end(self):
394-
return self._denoising_end
395-
396-
@property
397-
def num_timesteps(self):
398-
return self._num_timesteps
399-
400-
@property
401-
def interrupt(self):
402-
return self._interrupt
403-
404312
@torch.no_grad()
405313
@replace_example_docstring(EXAMPLE_DOC_STRING)
406314
def __call__(

src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_utils.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
from ...loaders import StableDiffusionXLLoraLoaderMixin, TextualInversionLoaderMixin
2121
from ...models import ImageProjection
22-
from ...models.attention_processor import AttnProcessor2_0, FusedAttnProcessor2_0, XFormersAttnProcessor
2322
from ...models.lora import adjust_lora_scale_text_encoder
24-
from ...utils import USE_PEFT_BACKEND, logging, scale_lora_layers, unscale_lora_layers
23+
from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
2524

2625

2726
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -393,18 +392,12 @@ def encode_image(self, image, device, num_images_per_prompt, output_hidden_state
393392
return image_embeds, uncond_image_embeds
394393

395394
def upcast_vae(self):
396-
dtype = self.vae.dtype
397-
self.vae.to(dtype=torch.float32)
398-
use_torch_2_0_or_xformers = isinstance(
399-
self.vae.decoder.mid_block.attentions[0].processor,
400-
(AttnProcessor2_0, XFormersAttnProcessor, FusedAttnProcessor2_0),
395+
deprecate(
396+
"upcast_vae",
397+
"1.0.0",
398+
"`upcast_vae` is deprecated. Please use `pipe.vae.to(torch.float32)`. For more details, please refer to: https://github.com/huggingface/diffusers/pull/12619#issue-3606633695.",
401399
)
402-
# if xformers or torch_2_0 is used attention block does not need
403-
# to be in float32 which can save lots of memory
404-
if use_torch_2_0_or_xformers:
405-
self.vae.post_quant_conv.to(dtype)
406-
self.vae.decoder.conv_in.to(dtype)
407-
self.vae.decoder.mid_block.to(dtype)
400+
self.vae.to(dtype=torch.float32)
408401

409402
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
410403
def get_guidance_scale_embedding(

0 commit comments

Comments
 (0)