[Cosmos3] Mixed W8A8/W8A16 denoising for ModelOpt FP8 checkpoints - #14664
Open
ConstBob wants to merge 4 commits into
Open
[Cosmos3] Mixed W8A8/W8A16 denoising for ModelOpt FP8 checkpoints#14664ConstBob wants to merge 4 commits into
ConstBob wants to merge 4 commits into
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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