ggml-cuda : add defensive VRAM margin to prevent swapping stalls#22580
Closed
demiquartz wants to merge 1 commit intoggml-org:masterfrom
Closed
ggml-cuda : add defensive VRAM margin to prevent swapping stalls#22580demiquartz wants to merge 1 commit intoggml-org:masterfrom
demiquartz wants to merge 1 commit intoggml-org:masterfrom
Conversation
* Add a 256MB defensive margin to ggml_cuda_device_malloc to prevent VRAM overcommit * Implement a 1GB grace interval for free_caches to reduce cudaMemGetInfo overhead * Prevents "swapping loops" that lead to system RAM exhaustion and computation stalls, especially on WSL2/ROCm Assisted-by: AI (Gemini)
Contributor
|
Create an issue with a reproduction first |
Author
|
I have created the issue with detailed reproduction steps and environmental information as requested: #22583 |
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.
Overview
This PR adds a defensive VRAM margin in
ggml_cuda_device_mallocto prevent system instability and computation stalls caused by VRAM overcommit, specifically in WSL2 with ROCm environments.free_cachesto minimize the performance overhead of callingcudaMemGetInfo.Additional information
In environments like WSL2/ROCm (tested with 7900 XTX), exceeding physical VRAM triggers a "swapping loop" where active inference memory is moved between VRAM and system RAM. This saturates the PCIe bus, causing the GPU computation to stall indefinitely and leading to rapid system RAM exhaustion, even if the process remains active. This PR ensures
llama.cppreports a memory allocation error before this stall occurs.Requirements
size_tcalculations, and cross-compiler compatibility. The core logic (Margin and Grace thresholds) and the diagnosis of the swapping-related stall were conceptualized and validated by the human contributor through practical troubleshooting.Closes #22583