Repository navigation
Studio: account for mmproj VRAM in GGUF fit budget (#5825) - #5849
Conversation
Vision GGUFs load the mmproj projector onto the GPU via --mmproj alongside the weights, but the context auto-sizing / GPU-selection budget sized off _get_gguf_size_bytes(model_path), which counts only the weight file(s). The projector was never added, so the budget was too optimistic: context got mis-estimated and tight vision loads spilled to system RAM / OOM'd. Resolve the launch projector once before GPU selection and fold its size into the fit budget. The same resolved path feeds both the budget and the --mmproj launch flag, so the two cannot disagree. The summary log now reports the projector size separately, keeping "GGUF size" accurate. Adds _mmproj_vram_bytes() + unit tests (no GPU / network / subprocess).
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request improves VRAM accounting for vision-capable GGUF models by factoring the vision projector (mmproj) size into the GPU fit budget, preventing context mis-estimation and potential OOM issues. It resolves the projector path once, adds its size to the total model size, updates logging to report the projector size, and includes unit tests for this new logic. A review comment suggests improving the readability of the updated logger statement by using a nested f-string instead of mixing explicit and implicit string concatenation.
Address review: the summary log mixed explicit `+` with implicit f-string concatenation. Extract the optional projector fragment into `mmproj_note` so the logger.info uses uniform implicit concatenation. No behavioral change.
Datta0
left a comment
There was a problem hiding this comment.
This does look good. A few examples of before and after measures for a couple of models as predicted by the functions and then sample runs would help speed upthe review. Can you please provide those?
|
@Datta0 Hi I tested this locally with a small Qwen3.5 vision GGUF. Model: Measured local file sizes:
Using the parsed GGUF metadata, the KV estimate at For a constrained 2 GiB device budget, the estimator result changes as follows:
So in this configuration, accounting for the mmproj lowers the fitted context by I also ran the model through Reproduction script#!/usr/bin/env bash
set -euo pipefail
MODEL="unsloth/Qwen3.5-0.8B-GGUF:UD-Q4_K_XL"
OUT="${TMPDIR:-/tmp}/qwen35-mmproj-run"
mkdir -p "$OUT"
echo "llama-server version:"
llama-server --version
wait_for_server() {
local port="$1"
for _ in $(seq 1 120); do
if curl -fsS "http://127.0.0.1:${port}/health" >/dev/null 2>&1; then
return 0
fi
sleep 1
done
echo "server on port ${port} did not become healthy" >&2
return 1
}
run_text_request() {
local port="$1"
curl -fsS "http://127.0.0.1:${port}/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"messages": [{"role": "user", "content": "Reply with exactly: ok"}],
"max_tokens": 8,
"temperature": 0
}'
}
run_image_request() {
local port="$1"
curl -fsS "http://127.0.0.1:${port}/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is the dominant color of this image? Answer with one word."},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC"}}
]
}],
"max_tokens": 16,
"temperature": 0
}'
}
# Baseline: no mmproj.
llama-server \
-hf "$MODEL" \
--no-mmproj \
-c 131072 \
-ngl all \
--port 18080 \
--host 127.0.0.1 \
--no-ui \
--log-file "$OUT/no-mmproj.log" \
--reasoning off &
NO_MMPROJ_PID=$!
wait_for_server 18080
run_text_request 18080 > "$OUT/no-mmproj-response.json"
kill "$NO_MMPROJ_PID"
wait "$NO_MMPROJ_PID" || true
# With mmproj auto-enabled.
llama-server \
-hf "$MODEL" \
-c 131072 \
-ngl all \
--port 18081 \
--host 127.0.0.1 \
--no-ui \
--log-file "$OUT/with-mmproj.log" \
--reasoning off &
WITH_MMPROJ_PID=$!
wait_for_server 18081
run_text_request 18081 > "$OUT/with-mmproj-text-response.json"
run_image_request 18081 > "$OUT/with-mmproj-image-response.json"
kill "$WITH_MMPROJ_PID"
wait "$WITH_MMPROJ_PID" || true
echo
echo "Relevant log lines:"
grep -E "MTL0|estimated worst-case|loaded multimodal|new slot|prompt eval|image processed|model loaded|n_ctx_seq" \
"$OUT/no-mmproj.log" "$OUT/with-mmproj.log"Observed without mmproj:
Observed with mmproj:
Note: on this machine the available Metal memory is ~38 GiB, so both real launches fit the requested |
# Conflicts: # studio/backend/core/inference/llama_cpp.py

Problem
Vision GGUFs load the mmproj (vision projector) onto the GPU via
--mmprojalongside the weights, but Studio's context auto-sizing / GPU-selection budget inLlamaCppBackend.load_modelsizes off_get_gguf_size_bytes(model_path), which counts only the weight file(s). The projector is never added, so the budget is too optimistic: context gets mis-estimated and tight vision loads spill to system RAM / OOM. Reported in #5825 (e.g. a 20.3 GB model + BF16 mmproj on 12 GB VRAM, context silently dropped to 4096).Change
LlamaCppBackend._mmproj_vram_bytes(launch_mmproj_path)returning the projector's on-disk size, or0when none resolves / the file is unreadable.model_size = gguf_size + mmproj_size). The same resolvedlaunch_mmproj_path/effective_is_visionnow feed both the fit budget and the--mmprojlaunch flag, so they can't disagree (previously_resolve_launch_mmproj_pathran twice per load).GGUF size:figure stays accurate.Tests
studio/backend/tests/test_mmproj_vram_accounting.py— no GPU / network / subprocess, cross-platform.test_llama_cpp_context_fit,test_log_filter_no_truncation,test_detect_mmproj_file,test_kv_cache_estimation, …).Scope / non-goals
This fixes the VRAM accounting so the budget is honest. It does not change whether a vision model auto-loads its mmproj (also raised in #5825) — that's a separate product decision, so this links rather than closes the issue.