Skip to content

[diffusion] RL rollout support for the Cosmos3 pipeline#30486

Draft
zhihengy wants to merge 4 commits into
sgl-project:mainfrom
Rockdu:feat/cosmos3-rl-rollout
Draft

[diffusion] RL rollout support for the Cosmos3 pipeline#30486
zhihengy wants to merge 4 commits into
sgl-project:mainfrom
Rockdu:feat/cosmos3-rl-rollout

Conversation

@zhihengy

@zhihengy zhihengy commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Motivation

GRPO-style post-training for Cosmos3 needs rollout log-probs from the serving engine. This wires the existing post-training rollout machinery (SDE-Euler + log-prob, per-request scheduler binding from #30036) into the Cosmos3 pipeline, which uses hand-rolled stages rather than the generic denoising loop.

Modifications

  • Cosmos3TimestepPreparationStage: rollout=True requests lazily bind a flow-match Euler scheduler that reuses the serving scheduler's sigma grid (set_timesteps(sigmas=...)) — the Cosmos3 checkpoint ships a Karras flow-sigma schedule, so grid reuse keeps rollout noise levels exactly at serving parity regardless of scheduler config.
  • Cosmos3DenoisingStage: RolloutDenoisingMixin hooks (prepare, per-step pre-step latent snapshots, SDE step via flow_sde_sampling, postprocess). The denoising env ships text_ids/text_mask (cond+uncond) + fps — KB-scale vs ~150MB/sample for per-layer KV. I2V+rollout is rejected (frame-0 re-injection breaks the Gaussian transition assumption).
  • RolloutDitTrajectory gains a sigmas snapshot (serialized in the rollout API) so trainers replay exact noise levels instead of reconstructing timesteps/1000 (fp32 round-trip drifts, and a Karras grid cannot be reconstructed at all).
  • WeightsUpdater fused-param fix: the tensor-update path dropped the param-mapping merge index, so fused params (to_qkv, gate_up_proj) narrowed out of bounds — Cosmos3 is the first fused-param model through this path. The merge index now reaches weight_loader as the shard id.
  • jit_kernel fa3: drop only_qv=False before the kernel call so older sgl-kernel builds without the argument keep working.
  • Cosmos3DecodingStage: propagate rollout_trajectory_data to OutputBatch.

Includes the two per-request rollout-scheduler infra files from #30036; will rebase once that lands.

Validation

Trained against miles-d (radixark/miles_diffusion#25): rollout↔train log-prob ratio_abs_minus_1 = 1–2.5e-5 across T2I and 17-frame T2V; SDE-Euler at 16 steps matches UniPC-35 output quality (PickScore + visual). Non-rollout serving paths untouched (rollout branch gated on batch.rollout).


CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

zhihengy and others added 2 commits July 8, 2026 00:47
Bind a flow-match Euler scheduler to rollout=True requests (same
per-request switch as the Wan rollout PR), reusing the serving
scheduler's sigma grid so rollout noise levels match serving exactly.
The denoising env ships text_ids/text_mask (cond+uncond) and fps; the
dit trajectory now carries the scheduler sigma snapshot so the training
side replays exact noise levels.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- WeightsUpdater: carry the param-mapping merge index through to
  weight_loader as the shard id; fused params (to_qkv, gate_up_proj)
  previously narrowed out of bounds. Cosmos3 is the first fused-param
  model through the tensor-update path.
- jit_kernel fa3: drop only_qv=False before calling the kernel so older
  sgl-kernel builds without the argument keep working.
- Cosmos3DecodingStage: propagate rollout_trajectory_data to OutputBatch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added diffusion SGLang Diffusion jit-kernel labels Jul 8, 2026
zhihengy and others added 2 commits July 9, 2026 02:01
…ted grid

The checkpoint's karras schedule ignores flow_shift; an explicit
override now builds the rollout Euler grid with the requested shift
(smoke: karras-16 still scores best, shift grids stay within the
UniPC-35 band but degrade visibly at shift 2-3).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Imported CUDA-IPC blocks stay cached in the consumer allocator until
torch.cuda.ipc_collect(), pinning the sender's exported storage. Large
models (Cosmos3-Super, 128GB sync volume) OOM the trainer mid-sync.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion jit-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant