Repository navigation
Conversation
With --image-max-tokens N, llama.cpp warmed a Qwen-VL encoder with the largest square under N (35x35 = 1,225 tokens for 1,280). smart_resize lets photos reach N (a 1280x1261 photo gets 36x35 = 1,260), and each photo bigger than any before rebuilt the encoder's compute buffers from the largest free block, leaving the old ones as a hole. patches/0021 warms Qwen2-VL, 2.5-VL, 3-VL and Ling3-VL projectors with exactly N tokens (40x32 for 1,280): their buffers depend only on the token count, never the shape. It also logs when an image grows a compute buffer after the warm-up. Other projectors and runs without a cap are unchanged. tests/server_vision_warmup_test.py runs untrained Qwen3-VL fixtures on a host llama-server with images of 1,225 to 1,280 tokens and fails when a buffer grows; it fails with the warm-up change switched off.
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. |
cobanov
left a comment
There was a problem hiding this comment.
Thanks @Adon1s, this is the llama.cpp-side fix I hoped for, and the reasoning holds up. The Qwen-VL graphs size by patch count only, so warming at exactly the cap, in any a×b shape, is the real worst case. The PS5 table (no more ~150 MiB steps at photos 15 and 23) and the CPU test that fails without the change make it convincing, and 0021 is a free number.
The catch is timing. #103 has just landed and moved llama.cpp to d2bceda3d, where clip.cpp and clip-model.h no longer exist, so 0021 no longer applies on main (the green CI here is from the old base). Could you:
- Port the patch to
tools/mtmd/mtmd-model.h(set_warmup_n_tokens),mtmd-model.cpp(the QWEN2VL/25VL/3VL/LING3VL case) andmtmd-subcontext.cpp(get_dummy_batchfor the w×h image). - Vision and audio now share one sched, so keep the "compute buffer grew" baseline on the shared
mtmd_backendssched. Take it after all the sub-contexts have warmed up, next to the compute-buffer log inmtmd.cpp. - Update the
warmup_buffersmatch intests/server_vision_warmup_test.py, which looks for the line underreserve_compute_meta, and rerun it with--projectoron the real mmproj. A quick photo run on the console after the port would be great too.
Optional: this looks upstreamable to ggml-org/llama.cpp, which would let us drop the patch later.
What happens
With
--image-max-tokens N, llama.cpp warms a Qwen vision encoder with the largest square under N: 35×35 = 1,225tokens for 1,280 (
clip-model.h,set_warmup_n_tokens). Photos get more than that.smart_resizerounds each sideto 32 px and scales down only when the result is over N, so every count up to N is reached: a 1280×1261 photo gets
36×35 = 1,260 tokens, a 1280×1024 one 40×32 = 1,280.
Each photo with more tokens than any before rebuilds the encoder's GPU buffers. The new buffer is cut from the
largest free block and the old one is left as a hole. That is the GPU part of the loss in #75.
Why exactly N, in any shape
The Qwen graphs (Qwen2-VL, 2.5-VL with its window attention, 3-VL, and Ling3-VL, which shares their setup) size
every tensor by the patch count, width × height. None uses either side alone: the learned position table is
interpolated to the grid in one op. So the most the buffers ever need is N tokens, whatever the shape. ggml grows a
buffer for any increase, so the warm-up has to be exactly N, not close to it.
llama.cpp's master still warms with the square (the code moved to
mtmd-model.hon 2026-11-08).Change
patches/0021: for those projectors, when--image-max-tokens Nis below their warm-up size (46×46), thewarm-up image is a×b = N tokens, b the largest divisor of N not over its square root. 1280 gives 40×32
(1280×1024 px); a prime N gives 1×N.
--image-max-tokensnothingchanges.
(
compute buffer grew from A to B MiB for a W x H image). ggml's own line for that is a debug line, compiled outof release builds.
tests/server_vision_warmup_test.py(run byscripts/test-fleet.sh --rpc): untrained Qwen3-VL text and projectorfixtures on a CPU llama-server with
--image-max-tokens 1280, and images of 1,225, 1,240, 1,260 and 1,280 tokens.It checks each image's token count, the 1280×1024 warm-up, and that no buffer grows. With the warm-up change
switched off it fails: the buffer grows three times.
Tested
PC, CI container, CPU llama-server, Unsloth's Qwen3.8-27B
mmproj-F16.gguf(the test with--projector):So the warm-up reserves 6.5 MiB more, once, and that is memory the photos took anyway.
PS5 (stock PS5LM title, Qwen3.8-27B UD-IQ2_S with
mmproj-F16.gguf,-c 2048 -b 1280 -ub 256 --image-max-tokens 1280, screen on, the same 25 listing photos as in #75 at full size, memory logged after eachphoto while the server was idle). MiB, largest free block:
main0 errors in both runs, about 10–13 s a photo. The two drops of ~150 MiB, one whole encoder buffer each, are gone;
the run ends 215 MiB higher. What is left is smaller steps; at photo 23 the title heap's peak rose 52 MiB, which
#110 handles.