Repository navigation
[Experimental][Diffusion] Add stage-local Wan TeaCache with pipeline parallelism - #8731
fusheng-ji wants to merge 46 commits into
Conversation
… CFG helper TeaCache keeps one cache state per CFG branch and decides which branch a transformer call belongs to from transformer.do_true_cfg. Only Flux, Flux Kontext and Qwen-Image set that flag; every other pipeline that runs sequential CFG through CFGParallelMixin.predict_noise_maybe_with_cfg left it unset. For TeaCache-enabled models among them (Flux2Klein, Flux2 with a negative prompt, LongCat-Image) the positive and negative calls of a step therefore shared one state. Both calls see the same latents and timestep, so the second call's modulated input matched the first exactly and it could reuse the other branch's residual, collapsing the guidance. Set transformer.do_true_cfg in predict_noise_maybe_with_cfg, where the branch layout is known, so every pipeline using the helper gets per-branch TeaCache states. The flag is reset for calls without CFG. Pipelines without a `transformer` attribute are untouched, and multi-branch CFG uses a separate method. TeaCache is the only reader of the flag. On FLUX.2-klein-base-4B (50 steps, guidance 4.0, rel_l1_thresh 0.2, 1024^2) mean SSIM against the uncached image goes from 0.59 to 0.90 at a similar speed-up; uncached output is byte-identical. Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
… CFG helper TeaCache keeps one cache state per CFG branch and decides which branch a transformer call belongs to from transformer.do_true_cfg. Only Flux, Flux Kontext and Qwen-Image set that flag; every other pipeline that runs sequential CFG through CFGParallelMixin.predict_noise_maybe_with_cfg left it unset. For TeaCache-enabled models among them (Flux2Klein, Flux2 with a negative prompt, LongCat-Image) the positive and negative calls of a step therefore shared one state. Both calls see the same latents and timestep, so the second call's modulated input matched the first exactly and it could reuse the other branch's residual, collapsing the guidance. Set transformer.do_true_cfg in predict_noise_maybe_with_cfg, where the branch layout is known, so every pipeline using the helper gets per-branch TeaCache states. The flag is reset for calls without CFG. Pipelines without a `transformer` attribute are untouched, and multi-branch CFG uses a separate method. TeaCache is the only reader of the flag. On FLUX.2-klein-base-4B (50 steps, guidance 4.0, rel_l1_thresh 0.2, 1024^2) mean SSIM against the uncached image goes from 0.59 to 0.90 at a similar speed-up; uncached output is byte-identical. Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
…rring it from parity TeaCacheHook chose the per-branch cache state for sequential CFG from _forward_cnt % 2. Request mode refreshes the hook before every request, so the parity always restarted at zero. Step execution never refreshes it, though: a CFG wave followed by a non-CFG wave with an odd number of forwards flipped the parity, and the next CFG step's positive call landed in the negative state, continuing from the other branch's residual (issue vllm-project#8482). CFGParallelMixin now stamps transformer.cfg_branch ("positive" / "negative") around each predict_noise call on all three paths (sequential CFG, CFG-parallel ranks, no CFG) and restores the previous value afterwards, also when predict_noise raises. TeaCacheHook prefers explicit sources and keeps the old rank/parity inference only for callers that provide none. A missing negative kwargs dict with do_true_cfg=True now raises a ValueError naming the branch. In request mode the stamp equals the old parity, so behaviour is unchanged there. Request boundaries under step execution (the second half of the issue) are not addressed here. This composes with the per-call extractor hint added for MammothModa2 (ctx.extra_states["teacache_branch"], PR 5357): the extractor hint wins, then the mixin stamp, then inference. Both explicit sources go through the same validation, keeping that PR's error message for invalid hints. Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
…it-cfg-branch Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
…anch-state Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Centralize transformer.do_true_cfg on CFGParallelMixin (including PP>1), drop redundant Flux/Qwen writes, tighten tests, and revert unrelated SPDX churn. Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
…iles Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
This PR appears to belong to: docs/design/module/diffusion/index.md, docs/design/module/diffusion/parallelism.md. Module owners: @princepride @wtomin @david6666666 Routing: @princepride via module of the changed files, module named in the PR description, CODEOWNERS; @wtomin via module of the changed files, module named in the PR description, CODEOWNERS; @david6666666 via module of the changed files, module named in the PR description @fusheng-ji, please review your own changes and leave a short self-review comment describing what you checked. PRs without author self-review may not be assigned a reviewer. Please take a look when you have a chance. If you would like an automated review, mention @vllm-omni-review-bot in a comment. |
Omni ReviewBot triage noteAutomated triage of commit
These are automated triage suggestions only — the final decision belongs to the maintainers. |
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
# Conflicts: # vllm_omni/diffusion/cache/teacache/hook.py Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
# Conflicts: # vllm_omni/diffusion/distributed/pipeline_parallel.py Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
Signed-off-by: Wenbo Ji <36562829+fusheng-ji@users.noreply.github.com>
|
Hi guys. Could you help review the experimental Wan TeaCache implementation at 7b1bbc4?
|
|
@fusheng-ji You forgot sign-off😂 |
a1957f7 to
d4f9a34
Compare
Hi, thanks for reminding me. I have fixed the sign-off issue; now it should be ready for review. |
Omni ReviewBot: no human activity for 7 days@fusheng-ji this pull request has had no human commit, comment or review since 2026-10-29. Please confirm the current plan and next step. The author or a maintainer decides whether to change the PR state. To keep it moving, any one of these is enough: push an update, reply to the open blocker, or post the current plan and timeline. |
Purpose and status
Add experimental stage-local TeaCache integration for real pretrained Wan2.1-T2V-1.3B, including PP=2 and CFG=2. Production acceptance has failed so far; keep this PR in draft. No qualified default cache profile is enabled. This branch includes dependencies #8475 and #8483.
Native forward and the TeaCache extractor share input preparation, local block execution, and output projection. Each PP stage caches only its own block residual; cache hits retain the required PP input/output handling and final projection. PP prediction uses #8483's explicit CFG branch helper. Branch state resets between requests, and no cache-decision collective is added between sequential PP stages.
The supported experimental scope is BF16, single-expert T2V 1.3B, PP/CFG sizes 1 or 2, TP=SP=1, without quantization. Unsupported variants are rejected; explicit coefficients are required through the existing cache configuration. The branch also fixes a pre-existing PP VAE non-owner
(None,)output crash, reproduced on the #8475 baseline with CPU and pretrained GPU runs.Current-head update (
b47ded2b9)Stage-specific coefficients, negative-prediction clamping, calibrated-input-range guards and warmup policy now run in the production TeaCache hook through optional
cache_config.wan_profile. Profiles validate the pinned Wan revision, BF16, PP/CFG topology and stage. The validation harness no longer replaces cache decisions; forced full compute remains test-only. Formal paired timing uses a separate minimal-observation run of the same profile, and independent acceptance is blocked unless calibration passes every unchanged gate. Calibration includes the historical 30-step warmup strategy, with a newly frozen independent acceptance prompt set.b47ded2b94f7a4f7e0b80216ccf12844c0ffd2ff: focused profile/config/guard/acceptance-gate CPU suite 25 passed, 0 failed, 0 errors, 0 skipped (4 GPU cases deselected).mypy-3.10skipped as in CI. Two validation JSON EOF violations were fixed. All commits on the branch now carry aSigned-off-bytrailer (history rewritten with identical tree), and the DCO check passes.f4eda6347208 passed / 8 failed / 17 errors. Failure identities and error messages match (CPU/CUDA dependencies and missingcpu_linear). The candidate worktree was edited during that run, so it is not exact-current-SHA acceptance evidence; the 25-case suite above was rerun on an immutable current-SHA checkout.1105534–1105542are pending: hook/full-model equivalence, four topology calibration campaigns, then four conditional acceptance campaigns. All four calibration jobs must succeed before independent acceptance starts. Queueing, dependency waits and timeouts do not count as passes.Historical evidence (not current-head GPU validation)
Protocol and reproduction · Results, profiles, JUnit and compressed logs/rank traces
7e88fc3e: four B200, PP2/CFG2, 4 passed / 0 failed / 0 skipped, including numerical prediction/scheduler alignment and CFG on → off → on flags on all four ranks. Results on #8475.ef6379755f1f12a64a41336efa70b62e43b933f6. Subsequent coefficient-collection changes and the main-branch merge have not been validated by these GPU runs; results must not be attributed to the current PR head.Required: mean SSIM ≥0.95, worst video SSIM ≥0.90, temporal error ≤0.10, latency ratio ≤0.90. Each completed PP1 run has 110 real local-block-stack cache hits per CFG branch, finite paired latents, distinct branch states and request resets. Scheduling and failed startup attempts are not counted as passing tests.
For the historical runs below the earlier implementation boundary, the evaluation harness added stage-specific polynomial selection, negative-prediction clamping and an observed-input-range guard. These are not production defaults, so its results alone cannot qualify the production backend. Performance includes rank-trace overhead, excludes loading/warmup, and alternates native/cached requests in one loaded engine. Exact temporal-error definition, per-video latent errors and all failed gates are retained in the report.
Ruff passes. Targeted mypy retains 12 pre-existing PP mixin errors (14 on the merged dependency baseline); it is not reported as a clean type-check run. Intermittent multiprocessing SemLock startup failures occurred on both baseline and feature attempts and are retained in the logs.
AI assistance: Codex implemented this draft and executed the validation. This remains an experimental draft, not a production-ready claim.
Historical evaluation update (2026-10-12; frozen source stated above): all four topologies completed, 144 paired requests / 288 videos. All four pass both SSIM gates and fail temporal-error and latency gates (8 measured gate passes, 8 failures, 0 skips). Each PP2 run has stage-0 positive/negative hits of 168/168 and stage-1 hits of 281/279, finite paired latents, distinct branch states and a passing request-reset audit. These are real local block-stack cache hits.
PP2/CFG1 retry 1096862 completed in 8m41s with the same frozen source, model, profile and dependency environment. Original job 1096100 timed out without complete video pairs and reported a ShmRingBuffer shared_memory AttributeError; root cause remains unresolved. Shutdown resource-tracker warnings remain in successful logs. Final raw PP2 reports, JUnit, videos and traces are retained in the shared
wan-teacache-validation/validation-1096101andvalidation-1096862directories. The source-tree evidence summary is updated; generated artifacts remain outside the current source tree, following the existing archive convention. This PR stays a draft with production defaults disabled.