-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Cosmos3] Mixed W8A8/W8A16 denoising for ModelOpt FP8 checkpoints #14664
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
ConstBob
wants to merge
4
commits into
huggingface:main
Choose a base branch
from
ConstBob:feat/cosmos3-mixed-w8a8-w8a16
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.
+1,119
−129
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b94bf63
Add opt-in mixed W8A8/W8A16 denoising for Cosmos3 ModelOpt FP8 checkp…
ConstBob 261265f
Merge branch 'huggingface:main' into feat/cosmos3-mixed-w8a8-w8a16
ConstBob 37c9248
Read Cosmos3 mixed-precision schedule from the checkpoint policy.
ConstBob 6939c05
Harden Cosmos3 mixed-precision loading and document official Hub fp8 …
ConstBob 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,33 @@ Two checkpoints are released on the Hub — [`nvidia/Cosmos3-Nano`](https://hugg | |
| > [!TIP] | ||
| > Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) section to learn how to efficiently load the same components into multiple pipelines. | ||
|
|
||
| ## FP8 mixed W8A8/W8A16 denoising | ||
|
|
||
| Official ModelOpt FP8 checkpoints live on the Hub `fp8` revision (for example [`nvidia/Cosmos3-Nano`](https://huggingface.co/nvidia/Cosmos3-Nano) with `revision="fp8"`). The serialized weights are static W8A8. Video Nano / Super / Super-I2V checkpoints also store a `quantization_config.runtime.diffusion_step_policy` on the transformer: the **first 3 and last 3** denoising steps run **W8A16** (dequantized FP8 weights, `torch.nn.functional.linear`), and the middle steps keep native **W8A8**. Precision is chosen once per scheduler step so CFG cond/uncond calls match. Distilled 4-step and Super-T2I FP8 checkpoints omit that policy (`runtime` is `null`) and stay native W8A8 on every step. | ||
|
|
||
| Loading those weights still uses [`NVIDIAModelOptConfig`](../../quantization/modelopt) as in the ModelOpt guide. After restore, mixed precision is **on by default** when the checkpoint declares the policy — you do not pass a format flag: | ||
|
|
||
| ```python | ||
| import torch | ||
| from diffusers import Cosmos3OmniPipeline | ||
|
|
||
| pipe = Cosmos3OmniPipeline.from_pretrained( | ||
| "nvidia/Cosmos3-Nano", | ||
| revision="fp8", | ||
| dtype=torch.bfloat16, | ||
| device_map="cuda", | ||
| ) | ||
| result = pipe(prompt="...", num_inference_steps=35) # 3×W8A16 / 29×W8A8 / 3×W8A16 | ||
| ``` | ||
|
|
||
| Call-site overrides: | ||
|
|
||
| - `mixed_precision_format="none"` disables the schedule only (quantized W8A8 remains). | ||
| - `mixed_precision_format="fp8"` forces the first/last-N schedule even if the checkpoint has no policy. | ||
| - `mixed_precision_first_steps` / `mixed_precision_last_steps` / `mixed_precision_reasoner_policy` override the checkpoint counts and reasoner path (`"high_precision"` = W8A16, `"base_precision"` = native W8A8). | ||
|
|
||
| These kwargs are not Accelerate `mixed_precision`. They only select W8A8 vs W8A16 on Cosmos3 ModelOpt linears. | ||
|
Comment on lines
+65
to
+71
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. I don't think we need to mention things like these. If we want the users to control them, we could simplify the text. |
||
|
|
||
| ## Prompt upsampling | ||
|
|
||
| Cosmos 3 was trained on long, highly descriptive captions. For optimal quality, short text prompts should be **upsampled into a specific JSON structure** before they are passed to the pipeline. The upsampler lives in the [cosmos-framework](https://github.com/NVIDIA/cosmos-framework) package. | ||
|
|
@@ -1117,6 +1144,9 @@ config (from the checkpoint's `modular_model_index.json`) and `guidance_scale` i | |
| 1.0 since guidance is baked into the weights — passing any other value for either raises an error, | ||
| and `negative_prompt` is warned about and ignored. | ||
|
|
||
| FP8 distilled checkpoints (`revision="fp8"`) do not declare a mixed-precision policy, so every | ||
| step stays native W8A8. | ||
|
|
||
| Prompts follow the same descriptive JSON structure as the non-distilled models, so short text | ||
| must be upsampled first — use `--mode text2image` (T2I) or `--mode image2video` (I2V) as | ||
| described in [Prompt upsampling](#prompt-upsampling), then pass the JSON via `json.dumps(...)`. | ||
|
|
||
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.
Users may not be familiar with the convention of W8A8. It would make sense to elaborate on that.