-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[diffusion] Enable Cache‑DiT config for diffusers backend #16662
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,7 +235,9 @@ class ServerArgs: | |
|
|
||
| # Attention | ||
| attention_backend: str = None | ||
| diffusers_attention_backend: str = None # for diffusers backend only | ||
| cache_dit_config: str | dict[str, Any] | None = ( | ||
| None # cache-dit config for diffusers | ||
| ) | ||
|
|
||
| # Distributed executor backend | ||
| nccl_port: Optional[int] = None | ||
|
|
@@ -452,15 +454,25 @@ def add_cli_args(parser: FlexibleArgumentParser) -> FlexibleArgumentParser: | |
| "--attention-backend", | ||
| type=str, | ||
| default=None, | ||
| choices=[e.name.lower() for e in AttentionBackendEnum] + ["fa3", "fa4"], | ||
| help="The attention backend to use. If not specified, the backend is automatically selected based on hardware and installed packages.", | ||
| help=( | ||
| "The attention backend to use. For SGLang-native pipelines, use " | ||
| "values like fa, torch_sdpa, sage_attn, etc. For diffusers pipelines, " | ||
| "use diffusers attention backend names such as flash, _flash_3_hub, " | ||
| "sage, or xformers." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--diffusers-attention-backend", | ||
| type=str, | ||
| dest="attention_backend", | ||
| default=None, | ||
| help="Attention backend for diffusers pipelines (e.g., flash, _flash_3_hub, sage, xformers). " | ||
| "See: https://huggingface.co/docs/diffusers/main/en/optimization/attention_backends", | ||
| help=argparse.SUPPRESS, | ||
| ) | ||
| parser.add_argument( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might function well. but we use env vars for non-diffusers-backend, introducing such a new arg could cause confusion |
||
| "--cache-dit-config", | ||
| type=str, | ||
| default=ServerArgs.cache_dit_config, | ||
| help="Path to a Cache-DiT YAML/JSON config. Enables cache-dit for diffusers backend.", | ||
| ) | ||
|
|
||
| # HuggingFace specific parameters | ||
|
|
@@ -999,7 +1011,7 @@ def check_server_args(self) -> None: | |
| raise ValueError("pipeline_config is not set in ServerArgs") | ||
|
|
||
| self.pipeline_config.check_pipeline_config() | ||
| if self.attention_backend is None: | ||
| if self.attention_backend is None and self.backend != Backend.DIFFUSERS: | ||
| self._set_default_attention_backend() | ||
|
|
||
| # parallelism | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
try...except Exceptionblock is very broad. Whilelogger.exceptionis helpful for debugging, catching a genericExceptioncan mask specific issues that might arise fromcache_dit.enable_cache. Consider catching more specific exceptions if known, or at least adding a comment explaining why a broad exception is necessary here (e.g., due to the external nature of thecache_ditlibrary and its potential to raise various exceptions).