Skip to content

Cosmos3 fp8 mixed precision - #36380

Merged
mickqian merged 12 commits into
sgl-project:mainfrom
kediwu0331:cosmos3-fp8-high-precision
Sep 4, 2026
Merged

mickqian merged 12 commits into
sgl-project:mainfrom
kediwu0331:cosmos3-fp8-high-precision

Conversation

@kediwu0331

@kediwu0331 kediwu0331 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Motivation

Improve the quality of generated video for Cosmos3 fp8 checkpoint. Parse diffusion_step_policy from modelopt fp8 checkpoint. Use W8A16 for specified steps of denoising stage.

Modifications

  • add StepMixedPrecisionController to control steps to use W8A16.
  • apply_fp8_w8a16_linear dequantizes the fp8 weight per call and runs a plain bf16 F.linear.
  • mixed precision behavior is controlled by diffusion_step_policy in checkpoint DiT config. (e.g. https://huggingface.co/nvidia/Cosmos3-Nano/blob/fp8/transformer/config.json#L180)
  • added envvar SGLANG_DIFFUSION_ENABLE_COSMOS3_STEP_MIXED_PRECISION, default is on. If turned off, the mixed precision will not take effect no matter if diffusion_step_policy exists in checkpoint config or not.

Accuracy Tests

Accuracy validated for Nano, Super, Super i2v.

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #33800700111
Latest PR Test (Extra): ❌ Run #33800699651
Latest PR Test (AMD ROCm 7.2): ⏳ Run #33800699908

@kediwu0331
kediwu0331 force-pushed the cosmos3-fp8-high-precision branch from 1f524a4 to 68c6799 Compare August 25, 2026 22:41
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Aug 26, 2026
…ions

A ModelOpt checkpoint carries one activation scale per projection, calibrated
as a max over the whole sampling trajectory ('calib_cfg': {'method': 'max'}).
That single scale fits the first and last denoising steps worst. Those steps
can instead run the resident FP8 weights through a 16-bit GEMM: the weight is
dequantized with its own weight_scale and input_scale goes unused, while the
middle steps keep the checkpoint's fully quantized path.

Nothing extra is read from the checkpoint -- same weights, same scales, no
second checkpoint and no persistent dequantized copy. first_steps/last_steps
are a runtime policy, not a calibrated quantity: the checkpoint records no
per-step information of any kind (no step/timestep/schedule tensors, one
scale per module across all 896 quantized modules).

vLLM-Omni (vllm-project/vllm-omni#6560) and SGLang (sgl-project/sglang#36380)
both landed the same mitigation with the same 3/3 windows and the same
one-step warmup carve-out. This matches their semantics; the defaults follow
SGLang, which enables it for every ModelOpt FP8 Cosmos3 checkpoint.

Unlike either of those, this topology quantizes shared activations *above*
the Linear -- gate/up and q/k/v each quantize once and hand the same tensor to
their projections, and swiglu_2in emits FP8 straight into down_proj. All three
must stand down while a 16-bit step is selected, or the step still runs on FP8
activations and the feature is silently absent. A quantization method advertises
that by publishing 'high_precision'; the sharing sites consult it, and
apply_fp8_w8a16_linear raises rather than accept an already-quantized
activation.

Precision is selected once per step from a pure function of the step index, so
a step's conditional and unconditional CFG branches cannot disagree.

Enabled by default for static FP8, off via
VisualGenArgs.step_precision_config.enable; only static FP8 qualifies, since
dynamic quantization derives its scale per call and has no calibration
mismatch for the outer steps to avoid.

Signed-off-by: Igor Shovkun <igshov@gmail.com>
…ision

# Conflicts:
#	python/sglang/multimodal_gen/runtime/loader/fsdp_load.py
#	python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py
@kediwu0331 kediwu0331 changed the title Cosmos3 fp8 high precision Cosmos3 fp8 mixed precision Sep 1, 2026
@kediwu0331

Copy link
Copy Markdown
Contributor Author

@mickqian could you help review this PR?

@mickqian

mickqian commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci label Sep 2, 2026
@kediwu0331

kediwu0331 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@mickqian I think the requested test case failure is due to transient network issue. Could you help rerun the failed test cases?

@mickqian
mickqian merged commit 94eb15e into sgl-project:main Sep 4, 2026
130 of 143 checks passed
StevenChenSE pushed a commit to StevenChenSE/sglang that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants