Skip to content

[diffusion] feat: overlap declared-parallel pipeline stages - #33036

Draft
mickqian wants to merge 16 commits into
sgl-project:mainfrom
mickqian:feat/parallel-stage-groups
Draft

mickqian wants to merge 16 commits into
sgl-project:mainfrom
mickqian:feat/parallel-stage-groups

Conversation

@mickqian

@mickqian mickqian commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Adjacent conditioning stages such as text encoding, image encoding, and image-VAE encoding can be independent, but pipelines currently execute every stage serially. This PR adds an explicit declaration mechanism and safely overlaps eligible stages.

Implementation

  • ComposedPipelineBase.add_parallel_stages() declares one dependency-free execution level.
  • ParallelExecutor runs eligible replicated stages on the caller stream plus reused side CUDA streams. Every member must opt into concurrency_safe and return the same request object.
  • PipelineStage.may_use_collectives independently declares cross-rank communication. Multiple collective members are placed in declaration-ordered epochs; non-collective siblings can overlap the first epoch without risking rank-dependent NCCL ordering.
  • ImageVAEEncodingStage reads an explicit VAE capability. Wan VAE reports an encode collective only when spatial-parallel encode is active.
  • The residency manager permits a parallel group only when all referenced components are resident. CPU/layerwise offload, non-CUDA execution, unsupported stage paradigms, and --parallel-stage-execution serial retain serial execution.
  • serial is the default. auto is explicit because overlap can increase the temporary activation/workspace peak.

Adoption

Wan I2V and I2V-DMD, Flux2, Qwen Image Edit, Joy Image Edit, MOVA, LongLive2, and the independent LingBot realtime conditioning branches declare applicable parallel groups.

Validation

  • Unit coverage includes execution-level derivation, overlap, ordered collective epochs, payload identity, offload downgrades, grad-mode inheritance, residency contracts, and Wan VAE's SP encode capability.
  • Prior H200 E2E measurements: Flux2 Klein Base I2I at 512x512 improved by 6.77% at one step on one GPU, 2.45% at four steps on one GPU, and 6.33% at four steps with TP2; the TP2 output was byte-identical. The same model at 50 steps improved 0.45% while increasing per-rank peak memory by about 1.65 GB. LongLive2 I2V at 832x480x61 and four steps showed no material gain (0.01%).

CI States

Latest PR Test (Base): ✅ Run #32321535556
Latest PR Test (Extra): ✅ Run #32321535429
Latest PR Test (AMD ROCm 7.2): ❌ Run #32321535580

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions github-actions Bot added the diffusion SGLang Diffusion label Jul 31, 2026
@mickqian
mickqian force-pushed the feat/parallel-stage-groups branch from b9f7f23 to 173ac2d Compare July 31, 2026 09:04
@mickqian

Copy link
Copy Markdown
Collaborator Author

Update: added a hard safety gate — overlap now additionally requires every group member to declare concurrency_safe = True (stage issues no cross-rank communication), default False. Motivation: on an internal 8-GPU pipeline, overlapping two cross-rank-communicating stages produced a gloo collective mismatch (concurrent members interleave collectives in a different order on each rank). The docstring contract is now enforced by the executor; unit contract added (test_communicating_member_downgrades_to_serial).

@mickqian
mickqian force-pushed the feat/parallel-stage-groups branch from 173ac2d to b710d6d Compare July 31, 2026 09:47
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 31, 2026
@mickqian
mickqian force-pushed the feat/parallel-stage-groups branch 2 times, most recently from c051849 to f301205 Compare July 31, 2026 10:03
@mickqian
mickqian marked this pull request as ready for review July 31, 2026 10:07
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@mickqian
mickqian force-pushed the feat/parallel-stage-groups branch 2 times, most recently from 5e7d18a to 50d5a32 Compare July 31, 2026 11:00
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci extra

@github-actions github-actions Bot added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jul 31, 2026
@mickqian

Copy link
Copy Markdown
Collaborator Author

CI triage for the red checks — none are caused by this PR:

multimodal-gen-test-2-npu-a3 (wan2_2_t2v_14b_w8a8_2npu consistency): deterministic failure (bit-identical metrics across two runs: min SSIM 0.7277, min PSNR 21.45, CLIP 0.99). Root cause is #32697, which switched the Wan pipelines' default vae_decode_precision to bf16 with no platform gating — the Ascend consistency reference for this case was generated before that change and has not been regenerated. Evidence: the last green run of this job (#32784's CI, Jul 29 13:25 UTC) predates #32697's merge; this branch is based on post-#32697 main; the executor change here is provably inert for the T2V path (verbatim paradigm-dispatch extraction, feature is opt-in per pipeline and only Wan I2V opts in). Any diffusion PR based on main after Jul 29 that runs the NPU suite should reproduce this. Fix options: regenerate the NPU reference for this case, or pin vae_decode_precision in the testcase.

