Fix Diffusers CPU offload lifecycle - #14
Open
iamwavecut wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #6 on the current upstream base. The old PR became conflicted after
316da877309523b9a2d335550aedbd0269ef0b6c(feat(inference): improve distributed inference and memory efficiency).Summary
--cpu_offload {none,model,sequential}for single-process Diffusers inference;text_encoder->transformer->vae;Upstream conflict resolution
The new upstream commit adds FSDP placement, base/refiner auxiliary-component sharing, VAE tiling, base-pipeline release, and an optional manual VAE move during refiner denoising. It does not add Diffusers/Accelerate model or sequential CPU offload, hook-aware VAE execution, or the Qwen sequential-offload preload.
This replay preserves the new upstream behavior and adapts CPU offload to it:
text_encoderand VAE sharing remains enabled normally, but is disabled for CPU offload because one module cannot safely belong to two independent Accelerate hook chains;--release_base_before_refinerremoves Accelerate hooks before dropping pipeline components, so hook-owned references do not retain the released models;Root causes
meta; their current parameter device is not the VAE execution device.Qwen3VLVisionModelreadspos_embed.weight.devicebefore invoking the childEmbedding. Sequential offload therefore needs Accelerate'spreload_module_classespath for that visual parent instead of excluding the full text encoder from offload.Post-rebase validation
The replacement commit is based directly on upstream
316da877309523b9a2d335550aedbd0269ef0b6c. Local checks used Python 3.12.9, Diffusers 0.37.1, Accelerate 1.14.0, Torch 2.13.0, and Transformers 5.14.1:No GPU measurements were rerun solely for this conflict resolution. The following GPU evidence belongs to the original implementation commit
a999b14d135c23d031ea7fe783225c26be1446c8; the lifecycle logic is retained here, while the new upstream compatibility paths are covered by the tests above.Existing GPU validation
Validated on one RTX PRO 4000 Blackwell 24 GB pod, PyTorch 2.8.0/CUDA 12.8, Diffusers 0.39.0, Accelerate 1.14.0, and
robbyant/lingbot-video-dense-1.3b. All runs used the same prompts, seeds, dimensions, steps, dtypes, and Torch SDPA backend; only offload mode changed.TI2V, 320x192, 49 frames, 40 steps:
Decoded RGB output from both offload modes is identical to
none: 49 frames, 9,031,680 values compared, maximum absolute difference0.Synthetic dense-refiner smoke, 320x192, 49 frames, 4+4 steps:
Base and refined decoded RGB outputs are identical between model and sequential offload. They are also identical to the pre-fix model-offload baseline, showing that the lifecycle fix does not change generated pixels.
The synthetic refiner
nonecontrol does not fit this 24 GB GPU because it preloads two complete dense pipelines; it reaches 23.41/23.42 GiB before generation. This is a fixture capacity limit, not an offload failure.