You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: count idle GPU buffers toward the max VRAM budget - #2446
Include ggml’s idle GPU buffer pool in the per-device --max-vram budget. Track cached bytes separately from device-reported free memory and trim the pool to make room for allocations.
Reuse compatible buffers for graph-cut outputs and weight prefetches. When trimming alone cannot admit a prefetch, check whether the weight buffer being evicted can serve the next upload before trimming the pool.
Update ggml to e9e6fe2c so adjacent scheduler plans can reuse same-size operator workspaces on the same backend. Update CLI help and memory documentation.
If this PR adds or changes model support, I have added or updated its usage guide and relevant model index/README entries following the model documentation requirements.
Summary by CodeRabbit
New Features
Backend memory buffers can now be reused during model loading and prefetching, helping reduce new memory allocations.
Memory checks better account for cached buffers and available device capacity.
Documentation
Clarified that --max-vram budgets include managed weights, compute and cache buffers, and idle backend buffers.
Added details on buffer reuse, memory limits, and factors that can affect total device VRAM usage.
No actionable comments were generated in the recent review.
Walkthrough
The change updates backend VRAM accounting to include idle cached buffers. It adds cache-backed tensor and prefetch allocation, changes capacity checks to use explicit modes, and retains pruned segment outputs for reuse. The CLI description and performance guides describe the updated budget and buffer-pool behavior.
Capacity checks use explicit modes and include idle cached buffers and reused allocations. Backend cache query, limit, and allocation wrappers are added. The CLI description and guides document the revised VRAM budget.
Pruning returns unused cached tensors. Output binding reuses compatible entries or attempts cache-backed allocation when an unused-output pool is provided.
Reuse buffers during weight prefetch src/segment_weight_pipeline.cpp, src/model_manager.*, src/device_residency_manager.h, src/core/execution_engine.cpp
Prefetch inspection can identify a single buffer for eligible CUDA or ROCm requests. The optional buffer is passed through capacity handling and staging preparation. A matching evicted staging allocation can be transferred to that buffer.
sequenceDiagram
participant ExecutionEngine
participant BackendBufferCache
participant ModelManager
participant SegmentWeightPipeline
ExecutionEngine->>BackendBufferCache: Try allocating the pending prefetch buffer
ExecutionEngine->>ModelManager: Inspect capacity and evict a compute-backend block
ModelManager->>ModelManager: Transfer a matching evicted allocation to the prefetch buffer
SegmentWeightPipeline->>ModelManager: Prepare prefetch parameters with the optional buffer
ModelManager->>ModelManager: Allocate staging tensors from the supplied buffer
leejet/stable-diffusion.cpp#2124 — Both changes alter how device free-memory reports and cached allocations factor into capacity checks.
Suggested reviewers:assouan
Merge Risk: Minimal · up to 9c1dd
This change counts idle GPU buffers toward the per-device VRAM budget and reuses buffers for graph outputs and weight prefetch. Review found no concrete defect, so the risk is low. A GPU run on the supported backends would still be a sensible final check.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix: count idle GPU buffers toward the max VRAM budget" matches the main change. The summary and objectives say idle ggml buffer pool contents are now included in the per-device --max-vram …
Description check
The description follows the template. It has a Summary section that describes the budget change, buffer reuse, the ggml update, and the CLI and documentation updates. It has a Related Issue / Discussi…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix: count idle GPU buffers toward the max VRAM budget" matches the main change. The summary and objectives say idle ggml buffer pool contents are now included in the per-device --max-vram budget, with trimming to make room for allocations. The title omits the buffer-reuse work and the ggml update, which is acceptable because it does not need to cover every detail. It is a single, specific sentence and avoids vague terms.
Full details: Description check
Explanation
The description follows the template. It has a Summary section that describes the budget change, buffer reuse, the ggml update, and the CLI and documentation updates. It has a Related Issue / Discussion section that says N/A. It has an Additional Information section that says N/A. The checklist is complete and both items are checked. The sections are present, but the Related Issue and Additional Information sections contain only placeholder text, and the Summary does not state why the change is needed beyond the mechanics. These gaps are non-critical, so the description is mostly complete.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4317d6f6-297c-43f3-b3f0-74a8ebb96ba1
Commits
Reviewing files that changed from the base of the PR and between 05adb5b and 9c1dd80.
Files selected for processing: 14
docs/guides/backend.md
docs/guides/performance.md
examples/common/common.cpp
ggml
src/core/execution_engine.cpp
src/core/ggml_extend_backend.cpp
src/core/ggml_extend_backend.h
src/core/runner_cache.cpp
src/core/runner_cache.h
src/core/segment_weight_pipeline.cpp
src/device_residency_manager.h
src/model_manager.cpp
src/model_manager.h
src/model_manager_prefetch.cpp
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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
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
Related Issue / Discussion
N/A
Additional Information
N/A
Checklist
Summary by CodeRabbit
New Features
Documentation
--max-vrambudgets include managed weights, compute and cache buffers, and idle backend buffers.