update dreambooth lora to work with IF stage II (#3560) · uuirs/diffusers@f751b88 · GitHub
Skip to content

Commit f751b88

Browse files
update dreambooth lora to work with IF stage II (huggingface#3560)
1 parent abb89da commit f751b88

4 files changed

Lines changed: 59 additions & 8 deletions

File tree

‎examples/dreambooth/train_dreambooth_lora.py‎

Lines changed: 44 additions & 5 deletions

‎src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import torch.nn.functional as F
1111
from transformers import CLIPImageProcessor, T5EncoderModel, T5Tokenizer
1212

13+
from ...loaders import LoraLoaderMixin
1314
from ...models import UNet2DConditionModel
1415
from ...schedulers import DDPMScheduler
1516
from ...utils import (
@@ -112,7 +113,7 @@ def resize(images: PIL.Image.Image, img_size: int) -> PIL.Image.Image:
112113
"""
113114

114115

115-
class IFImg2ImgSuperResolutionPipeline(DiffusionPipeline):
116+
class IFImg2ImgSuperResolutionPipeline(DiffusionPipeline, LoraLoaderMixin):
116117
tokenizer: T5Tokenizer
117118
text_encoder: T5EncoderModel
118119

@@ -1047,6 +1048,9 @@ def __call__(
10471048
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
10481049
noise_pred = torch.cat([noise_pred, predicted_variance], dim=1)
10491050

1051+
if self.scheduler.config.variance_type not in ["learned", "learned_range"]:
1052+
noise_pred, _ = noise_pred.split(intermediate_images.shape[1], dim=1)
1053+
10501054
# compute the previous noisy sample x_t -> x_t-1
10511055
intermediate_images = self.scheduler.step(
10521056
noise_pred, t, intermediate_images, **extra_step_kwargs, return_dict=False

‎src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import torch.nn.functional as F
1111
from transformers import CLIPImageProcessor, T5EncoderModel, T5Tokenizer
1212

13+
from ...loaders import LoraLoaderMixin
1314
from ...models import UNet2DConditionModel
1415
from ...schedulers import DDPMScheduler
1516
from ...utils import (
@@ -114,7 +115,7 @@ def resize(images: PIL.Image.Image, img_size: int) -> PIL.Image.Image:
114115
"""
115116

116117

117-
class IFInpaintingSuperResolutionPipeline(DiffusionPipeline):
118+
class IFInpaintingSuperResolutionPipeline(DiffusionPipeline, LoraLoaderMixin):
118119
tokenizer: T5Tokenizer
119120
text_encoder: T5EncoderModel
120121

@@ -1154,6 +1155,9 @@ def __call__(
11541155
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
11551156
noise_pred = torch.cat([noise_pred, predicted_variance], dim=1)
11561157

1158+
if self.scheduler.config.variance_type not in ["learned", "learned_range"]:
1159+
noise_pred, _ = noise_pred.split(intermediate_images.shape[1], dim=1)
1160+
11571161
# compute the previous noisy sample x_t -> x_t-1
11581162
prev_intermediate_images = intermediate_images
11591163

‎src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py‎

Lines changed: 5 additions & 1 deletion

0 commit comments

Comments
 (0)