Skip to content

[diffusion] Continuous batching v0 - #28690

Closed
qimcis wants to merge 15 commits into
sgl-project:mainfrom
qimcis:continous-batch
Closed

qimcis wants to merge 15 commits into
sgl-project:mainfrom
qimcis:continous-batch

Conversation

@qimcis

@qimcis qimcis commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add T2I continuous batching support for SGLang-Diffusion

Continuous batching lets diffusion requests join and leave the active batch mid-flight by batching compatible denoising steps across active requests, instead of only batching requests before denoising starts. This is intended to improve throughput and latency under bursty or concurrent image-generation traffic.

Modifications

Accuracy Tests

baseline:
qwen_1024_no_batch_seed_4401

continuous batching:
qwen_1024_seed_4401_continuous_batched

Speed Tests and Profiling

1x h100

Baseline

python3 -m sglang.multimodal_gen.runtime.entrypoints.cli.main serve \
  --model-path Qwen/Qwen-Image-2512 \
  --backend sglang \
  --num-gpus 1 \
  --host 0.0.0.0 \
  --port 30200 \
  --log-level info \
  --output-path "" \
  --warmup-mode off \
  --performance-mode speed \
  --dit-cpu-offload false \

Dynamic batching:

python3 -m sglang.multimodal_gen.runtime.entrypoints.cli.main serve \
  --model-path Qwen/Qwen-Image-2512 \
  --backend sglang \
  --num-gpus 1 \
  --host 0.0.0.0 \
  --port 30200 \
  --log-level info \
  --output-path "" \
  --warmup-mode off \
  --performance-mode speed \
  --dit-cpu-offload false \
  --batching-mode dynamic \
  --batching-max-size 4 \
  --batching-delay-ms 5 \
  --enable-batching-metrics

Continuous batching:

python3 -m sglang.multimodal_gen.runtime.entrypoints.cli.main serve \
  --model-path Qwen/Qwen-Image-2512 \
  --backend sglang \
  --num-gpus 1 \
  --host 0.0.0.0 \
  --port 30200 \
  --log-level info \
  --output-path "" \
  --warmup-mode off \
  --performance-mode speed \
  --dit-cpu-offload false \
  --batching-mode continuous \
  --batching-max-size 4 \
  --batching-delay-ms 5 \
  --enable-batching-metrics
Resolution Mode n Throughput (req/s) Δ vs No Batch Mean Lat (s) Δ P99 Lat (s) Δ Duration (s) Δ Peak Mem (MB)
512x512 No Batching 3 0.125 baseline 31.17 baseline 32.28 baseline 510.71 baseline 55071
512x512 Dynamic Batching 3 0.218 +73.8% 18.14 -41.8% 18.98 -41.2% 293.91 -42.5% 57699
512x512 Continuous Batching 3 0.294 +134.5% 13.60 -56.4% 13.73 -57.5% 217.80 -57.4% 57539
768x768 No Batching 3 0.116 baseline 33.64 baseline 34.66 baseline 551.12 baseline 56341
768x768 Dynamic Batching 3 0.135 +16.4% 29.26 -13.0% 31.85 -8.1% 473.34 -14.1% 61809
768x768 Continuous Batching 3 0.142 +22.2% 28.18 -16.2% 28.28 -18.4% 451.02 -18.2% 58028
1024x1024 No Batching 3 0.073 baseline 52.40 baseline 55.10 baseline 439.79 baseline 58602
1024x1024 Dynamic Batching 3 0.078 +6.9% 50.20 -4.2% 55.57 +0.8% 411.31 -6.5% 68127
1024x1024 Continuous Batching 3 0.078 +7.3% 51.20 -2.3% 51.47 -6.6% 409.94 -6.8% 58768

After Qwen benchmark, I also ran smaller benchmarks across Qwen, FLUX2 Klein, Z-Image, SANA, ERNIE, GLM, and Ideogram to verify model compatability

