Skip to content

Commit

Permalink
made compatible with UNet2DConditionModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafaz03 committed Jan 12, 2025
1 parent 36acdd7 commit 9adea33
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/diffusers/pipelines/ddpm/pipeline_ddpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class DDPMPipeline(DiffusionPipeline):

model_cpu_offload_seq = "unet"

def __init__(self, unet, scheduler):
def __init__(self, unet, scheduler, encoder_hidden_states=None):
super().__init__()
self.register_modules(unet=unet, scheduler=scheduler)
self.encoder_hidden_states=encoder_hidden_states

@torch.no_grad()
def __call__(
Expand Down Expand Up @@ -120,7 +121,9 @@ def __call__(

for t in self.progress_bar(self.scheduler.timesteps):
# 1. predict noise model_output
model_output = self.unet(image, t).sample
if self.encoder_hidden_states:
model_output = self.unet(image, t, self.encoder_hidden_states).sample
else: model_output = self.unet(image, t).sample

# 2. compute previous image: x_t -> x_t-1
image = self.scheduler.step(model_output, t, image, generator=generator).prev_sample
Expand Down

0 comments on commit 9adea33

Please sign in to comment.