Skip to content

[diffusion] Plan reversible residency before warmup - #36703

Open
mickqian wants to merge 127 commits into
mick/diffusion-auto-residencyfrom
codex/diffusion-preload-residency-planner
Open

mickqian wants to merge 127 commits into
mick/diffusion-auto-residencyfrom
codex/diffusion-preload-residency-planner

Conversation

@mickqian

@mickqian mickqian commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • inventory the selected checkpoint components before loading and seed a conservative resident set that the post-load planner can fully replace
  • plan complete resident, component-offload, and partial layerwise target states across DiTs, encoders, VAEs, lazy components, and two-stage pipelines, including independent resident counts and implicit policies per repeated layer group
  • use temporary manager-level warmup counters and denoising-stage attribution so repeated layer groups, including non-standard component keys, receive independent residency choices while one-shot or unused groups do not consume stage-resident VRAM
  • use one exact selection vector for every rank/phase VRAM constraint, placement-transition scratch, replica-pooled HostPin allowance, and host repacking headroom; assign per-rank pin quotas only after the joint solve
  • account the full persistent host-store footprint when an ordinary resident component first becomes layerwise; reuse existing CPU weights and charge only incremental repacking scratch from component offload
  • charge complete apply-time device deltas for coarse/layerwise transitions, and model prefetch with the same weight footprint as active use for all current strategies
  • run the same startup sequence for server and offline entrypoints: static placement, one representative warmup, and at most one measured adjustment; resident-only verification is one full-shape step
  • preserve the current HostPin layout during static weight-only planning and construct the complete pin frontier only after the representative warmup can score it
  • keep loader-required placement fixed for LTX2.3 original mode, retain allocator reserve after the realized placement runs, and let numerically non-invariant pipelines decline automatic residency changes

Design boundary

The preload decision is a replaceable load-feasibility seed, not an independent serving optimizer. Its load VRAM budget is a separate lifecycle feasibility constraint; it is never composed after the fact as an independently optimal serving decision. The serving solve uses one selection vector for every runtime phase VRAM, placement transition, and node HostPin constraint. Once modules have exact sizes, static planning may demote or replace every seeded component before the first forward; warmup then validates and refines the complete serving frontier with measured workload phases and latency utility.

Structural loading choices such as explicit FSDP remain outside this planner because changing them after calibration requires reloading weights. Explicit/online quantization and direct GPU loading likewise fix only their affected components; unrelated components in the same pipeline remain eligible for measured placement. The exactness guarantee is therefore relative to the supplied replaceable placement frontier, resource estimates, and target workload, rather than a claim about startup-plus-serving lifecycle cost.

Within one request replica, multi-process HostPin is pooled into the same placement solve, so TP/SP/PP/CFG ranks may receive asymmetric quotas while their sum remains bounded. Different DP replicas retain disjoint local-worker shares rather than coordinating one cross-replica solve; homogeneous startup remains symmetric, while heterogeneous DP workloads are outside the exactness claim. Quotas are applied transactionally and rollback restores the prior allocation.

Validation

B200: Wan2.2 A14B NVFP4, 640x384x17, 12 steps

The load-safe seed selected both DiTs resident. The text encoder and VAE retained their native layerwise loading semantics; the 4-step full-shape probe then selected both resident. This preserves checkpoint/model initialization behavior while moving serving placement out of model-specific thresholds. The post-adjustment pass validates the complete serving shape; resident-only changes use one denoise step because they remove hooks/transfers without changing the compute path.

metric old-head CI result
startup to ready 80.4 s
E2E 2740.56 ms
average denoise 209.78 ms
load / runtime peak 25182 / 52378 MiB
consistency passed

Conservative preload boundary

A 29.7 GiB Wan2.1 1.3B experiment showed why checkpoint bytes alone cannot promote auxiliary modules safely: a weight-only plan exhausted activation headroom near 29.1 GiB and then paid for layerwise recovery. LTX2.3 showed the same issue on a larger request. The production preload seed therefore covers native DiTs only; encoders and VAEs retain their configured loading path until the bounded full-shape probe supplies activation evidence.

The old-head NVIDIA run passed unit, BCG, component-accuracy, B200, RTX 5090, four of five H100 1-GPU partitions, and one completed H100 2-GPU partition before the three known long-running partitions were cancelled to avoid seven retries against stale VRAM guards. The current-head run validates workload-faithful CI sampling, resident-only one-step validation, and explicit before/after calibration timing.

Focused tests cover initial placement, the exact joint solver, per-rank checkpoint loading, HostPin accounting, layerwise transitions, and warmup/rollback orchestration. Changed-file and merge-conflict pre-commit passed on 93f1464c2af64. The current head preserves node-pooled HostPin and per-group policy choices, avoids speculative pin-frontier construction before calibration, and collapses a measured pin frontier only when every rank-local share and the exact per-component latency cap prove it non-binding.

Completed H100 evidence from parent run 33183409022 additionally showed why both planner layers are needed: LTX2.3 HQ selected a live-allocation-feasible layout whose mapped allocator pool left no request reserve, while SANA-WM changed numerics after runtime promotion. The stack now combines the child branch allocation-gap correction during candidate planning with the parent post-placement peak-reserved guard, fixes both LTX DiTs in original mode, and keeps SANA-WM on its proven static placement. No additional warmup or retry round was added.

Stack

Depends on #35335.


CI States

Latest PR Test (Base): ❌ Run #34829333187
Latest PR Test (Extra): ❌ Run #34829333044
Latest PR Test (AMD ROCm 10): ❌ Run #34829333150

Baseline note (2026-09-05)

  • 5090.json turbo_wan2_1_t2v_1.3b load peak 928 → 3810 MiB: the load-safe seed keeps the 1.3B DiT resident from load on a 32 GiB card (same effect already recorded for flux_2_klein_base_image_t2i and zimage_image_t2i).

Inventory selected component weights before loading and use them to seed a conservative resident set. The seed changes only ordinary component residency, so post-load planning can replace it before the first serving forward.

Run the same exact multi-resource placement solver after components are sized and again after one representative warmup. Each target state jointly obeys per-rank execution-phase VRAM, placement-transition scratch, per-worker HostPin, and host repacking headroom. The complete target frontier includes resident, component offload, and partial layerwise placements for DiTs, encoders, VAEs, lazy components, and two-stage pipelines.

Keep structural loading decisions such as explicit FSDP outside the reversible planner, cap normal calibration at one adjustment and one verification warmup, and retain bounded OOM recovery. Extend offline startup to use the same sequence and add exhaustive solver, lifecycle, rollback, multi-rank, custom-pipeline, and server-args coverage.
@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 Aug 27, 2026
@github-actions github-actions Bot added quant LLM Quantization blackwell SM100/SM120 labels Aug 27, 2026
mickqian and others added 16 commits September 5, 2026 20:58
The load-safe seed keeps the 1.3B DiT resident from load on a 32 GiB card,
so the load peak moves from 928 MiB to 3810 MiB (measured on the 5090 canary).
# Conflicts:
#	python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py
# Conflicts:
#	python/sglang/multimodal_gen/test/unit/test_auto_residency.py
#	python/sglang/multimodal_gen/test/unit/test_auto_residency_warmup.py
#	python/sglang/multimodal_gen/test/unit/test_component_residency.py
#	python/sglang/multimodal_gen/test/unit/test_placement_budget.py
# Conflicts:
#	python/sglang/multimodal_gen/runtime/server_args/auto_tune.py
The pre-load planner only promotes DiTs, so starting from main's memory
thresholds loses nothing and avoids serving below them when a promotion
is declined (see the apply layer's fix for the measured regressions).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…safe start

The 21 'defers residency' variants asserted that auto mode starts every
component offloaded so the static planner can place it later. Placement
now starts from the memory thresholds main applies and the planner only
promotes, so the apply layer's threshold tests are the right expectations
again; the FSDP-versus-planner test stays u1's own.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
# Conflicts:
#	python/sglang/multimodal_gen/test/server/perf_baselines/5090.json
#	python/sglang/multimodal_gen/test/server/perf_baselines/h100.json
The seed keeps native DiTs resident from load, so the load peaks of the
Wan2.2 A14B 2-GPU cases and the 5090 Wan/Turbo-Wan/FLUX.2-klein cases
rise accordingly (run 34131148154 at a330811); runtime peaks follow the
apply layer's refresh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

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

amd apple-silicon blackwell SM100/SM120 deepseek dependencies Pull requests that update a dependency file deterministic Issues on deterministic inference/kernels diffusion SGLang Diffusion documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel lora memory-pool model-gateway mthreads Multi-modal multi-modal language model npu piecewise-cuda-graph quant LLM Quantization run-ci CI: run the baseline test suite on this PR sgl-kernel speculative-decoding unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants