tolgacangoz
commited on
Upload matryoshka.py
Browse files- matryoshka.py +10 -28
matryoshka.py
CHANGED
@@ -3762,8 +3762,7 @@ class MatryoshkaPipeline(
|
|
3762 |
"""
|
3763 |
|
3764 |
model_cpu_offload_seq = "text_encoder->image_encoder->unet"
|
3765 |
-
_optional_components = ["unet", "
|
3766 |
-
_exclude_from_cpu_offload = ["safety_checker"]
|
3767 |
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
3768 |
|
3769 |
def __init__(
|
@@ -4549,18 +4548,10 @@ class MatryoshkaPipeline(
|
|
4549 |
self.do_classifier_free_guidance,
|
4550 |
)
|
4551 |
|
4552 |
-
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
4553 |
-
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
4554 |
# 4. Prepare timesteps
|
4555 |
-
|
4556 |
-
|
4557 |
-
|
4558 |
-
)
|
4559 |
-
|
4560 |
-
extra_step_kwargs |= {"use_clipped_model_output": True}
|
4561 |
-
else:
|
4562 |
-
timesteps = self.scheduler.timesteps
|
4563 |
-
|
4564 |
timesteps = timesteps[:-1]
|
4565 |
|
4566 |
# 5. Prepare latent variables
|
@@ -4577,6 +4568,10 @@ class MatryoshkaPipeline(
|
|
4577 |
latents,
|
4578 |
)
|
4579 |
|
|
|
|
|
|
|
|
|
4580 |
# 6.1 Add image embeds for IP-Adapter
|
4581 |
added_cond_kwargs = (
|
4582 |
{"image_embeds": image_embeds}
|
@@ -4634,19 +4629,7 @@ class MatryoshkaPipeline(
|
|
4634 |
noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=self.guidance_rescale)
|
4635 |
|
4636 |
# compute the previous noisy sample x_t -> x_t-1
|
4637 |
-
|
4638 |
-
latents[0] = self.scheduler.step(
|
4639 |
-
noise_pred[0], t, latents[0], **extra_step_kwargs, return_dict=False
|
4640 |
-
)[0]
|
4641 |
-
latents[1] = self.scheduler.inner_scheduler.step(
|
4642 |
-
noise_pred[1], t, latents[1], **extra_step_kwargs, return_dict=False
|
4643 |
-
)[0]
|
4644 |
-
if len(latents) > 2:
|
4645 |
-
latents[2] = self.scheduler.inner_scheduler.inner_scheduler.step(
|
4646 |
-
noise_pred[2], t, latents[2], **extra_step_kwargs, return_dict=False
|
4647 |
-
)[0]
|
4648 |
-
else:
|
4649 |
-
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
|
4650 |
|
4651 |
if callback_on_step_end is not None:
|
4652 |
callback_kwargs = {}
|
@@ -4672,8 +4655,7 @@ class MatryoshkaPipeline(
|
|
4672 |
|
4673 |
if self.scheduler.scales is not None:
|
4674 |
for i, (img, scale) in enumerate(zip(image, self.scheduler.scales)):
|
4675 |
-
|
4676 |
-
image[i] = self.image_processor.postprocess(img, output_type=output_type)[0]
|
4677 |
else:
|
4678 |
image = self.image_processor.postprocess(image, output_type=output_type)
|
4679 |
|
|
|
3762 |
"""
|
3763 |
|
3764 |
model_cpu_offload_seq = "text_encoder->image_encoder->unet"
|
3765 |
+
_optional_components = ["unet", "feature_extractor", "image_encoder"]
|
|
|
3766 |
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
3767 |
|
3768 |
def __init__(
|
|
|
4548 |
self.do_classifier_free_guidance,
|
4549 |
)
|
4550 |
|
|
|
|
|
4551 |
# 4. Prepare timesteps
|
4552 |
+
timesteps, num_inference_steps = retrieve_timesteps(
|
4553 |
+
self.scheduler, num_inference_steps, device, timesteps, sigmas
|
4554 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
4555 |
timesteps = timesteps[:-1]
|
4556 |
|
4557 |
# 5. Prepare latent variables
|
|
|
4568 |
latents,
|
4569 |
)
|
4570 |
|
4571 |
+
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
4572 |
+
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
4573 |
+
extra_step_kwargs |= {"use_clipped_model_output": True}
|
4574 |
+
|
4575 |
# 6.1 Add image embeds for IP-Adapter
|
4576 |
added_cond_kwargs = (
|
4577 |
{"image_embeds": image_embeds}
|
|
|
4629 |
noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=self.guidance_rescale)
|
4630 |
|
4631 |
# compute the previous noisy sample x_t -> x_t-1
|
4632 |
+
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4633 |
|
4634 |
if callback_on_step_end is not None:
|
4635 |
callback_kwargs = {}
|
|
|
4655 |
|
4656 |
if self.scheduler.scales is not None:
|
4657 |
for i, (img, scale) in enumerate(zip(image, self.scheduler.scales)):
|
4658 |
+
image[i] = self.image_processor.postprocess(img * scale, output_type=output_type)[0]
|
|
|
4659 |
else:
|
4660 |
image = self.image_processor.postprocess(image, output_type=output_type)
|
4661 |
|