Skip to content

Conversation

@dg845
Copy link
Collaborator

@dg845 dg845 commented Nov 21, 2023

What does this PR do?

This PR adds custom timesteps support to LCMScheduler.set_timesteps and pipelines which support LCMScheduler (e.g. LatentConsistencyModelPipeline, StableDiffusionPipeline, StableDiffusionXLPipeline). This gives users the flexibility to try out timestep schedules beyond the "standard" LCM inference schedule (as calculated when num_inference_steps is given to LCMScheduler.set_timesteps).

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten
@patil-suraj
@luosiallen

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 21, 2023

The documentation is not available anymore as the PR was closed or merged.

# 4. Prepare timesteps
self.scheduler.set_timesteps(num_inference_steps, device=device)
timesteps = self.scheduler.timesteps
if timesteps is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

Could we maybe factor this out into a function:

timesteps = retrieve_timesteps(self.scheduler, timesteps)

and then use #copied from for all pipelines?

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for opening this PR - I think that's a good idea! Could we maybe try to make use of # Copied from by factoring out the function (similarly to:

# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.retrieve_latents
)

@dg845
Copy link
Collaborator Author

dg845 commented Nov 22, 2023

@patrickvonplaten I have refactored the timestep handling logic into a retrieve_timesteps function located in /src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py and copied it to all of the pipelines which support LCMScheduler with the # Copied from mechanism.

@patrickvonplaten
Copy link
Contributor

@patrickvonplaten I have refactored the timestep handling logic into a retrieve_timesteps function located in /src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py and copied it to all of the pipelines which support LCMScheduler with the # Copied from mechanism.

This looks great - very nice job! Merging!

@patrickvonplaten patrickvonplaten merged commit 67d0707 into huggingface:main Nov 27, 2023
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…uggingface#5874)

* Add custom timesteps support to LCMScheduler.

* Add custom timesteps support to StableDiffusionPipeline.

* Add custom timesteps support to StableDiffusionXLPipeline.

* Add custom timesteps support to remaining Stable Diffusion pipelines which support LCMScheduler (img2img, inpaint).

* Add custom timesteps support to remaining Stable Diffusion XL pipelines which support LCMScheduler (img2img, inpaint).

* Add custom timesteps support to StableDiffusionControlNetPipeline.

* Add custom timesteps support to T21 Stable Diffusion (XL) Adapters.

* Clean up Stable Diffusion inpaint tests.

* Manually add support for custom timesteps to AltDiffusion pipelines since make fix-copies doesn't appear to work correctly (it deletes the whole pipeline).

* make style

* Refactor pipeline timestep handling into the retrieve_timesteps function.
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…uggingface#5874)

* Add custom timesteps support to LCMScheduler.

* Add custom timesteps support to StableDiffusionPipeline.

* Add custom timesteps support to StableDiffusionXLPipeline.

* Add custom timesteps support to remaining Stable Diffusion pipelines which support LCMScheduler (img2img, inpaint).

* Add custom timesteps support to remaining Stable Diffusion XL pipelines which support LCMScheduler (img2img, inpaint).

* Add custom timesteps support to StableDiffusionControlNetPipeline.

* Add custom timesteps support to T21 Stable Diffusion (XL) Adapters.

* Clean up Stable Diffusion inpaint tests.

* Manually add support for custom timesteps to AltDiffusion pipelines since make fix-copies doesn't appear to work correctly (it deletes the whole pipeline).

* make style

* Refactor pipeline timestep handling into the retrieve_timesteps function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants