fix: evict idle models before loading reranker on low-VRAM GPUs#276
Open
fix: evict idle models before loading reranker on low-VRAM GPUs#276
Conversation
On GPUs with limited VRAM (e.g. 2 GB), `qmd query` crashes at the reranking step because the generation model (~1.2 GB) and embedding model (~314 MB) remain resident while the reranker (~610 MB + 960 MB context) tries to allocate. Before loading the reranker, check free VRAM against the model file size plus context overhead. If insufficient, dispose the generation and embedding models first — they've already completed their work in the pipeline and can be reloaded from disk later if needed. On machines with enough VRAM, the check passes and nothing is evicted. Tested on GTX 960M (2 GB VRAM), driver 560.35.05, CUDA 12.6.
6abb410 to
8d61ba0
Compare
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.
Problem
On GPUs with limited VRAM (e.g. 2 GB GTX 960M),
qmd querycrashes at the reranking step:The three models (generation ~1.2 GB, embedding ~314 MB, reranker ~610 MB) plus a rerank context (~960 MB) total ~3.1 GB — well beyond 2 GB. Since query expansion and embedding are already done by the time reranking starts, those models sit idle in VRAM while the reranker fails to allocate.
Fix
In
ensureRerankModel(), before loading the reranker, check free VRAM against the reranker model file size + context overhead. If insufficient, dispose the generation model and embedding model/contexts — they've already completed their work and can be reloaded from disk later if needed.statSyncon the model file (already imported) so the threshold adapts if models changeTesting
Tested on GTX 960M (2 GB VRAM), driver 560.35.05, CUDA 12.6:
qmd querycrashes at reranking every timeRelates to #275