Repository navigation
[diffusion] Skip warmup preferred preload when it would OOM - #40761
Conversation
|
/tag-and-rerun-ci |
|
@cipheraxat Thanks for working on this. From reading the patch, I think it addresses the immediate failure reported in #40562: a preferred warmup preload is now skipped when its weights do not fit, and a partial move is rolled back if the copy still OOMs. I still have two concerns before considering the original problem fully resolved. 1. The preferred preload policy is still not user-configurableThe patch deliberately keeps the existing The budget check also uses a fixed Would it be possible to expose a user-facing policy that can:
For example, 2. The unused
|
|
@yummyaa Thanks for the detailed review, agreed on both points. Point 2 (unused
The new tests follow the real call order ( Point 1 (user-configurable preload policy / headroom): tracked as a follow-up in #41126, since it adds a new server arg. Does that split work for you? |
|
@cipheraxat Thanks for the quick and thoughtful follow-up. Yes, this split works well for me. The updated handling for the unused Tracking the user-configurable preferred preload policy and memory headroom separately in #41126 also makes sense, since that introduces new user-facing configuration rather than only fixing the current failure path. I really appreciate how thoroughly you addressed both concerns and incorporated the feedback. I will continue following both the PR and the follow-up issue and report any additional findings. |
|
/tag-and-rerun-ci |
Warmup finalization may optionally reload preferred components; if they cannot fit, leave them offloaded and recover instead of crashing startup. Fixes sgl-project#40562.
Drop dtype scaling and storage dedup. The reported Wan path does not cast on preload, and a plain CPU byte sum is enough to skip a copy that cannot fit.
VAE release at request end is not memory_intensive, so reserved allocator blocks can still look used to mem_get_info. Free them before deciding whether the optional preferred preload fits.
Stage exit was advancing into later co-declared experts (e.g. transformer_2 during Wan2.2 synthetic warmup) via finish_active_use's prefetch. Skip the remaining same-stage uses and release any prefetched-but-never-begun copies.
… use DenoisingStage calls finish_active_use() inside the stage, so the earlier end_stage-only fix never ran on the Wan2.2 warmup path and transformer_2 was still prefetched. Prefetch from the next stage when finishing an active use, and release unconsumed same-stage prefetches at end_stage even when no use is active.
Fold the budget-skip and OOM paths into one fallback, filter same-stage prefetch by stage name instead of index math, and consolidate the tests. No behavior change.
Some backends expose mem_get_info without implementing it; catch RuntimeError so the warmup budget check falls back to attempting the optional preload.
module.to(device, dtype=...) widens floating-point weights during the H2D, so counting host nbytes alone underestimates the copy when target_dtype is wider than the stored dtype.
3a3fb15 to
a3d95da
Compare
Motivation
With
dit/text_encoder/vaecomponent-offload, synthetic warmup finalizationcan OOM while reloading preferred components via
prepare_for_use→module.to(device), then leave the allocator full so smallerwarmup retries also fail.
ComponentOffloadStrategy.finish_request(..., preferred=True)always tried to keeppreferred components resident after a warmup request. After VAE release, that
optional H2D can still exceed free device memory:
memory_intensivereleases leave reserved allocator blocks thatmem_get_infostill reports as usedmodule.to(device)then fails with CUDA OOM (or partially moves tensors)Separately, Wan2.2 A14B synthetic warmup only runs the high-noise
transformer,but
DenoisingStage→finish_active_use(prefetch_next=True)still prefetched theco-declared low-noise
transformer_2(~26 GiB) and left it resident through VAEdecode.
Tracked in #40562.
Reproduced with:
Modifications
Warmup preferred path in
component_residency_strategies.py/ComponentOffloadStrategy.finish_request:or clearing the allocator cache. Otherwise, query free memory first; only
call
empty_cacheand recheck if the optional preload would not fit._cpu_module_nbytes),counting weights at
target_dtypesincemodule.tocasts them during thecopy. If that doesn't fit in free memory minus 1 GiB headroom, skip the copy
and leave the component offloaded; the next request loads it on demand.
torch.OutOfMemoryError/"out of memory",call
finish_use(moves any partial device tensors back to CPU), andempty_cacheso startup can continue.the device when a parent parameter remains on CPU after a failed copy.
unchanged.
Same-stage prefetch cleanup in
component_manager.py:finish_active_useprefetches starting at the next stage. Stages call itwhen they are done with their components (e.g.
DenoisingStageat the end ofthe loop), so a later same-stage declaration such as
transformer_2on awarmup that only ran the high-noise expert is never H2D'd.
end_stagereleases same-stage prefetches that were never begun (strategiesthat can prefetch while another use is active), including when no use is
active anymore. A component that is still the active use is left alone.
end_useprefetch is unchanged.Deliberately unchanged:
finish_use)preferred_ready_after_requestSHARED_POOL_NEXT_STAGE_HEADROOM_BYTES)begin_useboth transformers inside the stageTests
Validated on one NVIDIA H200, Python 3.12, PyTorch 2.13.0+cu130:
121 passed, including component and snapshot offload, budget skips, cache
reclamation, target-dtype sizing, non-OOM propagation, and same-stage prefetch
cleanup. CUDA recovery tests exercise real
Module.tocopies with an injectedmid-copy OOM, check all recovered weights and buffers, and run the next forward.
The expanded warmup tests against the earlier PR implementation (
1dde33a4)reported 10 failures and 11 passes, exposing unnecessary cache clears and the
parent-CPU/child-CUDA rollback gap. They all pass with the follow-up fix.
Full Wan2.2-T2V-A14B startup/inference on L20 and startup latency benchmarks
have not been rerun. The injected-OOM tests do not exhaust physical GPU memory.
Accuracy Tests
N/A: residency / memory-management only; no model output change when preload
succeeds. When preload is skipped or recovered, the next real request loads the
component on demand (same as a cold start for that component).
Speed Tests and Profiling
N/A for correctness. Warmup may be slightly slower when preload is skipped
(on-demand H2D on the first real request). Successful preloads keep today's
behavior. Avoiding the unused
transformer_2prefetch reduces warmup devicetraffic on dual-DiT pipelines.
Checklist
CI States
Latest PR Test (Base): ✅ Run #37272621265
Latest PR Test (Extra): ❌ Run #37272621075
Latest PR Test (AMD ROCm 10): ❌ Run #37272621171