Skip to content

[Perf] diffusion: Remove per-step and per-request host syncs in Cosmos3 and Qwen-Image-2.1 - #45967

Merged
mickqian merged 2 commits into
mainfrom
mick/diffusion-image-request-overhead-v2
Oct 23, 2026
Merged

mickqian merged 2 commits into
mainfrom
mick/diffusion-image-request-overhead-v2

Conversation

@mickqian

@mickqian mickqian commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Two blocking device reads sit on the host's critical path:

  1. Cosmos3, every step. The denoising loop checked the CFG window, and the Transfer control-CFG window, with t.item() on the device timestep. So the host waited for each step's kernels to finish before it launched the next step.
  2. Qwen-Image-2.1 edit, every request. The edit path built the VAE latent mean/std with new_tensor right after launching the condition-image VAE encode. That pageable upload made the host wait for the encode before it could start the prompt's image preprocessing.

Modifications

  • cosmos3.py: the loop takes one host copy of the timestep schedule (timesteps.tolist()), and _cfg_active_at reads the window from those floats. The per-step decisions and kernels are unchanged.
  • qwen_image21.py: QwenImage21EncodingStage uploads the latent mean/std once per (dtype, device) and reuses them, so the preprocessing overlaps the encode. The normalization is bit-identical.

Tests:

  • test_cosmos3_rollout.py::test_cfg_window_check_reads_host_timesteps: runs the denoising loop with a [400, 1000] CFG window over timesteps whose item() / float() / bool() raise. The window must still choose batched CFG at 999, 700 and 400, and the cond branch alone at 399 and 100. It fails on main.
  • test_qwen_image21.py::test_condition_latents_reuse_uploaded_latent_stats: two edit requests must produce the reference-normalized condition latents bitwise, and the second request must reuse the first one's mean/std tensors (checked by identity).

No files are shared with #45942, #45943, #45944 or #45948.

Accuracy Tests

The output pixels are identical across arms for both models.

Speed Tests and Profiling

Server benchmark, 2 interleaved rounds x 5 repeats, e2e. Each commit was measured on its own against the same base.

case GPUs base (round 1 / 2) this PR (round 1 / 2)
Cosmos3-Nano T2I 720p, eager, CFG parallel 2xH200 0.928 / 0.929 s 0.920 / 0.920 s (−8 ms)
Qwen-Image-2.1 edit 1024 1xH200 5.300 / 5.302 s 5.285 / 5.284 s (−17 ms)

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #39900393237
Latest PR Test (Extra): ❌ Run #39900393310
Latest PR Test (AMD ROCm 10): ⏳ Run #39900393090

mickqian and others added 2 commits October 23, 2026 12:21
The denoising loop checked the CFG window with `t.item()` on the device
timestep every step, so the host waited for each step's kernels before
launching the next one. Read the window from one host copy of the
schedule instead; the per-step decisions and kernels are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The edit path built the VAE latent mean/std with `new_tensor` on every
request, right after launching the condition-image VAE encode. That
blocking upload made the host wait for the encode before it could start
the prompt's image preprocessing. Keep the device tensors per (dtype,
device) so the preprocessing overlaps the encode; the normalization is
bit-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR labels Oct 23, 2026
@mickqian
mickqian merged commit 1cd0ebb into main Oct 23, 2026
188 of 200 checks passed
@mickqian
mickqian deleted the mick/diffusion-image-request-overhead-v2 branch October 23, 2026 07:30
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.

1 participant