Checklist

  • Format your code according to the pre-commit hooks.
  • Add unit tests according to the contribution guide.
  • Update documentation according to the documentation guide.
  • Provide speed benchmark results.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ❌ Run #29277752170
Latest PR Test (Extra): ❌ Run #29277751959

@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 documentation Improvements or additions to documentation diffusion SGLang Diffusion jit-kernel labels Jun 18, 2026
@qimcis

qimcis commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

qimcis and others added 5 commits July 13, 2026 10:53
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@qimcis
qimcis force-pushed the continous-batch branch from 903de8c to b7db4ad Compare July 13, 2026 19:15
detain added a commit to detain/sglang that referenced this pull request Oct 8, 2026
…28690)

Squash-apply of PR sgl-project#28690 head b7db4ad (15 commits, base 2026-07-13)
since the branch history is fixup-heavy and pre-dates several upstream
refactors. Net feature unchanged:

- scheduler: continuous batching loop, stage worker (async encode),
  varlen step packing, TeaCache packed plans, CFG batch folding,
  dynamic-cap admission; --batching-mode continuous
- pipeline configs: continuous_batching_supported_tasks /
  supports_cfg_batch_folding / supports_varlen_step_packing capability
  flags, per-model opt-ins (flux/qwen/wan/zimage/ideogram/sana/ernie/
  glm/stablediffusion3)
- denoising: context/step-state split (prepare_denoising_context,
  prepare_denoising_step_state, run_single_denoising_step) so packed
  and unpacked paths share one step implementation
- new files: runtime/managers/continuous_batching.py,
  continuous_stage_worker.py, pipelines_core/batched_solver.py,
  fallback_diagnostics.py + 3 unit tests + docs
- cutedsl scale_residual kernel: normalize_packed_scale_shift for
  per-row packed scale/shift (file now under kernels/ops/diffusion/norm/)

Conflicts resolved against the current tree:
- scheduler metrics keep output-slot vocabulary and accept the PR's
  batch_size kwargs via an alias in _record_batch_dispatch_metrics
- wan DiT forward keeps spectrum/rope_cos_sin_cache paths inside the
  PR's teacache_plan packed/else split; _WanGELUMLP preserved
- qwen DiT keeps fused-QKV-epilogue (gated off when per-token rope
  positions are present) + positions threaded through fallback path
- denoising keeps LiteAttention registry reset (c428f58) alongside
  the PR's context preparation refactor
- auto_tune skips tuning in continuous mode using current
  enable_dit_layerwise_offload_by_default() name
- docs landed under docs/docs/sglang-diffusion/ (docs_new rename)
detain added a commit to detain/sglang that referenced this pull request Oct 8, 2026
…mixin

sgl-project#28690's fake predates _init_teacache_state reading self.prefix
(CFG cache separation). Amends the squash-pick 1d411e4.
detain added a commit to detain/sglang that referenced this pull request Oct 8, 2026
Triage of the full multimodal_gen unit battery after entries 136-155:
- scheduler.event_loop: the sgl-project#28690 continuous-batching guard read
  self.server_args unconditionally; the metrics tests drive event_loop
  on __new__-built schedulers. getattr-chained (real schedulers always
  have server_args). 8 tests restored.
- test_text_encode_dp_gate: SimpleNamespace double lacked the cb_*
  fields _validate_batching (from sgl-project#28690) checks. 1 test restored.
- test_layerwise_offload: register-time content assert predates the
  09-28-merged sgl-project#40439 register-then-populate design (pre-existing
  failure since that merge; runtime unchanged by this batch -- the
  upstream test version assumes upstream manager code we don't have,
  so adapt in place). 2 tests restored.
227 passed across the four affected files incl. continuous-batching.
Remaining battery failures are ENV: runai_model_streamer, skimage,
os.memfd_create, msgpack absences + SM100-only nvfp4 kernels.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @qimcis. Closing this because it has had no updates in 91 days.

Reopen it if the work is still relevant.

Some directories moved recently, so an older branch may need retargeting:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation jit-kernel 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