r/LocalLLaMA • • 7h ago

Question | Help Llama.cpp compute buffer allocation issue

I recently updated llama.cpp for using qwen4. This is on an M3 Pro mac with 36GB memory, earlier I was able to run qwen3.5 0.8B Q8 at full context with q8_0 K and V cache.

However, now when using q8_0 or q4_0 KV Cache, the memory usage has ballooned, f16 cache uses lesser memory than the quantized ones. I tested qwen3.5 9B, gemma4 12B and they too had this weird issue, so it's not the models but some change in llama.cpp itself.

I have created an issue for this, are any of you experiencing this bug?

https://github.com/ggml-org/llama.cpp/issues/33801

5 Upvotes

3 comments sorted by

2

u/Mithrandir_First_Age 5h ago

I can try to repro this later today on an M4 Mac mini 16 GB and an M5 Max 128 GB. What build are you on, and does it still happen with -fa on and -ub 512? My guess is the compute buffer sizing changed, since a q8_0 cache shouldn't need more than f16. Worth adding your full command to the GitHub issue too. Tell me :)

1

u/PM_ME_YOUR_ROSY_LIPS 5h ago

Thanks that'd help. I tested this on build 13012, but it is the same on the latest too (i just build it after pulling, not using any files from the git release).

I have the command listed on git and in a comment here as well:

llama-server -m ~/ai/models/Qwen3.5-0.8B-Q8_0.gguf -mm ~/ai/models/mmproj-qwen3.5-0.8B-BF16.gguf -c 262144 -ctk q8_0 -ctv q8_0 -b 2048 -ub 2048 --temp 1.0 --top-p 1.0 --top-k 20 --min-p 0.00 --presence-penalty 2.0 --repeat-penalty 1.0 --spec-type ngram-mod --host 0.0.0.0 --reasoning off -lv 4

-fa is always needed when using quantized kv, so the flag is switched on. It doesn't work with -ub 512 too. I am running it with --parallel 1 which seems to be working as before at the cost of concurrency.

Yeah I agree that some default compute value has changed for the buffer allocation but I haven't kept up with all llama.cpp changes. The kv cache buffer is still less for quantized ones but the Compute buffer allocation is where it's going awry.

1

u/PM_ME_YOUR_ROSY_LIPS 7h ago edited 7h ago

The logs.

    llama-server -m ~/ai/models/Qwen3.5-0.8B-Q8_0.gguf -mm ~/ai/models/mmproj-qwen3.5-0.8B-BF16.gguf -c 262144 -ctk q8_0 -ctv q8_0 -b 2048 -ub 2048 --temp 1.0 --top-p 1.0 --top-k 20 --min-p 0.00 --presence-penalty 2.0 --repeat-penalty 1.0 --spec-type ngram-mod --host 0.0.0.0 --reasoning off -lv 4 
  • When using q8_0
    0.00.463.928 E ggml_metal_buffer_init: error: failed to allocate buffer, size = 35329.61 MiB
    0.00.463.930 E ggml_backend_metal_buffer_type_alloc_buffer: failed to allocate Metal buffer of 37045772800 bytes (out of memory)
    0.00.463.940 E ggml_gallocr_reserve_n_impl: failed to allocate MTL0 buffer of size 37056553696
    0.00.463.941 E graph_reserve: failed to allocate compute buffers
    0.00.464.018 I ggml_metal_free: deallocating
    0.00.468.262 E llama_init_from_model: failed to initialize the context: failed to allocate compute tg buffers
    0.00.468.378 E cmn  common_init_: failed to create context with model '/Users/user/ai/models/Qwen3.5-0.8B-Q8_0.gguf'
    0.00.468.379 E cmn  common_init_: failed to create context with model '/Users/user/ai/models/Qwen3.5-0.8B-Q8_0.gguf'
    0.00.468.380 E srv    load_model: failed to create_context with model '/Users/user/ai/models/Qwen3.5-0.8B-Q8_0.gguf'
    0.00.468.390 I srv    operator(): operator(): cleaning up before exit...
    0.00.468.605 E srv  server_run_i: exiting due to model loading error
  • When using q4_0
    0.01.802.217 I common_memory_breakdown_print: | memory breakdown [MiB]  | total   free     self   model   context   compute    unaccounted |
    0.01.802.224 I common_memory_breakdown_print: |   - MTL0 (Apple M3 Pro) | 28753 = 7736 + (20657 =   763 +     942 +   18951) +         359 |
    0.01.802.225 I common_memory_breakdown_print: |   - Host                |                  1317 =   257 +       0 +    1060                |
  • When using f16
    0.02.863.372 I common_memory_breakdown_print: | memory breakdown [MiB]  | total    free    self   model   context   compute    unaccounted |
    0.02.863.375 I common_memory_breakdown_print: |   - MTL0 (Apple M3 Pro) | 28753 = 20763 + (7630 =   763 +    3149 +    3718) +         359 |
    0.02.863.376 I common_memory_breakdown_print: |   - Host                |                  1317 =   257 +       0 +    1060                |