-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[diffusion] Support cache-dit #14234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Brain97, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces comprehensive support for Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for cache-dit to accelerate DiT-based model inference. The changes are well-structured, adding a dedicated integration module (cache_dit_integration.py) that handles the lazy loading and configuration of cache-dit. The core denoising pipeline is updated to enable caching on the transformer model, with appropriate safety checks for distributed environments and correct handling of wrapped functions. Configuration options are also exposed through server arguments. Overall, this is a solid implementation that thoughtfully integrates a new performance optimization.
|
|
||
|
|
||
| self.transformer = enable_cache_on_transformer( | ||
| self.transformer, | ||
| config, | ||
| model_name="transformer", | ||
| ) | ||
| self._cache_dit_enabled = True | ||
| self._cached_num_steps = num_inference_steps | ||
| logger.info( | ||
| "cache-dit enabled successfully on transformer (steps=%d)", | ||
| num_inference_steps, | ||
| ) | ||
|
|
||
|
|
||
| @lru_cache(maxsize=8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These extra blank lines can be removed to improve code compactness.
)
self.transformer = enable_cache_on_transformer(
self.transformer,
config,
model_name="transformer",
)
self._cache_dit_enabled = True
self._cached_num_steps = num_inference_steps
logger.info(
"cache-dit enabled successfully on transformer (steps=%d)",
num_inference_steps,
)
@lru_cache(maxsize=8)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please solve it
| if hasattr(transformer_instance, '_original_forward'): | ||
| target_func = transformer_instance._original_forward |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic relies on an internal attribute _original_forward of the transformer_instance from cache-dit. This creates a tight coupling and could break if cache-dit changes its internal implementation. It would be good to add a comment here to note this dependency, or investigate if cache-dit provides a more stable API for unwrapping functions.
mickqian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up TODOs:
- add to CI
- add docs
| self._cache_dit_enabled = False | ||
| self._cached_num_steps = None | ||
|
|
||
| def _maybe_enable_cache_dit( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use it in denoising_dmd.py?
| return | ||
|
|
||
| # Check if cache-dit is enabled in config | ||
| if not getattr(server_args, "enable_cache_dit", False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not server_args.enable_cache_dit?
| # Check if cache-dit is available | ||
| if not is_cache_dit_available(): | ||
| logger.warning( | ||
| "cache-dit is not installed. Please install it with: pip install cache-dit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add it as a requirement?
|
|
||
|
|
||
| self.transformer = enable_cache_on_transformer( | ||
| self.transformer, | ||
| config, | ||
| model_name="transformer", | ||
| ) | ||
| self._cache_dit_enabled = True | ||
| self._cached_num_steps = num_inference_steps | ||
| logger.info( | ||
| "cache-dit enabled successfully on transformer (steps=%d)", | ||
| num_inference_steps, | ||
| ) | ||
|
|
||
|
|
||
| @lru_cache(maxsize=8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please solve it
| @@ -0,0 +1,190 @@ | |||
| # SPDX-License-Identifier: Apache-2.0 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this file to runtime/utils
|
|
||
| # cache-dit acceleration parameters | ||
| enable_cache_dit: bool = False | ||
| cache_dit_Fn: int = 1 # Number of first blocks to always compute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider supporting these in env vars?
|
Also, could you dump the perf report according to |
done |
|
@Brain97 Great, would you solve the issues |
sure |
|
update the quantizer method to commit |
Motivation
Support cache-dit #13753
Modifications
Accuracy Tests
Benchmarking and Profiling
baseline
sglang generate --model-path black-forest-labs/FLUX.1-dev --prompt "A Logo With Bold Large Text: SGL Diffusion" --save-output --perf-dump-path sglang_no_cache.json
with cache
sglang generate --model-path black-forest-labs/FLUX.1-dev --prompt "A Logo With Bold Large Text: SGL Diffusion" --save-output --enable-cache-dit --cache-dit-warmup 8 --cache-dit-rdt 0.35 --perf-dump-path sglang_with_cache.json
Performance Comparison Report
1. High-level Summary
2. Stage Breakdown
Metadata
N/AN/AChecklist