Closed ethankongee closed 1 year ago
cc @DN6 can you take a look here? :-)
Also cc'ing : @okotaku since they added the pipeline.
@ethank852 You're right, the change in the size of ref_image_latents
is causing an issue when adding noise to them here:
https://github.com/huggingface/diffusers/blob/5fd3dca5f377126b73a9af8aaf7a6291951d201c/examples/community/stable_diffusion_reference.py#L726-L728 Since there is mismatch in the length of generator
and ref_image_latents
.
I would recommend moving the logic for classifier free guidance with ref_image_latents
to the diffusion loop, so that it's explicit when the length is changed
e.g.
for i, t in enumerate(timesteps):
# expand the latents if we are doing classifier free guidance
latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents
latent_model_input = self.scheduler.scale_model_input(latent_model_input,
# ref only part
noise = randn_tensor(
ref_image_latents.shape, generator=generator, device=device, dtype=ref_image_latents.dtype
)
ref_xt = self.scheduler.add_noise(
ref_image_latents,
noise,
t.reshape(
1,
),
)
ref_xt = torch.cat([ref_xt] * 2) if do_classifier_free_guidance else ref_xt
@okotaku could you confirm if this change is compatible with the pipeline? And would you be able to open a PR for it if that's the case?
Hi @ethank852. I pushed a fix for this issue in this PR: #4531 Can you verify it works as expected? I'm closing the issue for now. LMK if you run into any further issues.
Describe the bug
StableDiffusionReferencePipeline
throwslist index out of range
error when you havebatch_size
over 1 andguidance_scale
over 1.Here's how I'm trying to call the pipeline:
So I'm trying to generate 4 images per batch and by default, guidance_scale is 7.5. However, this line would throw the error:
When I inspect the value,
batch_size
is 8 instead of 4. And I traced it back to this line:So the code above is trying to double
ref_image_latents
and it breaks because the size ofref_image_latents
and the size of generator are not the same anymore.Reproduction
Logs
No response
System Info
diffusers
version: 0.19.0.dev0Who can help?
@patrickvonplaten @sayakpaul @williamberman