Repository navigation
Vulkan: keep CPU-offloaded weights in pageable RAM (upstream #2450) - #106
Merged
Merged
Conversation
Cherry-picked from upstream leejet/stable-diffusion.cpp PR leejet#2450 (MIT). Only the Vulkan guard is taken; the fork's params_buffer_type_for condition is otherwise unchanged. (cherry picked from commit 58d1126)
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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 Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Vulkan: keep CPU-offloaded weights in pageable RAM (upstream leejet#2450)
Cherry-pick of upstream leejet/stable-diffusion.cpp PR leejet#2450 (merged as 58d1126, MIT) onto master.
Problem
With
--offload-to-cpu,ModelManager::params_buffer_type_forplaces the CPU-side copy of every offloaded weight inggml_backend_dev_host_buffer_type(compute_dev). On Vulkan that buffer type is a driver allocation. On AMD radv it is GTT, which the kernel caps with TTMpages_limit, so the CPU copies of the weights compete with the GPU replicas for the same pool. A MiniMax-H3 Q4_K render at 864x480x124 pins about 31 GiB of GTT this way (about 15.5 GiB with the text encoder on the CPU). When the pool runs out, the run ends indevice losteven though the device copies have already been evicted.Change
src/model_manager.cpp,params_buffer_type_for: do not use the device host buffer type when the compute backend is Vulkan. The offloaded weights then use the default CPU buffer type, which is ordinary pageable memory. CUDA, ROCm and the other backends are unchanged.Only the Vulkan guard is taken from upstream. The surrounding condition on master is older than the upstream one (it lacks the
sd_backend_is_cpu(state.params_backend)clause from a different upstream change), and that part is left alone so this PR stays a single behaviour change. The docs line from upstream is added todocs/performance.md.Validation
gfx1151 (Radeon 8060S, Linux, Vulkan/radv). Both sd-cli builds come from one source tree with the same toolchain and flags. The H3 run is
--mode vid_genwith MiniMax-H3fl2va_pruned-Q4_Kand theQ4_K_Mencoder at 864x480, 124 frames, 8 steps, seed 1, using the same Auto flags the app uses (--offload-to-cpu --diffusion-fa --max-vram -1), and writes a raw AVI so the frames can be hashed. Runs alternate between the two builds, two each.Baseline GTT before each run was 0.02 GiB. Peak GTT drops by 25.07 GiB (median of peaks), and the weights move into ordinary process memory (RSS rises by about 31 GiB). Sampling speed is unchanged: s/it after/before is 0.997, and the spread between repeats of the same build is 0.35% (before) and 0.17% (after). The decoded frames are bit-identical.
Follow-up
After a prebuilt that carries this change is pinned, the app's MiniMax-H3 memory fit can stop charging the offloaded weights against free GTT for Vulkan on that tag. Until then the existing charge stays, because older binaries still pin GTT.