Repository navigation
fix: demote resident params to disk residency when memory reclamation fails - #2119
Merged
Merged
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.
Summary
When
ModelManager::ensure_compute_backend_capacityexhausts its normal tiers (other runners' workspace, preferred eviction order, global LRU eviction), states resident on the compute device (params_backend == compute_backend) remain unevictable because they have no reloadable backing copy. This adds a final tier: demote eligible resident states toResidencyMode::Diskin LRU order, which only unlocks evictability —release_params_storage_blocksstill decides what is actually freed, and the unchanged disk-resident load path reloads them on next use.Demotion is skipped for protected, pinned, staged, unloaded, required, view, split-buffer, LoRA-fused, and non-file-backed states, and it never runs when capacity already fits. States that end up not being released get their residency reverted, so permanent disk residency applies only to tensors that actually entered the disk lifecycle — afterwards they behave identically to native
--params-backend ...=diskparams.Fixes #2118. On a 12 GB card the Qwen Image 2.1 Q6_K DiT (5.6 GB) previously stayed GPU-resident while the Wan-family VAE needed a 7.8 GB decode workspace, forcing 49 tiles at 256px (15.9 s) instead of a full-frame decode (4.4 s).
Test evidence (RTX 5070 Ti Laptop 12 GB, CUDA, master
f89d9b1)Reload path verified with
sd-server: after the first request evicts the demoted DiT, the second request reloads it from disk in ~2.3 s and samples normally; subsequent decodes evict only as much as needed (LRU, block-granular).Notes for reviewers
assign_compute_backend(this already applies to--params-backend disktoday).Summary by CodeRabbit