Skip to content

Add Cosmos3 Edge and Distilled checkpoints support - #31590

Merged
mickqian merged 20 commits into
sgl-project:mainfrom
nv-dmajchrowski:feat/add-cosmos3-edge-distil
Aug 12, 2026
Merged

mickqian merged 20 commits into
sgl-project:mainfrom
nv-dmajchrowski:feat/add-cosmos3-edge-distil

Conversation

@nv-dmajchrowski

@nv-dmajchrowski nv-dmajchrowski commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

PRs #24994, #26492 and #27168 added support for the Cosmos3 model family. This PR extends that support to the Cosmos3 Edge and Distilled variants. All variants continue to be served by the single Cosmos3 pipeline, with the variant selected from the checkpoint config at load time.

Modifications

Cosmos3 Edge

  • Add a dense squared-ReLU MLP variant of the transformer, selected from transformer/config.json (hidden_act: relu2 / backbone_type); the gated (SwiGLU) path is unchanged.
  • Make per-head QK-norm on the text self-attention optional (qk_norm_for_text).
  • Derive the MLP weight mapping (merged vs. unmerged gate/up) and RoPE theta from the checkpoint config instead of hard-coded values.
  • Add Edge resolution / guidance / flow-shift sampling defaults, resolved per request.

Distilled (few-step) checkpoints

  • Detect distilled checkpoints from the scheduler config (FlowMatchEulerDiscreteScheduler + fixed_step_sampler_config.t_list) and drive the scheduler from its explicit fixed-step sigma schedule (step
    count = len(sigmas)).
  • Force guidance_scale = 1.0 for distilled inference (single forward, no CFG).
  • Drop scheduler-config keys the scheduler constructor does not accept in the scheduler loader (generic; a no-op for schedulers that already accept them).

Checkpoint format compatibility

  • Register Cosmos3OmniPipeline and keep Cosmos3OmniDiffusersPipeline as a back-compat alias, so both the new and legacy model_index.json _class_name spellings resolve to the same pipeline.
  • Broaden the _class_name detector to match both.

Others

  • Copied changes from #30569 to make it work with new model format.
  • Drop ModelOpt calibration buffers (*_quantizer.*) during weight load so the new format FP8 path reads the weight/input scales correctly.
  • Thread a per-request, SP-synchronized generator into the stochastic (SDE) scheduler step so sequence-parallel ranks draw identical noise, fixing shard-boundary artifacts under Ulysses.

For reference see vllm-omni PR

Accuracy Tests

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 #31552675351
Latest PR Test (Extra): ❌ Run #31552675179

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the Cosmos3-Edge model variant and distilled checkpoints in the SGLang multimodal generation pipeline. Key changes include implementing dense squared-ReLU MLPs, supporting optional QK-normalization, dynamically resolving sampling defaults (resolution, guidance, and steps) for Edge and distilled checkpoints, and ensuring stochastic noise is consistently seeded across sequence-parallel ranks. Reviewer feedback highlights several improvement opportunities, such as resetting the scheduler shift to 1.0 for distilled checkpoints to prevent double-shifting, adding defensive guards against null or empty model paths and server arguments to avoid potential crashes, wrapping signature inspection in a try-except block, and aligning the torch Generator's device with the latents to prevent device mismatch errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@nv-dmajchrowski
nv-dmajchrowski force-pushed the feat/add-cosmos3-edge-distil branch 2 times, most recently from b010020 to e66d109 Compare July 17, 2026 15:33
fps: int = 24

guidance_scale: float = 4.0
guidance_scale: float | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nv-dmajchrowski
I think this default will make warmup fail. See following error for warmup:
[07-17 22:30:40] Synthetic server warmup failed; continuing startup
Traceback (most recent call last):
File "/sgl-workspace/sglang/python/sglang/multimodal_gen/runtime/server_warmup.py", line 160, in run_async_client_warmup
for req in build_client_warmup_reqs(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sgl-workspace/sglang/python/sglang/multimodal_gen/runtime/server_warmup.py", line 135, in build_client_warmup_reqs
warmup_reqs = build_warmup_reqs(
^^^^^^^^^^^^^^^^^^
File "/sgl-workspace/sglang/python/sglang/multimodal_gen/runtime/warmup_request_builder.py", line 392, in build_warmup_reqs
req = Req(**prompt_req_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/sgl-workspace/sglang/python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py", line 247, in init
self.validate()
File "/sgl-workspace/sglang/python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py", line 360, in validate
if cfg_scale > 1.0 and self.negative_prompt is not None:
^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'NoneType' and 'float'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out, I've pushed the fix.

@mickqian

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 21, 2026
@nv-dmajchrowski
nv-dmajchrowski force-pushed the feat/add-cosmos3-edge-distil branch from d570bc0 to 4c95be4 Compare July 30, 2026 06:47
@nv-dmajchrowski

Copy link
Copy Markdown
Contributor Author

@mickqian after the previous approval we had to add few more changes (edge checkpoint format changed slightly after the release + we had small accuracy issues). We have completed accuracy testing for both edge and distil and the number looks good, so from our side this PR is ready to be merged. Could you review, so we can merge it and follow up with user guides for sglang on github and HF? FYI, I will be off next 2 weeks, @kediwu0331 will help resolving any comments on this.

@kediwu0331
kediwu0331 force-pushed the feat/add-cosmos3-edge-distil branch from 4c95be4 to ad7af0c Compare August 3, 2026 19:06
@mickqian

mickqian commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

@nv-dmajchrowski @kediwu0331 of course, genuinely appreciate your help

@mickqian

mickqian commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

also please fix lint

@kediwu0331

Copy link
Copy Markdown
Contributor

@mickqian thanks, it was transient error. passed now.

@kediwu0331

Copy link
Copy Markdown
Contributor

@mickqian I resolved the recent conflict due to action endpoint reconfiguration. Also I added multipart form support for /v1/actions/generations endpoint. Let me know if you are ok with this change.

@mickqian

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@kediwu0331

Copy link
Copy Markdown
Contributor

/rerun-failed-ci

@mickqian
mickqian merged commit f7b6800 into sgl-project:main Aug 12, 2026
126 of 137 checks passed
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
)

Co-authored-by: Kedi Wu <31940276+kediwu0331@users.noreply.github.com>
Co-authored-by: Kedi Wu <kediw@nvidia.com>
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
)

Co-authored-by: Kedi Wu <31940276+kediwu0331@users.noreply.github.com>
Co-authored-by: Kedi Wu <kediw@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants