-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Add SeaCache support for Cosmos3 pipelines #14663
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
Open
yzhautouskay
wants to merge
13
commits into
huggingface:main
Choose a base branch
from
yzhautouskay:yzhautouskay/cosmos3_diffusion_caching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
981fe04
Add optional FP32 sampling state for Cosmos3
yzhautouskay 1dac4d4
Add cache execution contexts to Cosmos3 pipelines
yzhautouskay 613e441
Add SeaCache support for Cosmos3
yzhautouskay 12f66f6
Cap consecutive SeaCache reuses
yzhautouskay 54c4cc5
Align SeaCache defaults with Cosmos3 inference
yzhautouskay 058c0e9
Enable SeaCache by default for Cosmos3
yzhautouskay 9985bf7
Document SeaCache for Cosmos3
yzhautouskay e185225
Use FP32 sampling state by default for Cosmos3
yzhautouskay 2cf229c
Fix SeaCache reconfiguration, transfer state isolation, and FP32 samp…
yzhautouskay 3e68be9
Remove SeaCache stats and ablation instrumentation
yzhautouskay 21c75ca
Move SeaCache to transformer-level and disable by default
yzhautouskay 0d3c8d6
Align SeaCache and tests with model-level cache patterns
yzhautouskay b6b564f
Make Cosmos3 sampling state always FP32
yzhautouskay 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,34 @@ config = FasterCacheConfig( | |
| pipeline.transformer.enable_cache(config) | ||
| ``` | ||
|
|
||
| ## SeaCache | ||
|
|
||
| [SeaCache](https://huggingface.co/papers/2602.18993) compares Spectral-Evolution-Aware (SEA) indicators between | ||
| successive denoising steps. When the accumulated indicator change remains below a threshold, it skips the expensive | ||
| transformer block stack and predicts its output from cached residuals. | ||
|
|
||
| SeaCache is disabled by default. Enable it on the transformer and provide callbacks for the active scheduler step, | ||
| sigma, and number of inference steps: | ||
|
|
||
| ```python | ||
| from diffusers import Cosmos3OmniPipeline, SeaCacheConfig | ||
|
|
||
| pipe = Cosmos3OmniPipeline.from_pretrained("nvidia/Cosmos3-Nano") | ||
| pipe.transformer.enable_cache( | ||
| SeaCacheConfig( | ||
| threshold=0.2, | ||
| max_consecutive_cached=2, | ||
| current_step_callback=lambda: pipe.current_step_index, | ||
| current_sigma_callback=lambda: pipe.current_sigma, | ||
| num_inference_steps_callback=lambda: pipe.num_timesteps, | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
||
| This model-level API works with [`Cosmos3OmniPipeline`], [`Cosmos3OmniModularPipeline`], and | ||
| [`Cosmos3DistilledModularPipeline`]. SeaCache is an approximate optimization and may change generated outputs. Call | ||
| `pipe.transformer.disable_cache()` when you need every denoising step to execute the full transformer. | ||
|
Comment on lines
+95
to
+97
Member
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. Nice, thanks for the note! From a quick skim of the paper, it doesn't look like it needs to be Cosmos3 specific no? |
||
|
|
||
| ## FirstBlockCache | ||
|
|
||
| [FirstBlock Cache](https://huggingface.co/docs/diffusers/main/en/api/cache#diffusers.FirstBlockCacheConfig) checks how much the early layers of the denoiser changes from one timestep to the next. If the change is small, the model skips the expensive later layers and reuses the previous output. | ||
|
|
||
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
Oops, something went wrong.
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.
Would it make sense to provide actual values here? Or maybe even just specify what
pipeis supposed to be?