Repository navigation
[Cosmos3] Mixed W8A8/W8A16 denoising for ModelOpt FP8 checkpoints - #14664
Conversation
…oints. Keep native ModelOpt GEMM on middle steps and dequant-linear W8A16 on the first/last steps so CFG cond/uncond share one precision per scheduler step.
Enable first/last W8A16 only when transformer/config.json declares diffusion_step_policy, so distilled FP8 stays native W8A8 instead of inheriting a hardcoded 3+3 window.
…schedules. Read the checkpoint runtime policy from on-disk transformer/config.json when the live ModelOpt config omits it, fail closed on incomplete policies, and allow FP32 activations on the W8A16 path.
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks for the PR. I think it's a bit intrusive in terms of what it is doing. Could you provide runtime numbers (latency, throughput) and also how does it compare in terms of visual results (with and without comparisons would be great).
… drop unit tests. W8A8/W8A16 is explained without listing call-site overrides; TorchAO and other quantizers keep their native forwards; focused tests are removed until Hub fp8 usage is clearer.
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks for the iteration. Do you think it could make sense to try to think of an approach where we make the changes bit more general, i.e., we make it so that these are done at the Modelopt quantizer class?
Or do you think the pipeline-level call arguments make it difficult to do so?
…e boilerplate. Keep serialized restore in the ModelOpt guide and spell out that all-W8A8 is faster but can flicker on multi-step video.
|
Thanks @sayakpaul for the review. I've updated the PR. I looked at the other Cosmos3 FP8 runtimes that already landed this schedule. None of them put it on the generic ModelOpt loader/quantizer. vLLM-Omni (vllm-project/vllm-omni#6560, merged) keeps policy parse + W8A16 dispatch under SGLang (sgl-project/sglang#36380, merged) does the same from the Cosmos3 denoise stage ( That matches this PR: To align with this PR's counterparts in other runtimes, I'd prefer to keep that split in this PR rather than moving the schedule onto |
|
@bot /style |
|
Style bot fixed some files and pushed the changes. |



What does this PR do?
Adds denoising-step-aware mixed W8A8/W8A16 for Cosmos3 ModelOpt FP8 checkpoints, so official Hub
revision=fp8is not W8A8 on every step.This is the Diffusers counterpart of the FP8 schedule contract in vllm-omni#6560 (not a port of NVFP4, tensor parallel, caches, or
vllm serve).Behavior
weight_only: false). Mixing is runtime.fp8: first 3 + last 3 scheduler steps W8A16 (dequant +F.linear); middle steps native ModelOpt W8A8.reasoner: a16.fp8haveruntime: null→ mixed off, all steps native W8A8.mixed_precision_format=None(default) readsquantization_config.runtime.diffusion_step_policyfrom the transformer (including on-disktransformer/config.jsonwhen the live ModelOpt config omitsruntime)."none"disables only the schedule."fp8"forces it.Code
src/diffusers/pipelines/cosmos/mixed_precision.py— policy parse (fail-closed), linear discovery, W8A16 dispatch.pipeline_cosmos3_omni.pyand modulardenoise.py— apply/reset once per step.docs/source/en/api/pipelines/cosmos3.md— user-facing FP8 mixed section.Tests
Unit (CPU, in-tree):
tests/pipelines/cosmos/test_cosmos3_mixed_precision.py— 17 passed (schedule boundaries, 1-step stays native, reasoner vs generation, overlay of liveruntime: null+ on-disk policy, FP32 W8A16, malformed policy / NVFP4 reject).GPU, not in CI (official Hub
revision=fp8):@fp8: auto-enable 3+3; 8-step T2I E2E with exact trace W8A16×3 / W8A8×2 / W8A16×3; 35-step latent W8A16×3 / W8A8×29 / W8A16×3.@fp8transformer: auto-off; GEMM stays native W8A8.Not claimed in this PR: Super 64B generate, 189-frame I2V, vs-BF16 hashes, or the vLLM-Omni H100 throughput table.
Depends on NVIDIA ModelOpt restore for serialized FP8 (same as existing Cosmos3 FP8 loading).
Self-review (final)
Ran the
self-reviewskill onhuggingface/main...HEADagainst.ai/references/review-rules.md(pluspipelines.md,modular.md,testing.md,code_style.md,pitfalls.md).Diff files:
mixed_precision.py,pipeline_cosmos3_omni.py,modular_pipelines/cosmos/denoise.py,test_cosmos3_mixed_precision.py,docs/source/en/api/pipelines/cosmos3.md.Blocking issues: none.
Non-blocking — left for review (deliberate):
forwardwrappers stay installed after__call__(mixed_precision.py). Inactive wrappers call the original ModelOpt forward. Perpipelines.mdgotcha 7 we could uninstall on exit (PAG-style); we kept wrappers to avoid re-wrapping hundreds of linears each generate.layer.weightthenF.linear. Pertesting.md, that bypasses group-offload leaf hooks. Same dense A16 reference as vLLM-Omni; group offload + serialized FP8 was not a target.unittest.TestCase. Pertesting.md, new pipeline tests prefer real tiny classes and pytest mixins. Existing Cosmos3 pipeline tests are still unittest; ModelOpt restore is impractical in CI.mixed_precision_overlapis parsed from the checkpoint /resolve(), not exposed onCosmos3OmniPipeline.__call__.revision="fp8"example does not repeat full ModelOptfrom_pretrainedkwargs; loading still follows the ModelOpt guide.Dead code:
FIRST_LAST_N_FP8_POLICY,from_kwargs, andquantization_config_from_moduleare used (tests +resolve). No unused runtime methods.Verdict: READY.
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu @asomoza