multimodal-gen-test-*-gpu-amd (flux2_modelopt_fp8_tp2_t2i): HIPBLAS_STATUS_NOT_SUPPORTED from the fp8 GEMM path on MI300 — unrelated to this PR (no GEMM/quantization surface touched); will re-enqueue once the run completes.

@mickqian

Copy link
Copy Markdown
Collaborator Author

Re-run outcome: zimage_sp2 (server timeout) and the 1-GPU AMD partition cleared on re-enqueue — flaky as suspected. The two remaining reds are deterministic pre-existing platform issues per the triage above: flux2_modelopt_fp8_tp2_t2i (HIPBLAS_STATUS_NOT_SUPPORTED on MI300) and the Ascend wan2_2_t2v_14b_w8a8_2npu consistency reference staleness from #32697. 51 checks green otherwise.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 5, 2026
mickqian and others added 7 commits August 5, 2026 20:09
Pipelines execute strictly serially even when consecutive stages have
no data dependencies: an image-conditioned request pays text encoding
plus condition encoding back to back although neither reads the
other's output.

Let a pipeline declare mutually independent stages with
add_parallel_stages. The stage list stays flat, so residency
bookkeeping, disaggregation role filtering, and profiling see the
same order; members share an execution-group token and the production
ParallelExecutor derives sequential levels from consecutive tokens. A
multi-member level of replicated stages runs member 0 on the calling
thread and the rest on pooled threads pinned to reused side CUDA
streams that wait on the current stream before starting and are
waited on after joining, preserving every ordering the serial
schedule provided; every other level keeps the exact per-paradigm
rank behavior. SyncExecutor stays a plain serial executor.

Contract for group members: mutate disjoint request state, return the
payload received, and keep collective communication to at most one
member per process-group family. Residency active-use bookkeeping is
serialized under a manager lock; levels fall back to declaration
order whenever component offload is enabled or grouped-batch
execution chains new batch lists.

Co-Authored-By: Claude Fable 5 <[email protected]>
TextEncodingStage and ImageEncodingStage report concurrency_safe
dynamically: False whenever encoder folding or encoder dp is active
(both involve cross-rank collectives), or when the image stage shares
a VLM text encoder with the text stage (conflicting prompt_embeds
writes). This keeps declared-parallel groups conservative by default
while allowing single-rank replicated encoders to overlap.

Co-Authored-By: Claude Fable 5 <[email protected]>
Adopt declared-parallel stage groups in the Wan I2V pipeline: text
encoding, CLIP image encoding, and image VAE encoding form one
execution level (opt-in via add_standard_ti2v_stages(
overlap_condition_encoders=True), requires the before_timestep VAE
position).

Validated on a single B200 (Wan2.1-I2V-14B-480P, 480x832x33f, 20
steps, performance-mode speed, two sequential requests per process):

- request 1 correctly downgrades to serial while the DiT sits in the
  compile-scoped layerwise-offload window; request 2 overlaps
  (engagement log observed) and completes with stable memory
  (members enter at 58.4GB allocated, exit at 58.7GB).
- warm-request level time equals the slowest member (~0.44s VAE
  encode) instead of the serial sum (~0.45s); the win grows when the
  branches are balanced (cold text encoding: 0.56s text + 0.45s VAE
  serial vs ~0.6s overlapped) or on hardware where encoders are
  proportionally slower.

Co-Authored-By: Claude Fable 5 <[email protected]>
# Conflicts:
#	docs/docs/sglang-diffusion/api/cli.mdx
#	python/sglang/multimodal_gen/runtime/managers/memory_managers/component_manager.py
#	python/sglang/multimodal_gen/runtime/pipelines_core/executors/pipeline_executor.py
#	python/sglang/multimodal_gen/runtime/pipelines_core/stages/text_encoding.py
#	python/sglang/multimodal_gen/runtime/server_args/server_args.py
@mickqian
mickqian marked this pull request as draft August 20, 2026 01:51
detain added a commit to detain/sglang that referenced this pull request Oct 8, 2026
… of sgl-project#33036)

Squash of 14 commits 5d2f658..12e5682 (net diff from PR base
1270204 applied with git apply -3). Adds --parallel-stage-execution
{auto|serial} (default serial): parallel_executor builds groups from
stages declaring concurrency safety and overlaps independent CUDA
conditioning stages (Wan I2V text+image encoders first), with explicit
collective sequencing for distributed, residency-manager coordination in
component_manager, and stage-contract markers in stages/base.py,
text_encoding.py, image_encoding.py + per-pipeline declarations.

Conflict resolutions:
- component_manager.py imports: union (theirs threading + ours Iterable).
- cli.mdx: kept our fuller cfg-parallel/encoder-parallel bullets, appended
  theirs' new --parallel-stage-execution bullet.
- composed_pipeline_base.py (which carries our sgl-project#32550 DAG hooks) and
  parallel_executor.py auto-merged cleanly; re-verified by tests.

Tests: test_parallel_stage_groups.py + test_server_args.py 221 passed;
unit -k "pipeline or executor or component or residency or stage"
651 passed.

This branch has not been deployed

No deployments
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 run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant