Skip to content

Conversation

horseee
Copy link
Contributor

@horseee horseee commented Dec 29, 2023

What does this PR do?

This PR is for the documentation of DeepCache, which is a new training-free method for accelerating diffusion models. DeepCache can be easily used on StableDIffusionPipeline to accelerate the inference speed. The doc contains the installation and usage of DeepCache, and also a quick overview of the quality and speed after applying DeepCache on the Stable Diffusion Pipeline.

Before submitting

Who can review?

@sayakpaul

@sayakpaul
Copy link
Member

Thanks for the very nice doc!

@stevhliu, would it make sense to have a dedicated page for the optimization techniques that lie outside of diffusers? We have one already: https://huggingface.co/docs/diffusers/main/en/optimization/tome. Now, we will have another on DeepCache.

-->

# DeepCache
[DeepCache](https://huggingface.co/papers/2312.00858) accelerates [`StableDiffusionPipeline`] by strategically caching and reusing high-level features, while efficiently updating low-level features, which leverages the unique properties of the U-Net architecture.
Copy link
Member

Choose a reason for hiding this comment

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

If it supports StableDiffusionXLPipeline too, I'd mention it here.

Additionally, out of curiosity: does it support the img2img, and inpainting pipelines from SD and SDXL yet? If not, it might be extremely beneficial for the community to have them supported because they are so widely used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it supports StableDiffusionXLPipeline!

For other tasks, like inpainting, img2img, and video, I listed some of the results here:

Task Model Original Pipeline + DeepCache Speedup
inpainting diffusers/stable-diffusion-xl-1.0-inpainting-0.1 image image 1.8x
inpainting runwayml/stable-diffusion-inpainting image image 1.7x
img2img runwayml/stable-diffusion-v1-5 image image 1.6x
video stabilityai/stable-video-diffusion-img2vid-xt origin deepcache 1.7x

In these cases, under the premise of ensuring quality and consistency, the acceleration ratio obtained is not particularly high.

I would later add scripts of these cases in the DeepCache repo😃

Comment on lines 39 to 40
The `set_params` method accepts two arguments: `cache_interval` and `cache_branch_id`. `cache_interval` means the frequency of feature caching, specified as the number of steps between each cache operation. `cache_branch_id` identifies which branch of the network (ordered from the shallowest to the deepest layer) is responsible for executing the caching processes.
Opting for a lower `cache_branch_id` or a larger `cache_interval` can lead to faster inference speed; however, this may come at the cost of reduced image quality. Once those arguments are set, use the `enable` or `disable` methods to activate or deactivate the DeepCacheSDHelper respectively.
Copy link
Member

Choose a reason for hiding this comment

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

Very clear! If there's any ablation already done on these hyperparameters in the original DeepCache paper, I'd mention it here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ablation experiments for cache_interval are detailed in Tables 13 and 14 of the appendix, using SD1.5 as the base model. Regarding cache_branch_id, its corresponding ablation experiments are also presented, found in Table 12; however, these experiments were carried out using the DDPM model.

  • cache_interval: (N here represents the cache interval)
image
  • cache_branch_id:
image

Would this be okay?

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Feel free to include this in the doc.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Sweet!

@horseee
Copy link
Contributor Author

horseee commented Jan 2, 2024

Thanks @sayakpaul for the wonderful suggestions😃 Following your advice, I have updated the doc, and also the DeepCache package to support inpaint/img2img tasks for SD.

Warm welcome for any further advice or feedback

@sayakpaul sayakpaul requested a review from stevhliu January 2, 2024 08:00
@sayakpaul
Copy link
Member

Thank you! I have requested for another review from @stevhliu. Let's see what Steven has to say :-)

Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding the docs! 😄

@sayakpaul
Copy link
Member

@stevhliu WDYT #6390 (comment) ?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@stevhliu
Copy link
Member

stevhliu commented Jan 4, 2024

would it make sense to have a dedicated page for the optimization techniques that lie outside of diffusers?

Oops sorry I missed that Sayak! I assume you mean creating a section for optimization techniques outside of Diffusers and grouping ToMe and DeepCache under it since we're already adding a dedicated page for DeepCache here.

I don't think it's necessary at this point since we only have the two (ToMe + DeepCache), and it'll probably make the table of contents more cluttered to add another subsection. I also don't think users really care whether a technique is native or external to Diffusers as long as it works and is clearly documented, so maybe we don't need to organize it so granularly right now 🙂

@sayakpaul
Copy link
Member

@horseee let's apply the changes suggested by Steven and ship this 🚀

@horseee
Copy link
Contributor Author

horseee commented Jan 5, 2024

@horseee let's apply the changes suggested by Steven and ship this 🚀

Thanks @sayakpaul and @stevhliu! I have applied the suggested modifications.

@sayakpaul sayakpaul merged commit 811fd06 into huggingface:main Jan 5, 2024
@sayakpaul
Copy link
Member

sayakpaul commented Jan 5, 2024

Thank you so much for your contributions and awesome work on DeepCache! Let's continue to make diffusion models more accessible!

Also, if you want, feel free to include a link to the doc page (when it appears on the Diffusers site) from your DeepCache GitHub repo.

@horseee
Copy link
Contributor Author

horseee commented Jan 5, 2024

Thank you so much for your contributions and awesome work on DeepCache! Let's continue to make diffusion models more accessible!

Also, if you want, feel free to include a link to the doc page (when it appears on the Diffusers site) from your DeepCache GitHub repo.

Many thanks for your support!

I've updated the GitHub repo to include the link, and I would continue to support DeepCache with more pipelines/models in Diffusers. Thanks again for your support!

@sayakpaul
Copy link
Member

Just for folks visiting this PR, the doc is live here: https://huggingface.co/docs/diffusers/main/en/optimization/deepcache.

AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…uggingface#6390)

* add documentation for DeepCache

* fix typo

* add wandb url for DeepCache

* fix some typos

* add item in _toctree.yml

* update formats for arguments

* Update deepcache.md

* Update docs/source/en/optimization/deepcache.md

Co-authored-by: Sayak Paul <[email protected]>

* add StableDiffusionXLPipeline in doc

* Separate SDPipeline and SDXLPipeline

* Add the paper link of ablation experiments for hyper-parameters

* Apply suggestions from code review

Co-authored-by: Steven Liu <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Steven Liu <[email protected]>
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.

4 participants