Skip to content

Misc. bug: ROCm backend leaks VRAM with quantized KV cache #23873

Description

@Edremon

Name and Version

I had a local unrelated server commit applied on top, it was built on 6ed481e.

version: 9414 (4614480ab)
built with GNU 16.1.1 for Linux x86_64

Operating systems

Linux

Which llama.cpp modules do you know to be affected?

libllama (core library)

Command line

# Leaking case (rocm-kv-q8_0-vram-leak.log)
./llama-server \
    --no-mmap --no-mmproj-offload --ctx-size 65536 \
    --cache-type-k q8_0 --cache-type-v q8_0 \
    --fit-target 3072 \
    --model gemma-4-31B-it-UD-Q4_K_XL.gguf \
    --mmproj mmproj-BF16.gguf \
    --temp 1.0 --top-p 0.95 --top-k 64 --reasoning off \
    --verbosity 4

# Baseline (rocm-kv-f16-no-leak.log)
./llama-server \
    --no-mmap --no-mmproj-offload --ctx-size 65536 \
    --fit-target 3072 \
    --model gemma-4-31B-it-UD-Q4_K_XL.gguf \
    --mmproj mmproj-BF16.gguf \
    --temp 1.0 --top-p 0.95 --top-k 64 --reasoning off \
    --verbosity 4

# Vulkan (vulkan-kv-q8_0-no-leak.log)
./llama-server \
    --no-mmap --no-mmproj-offload --ctx-size 65536 \
    --cache-type-k q8_0 --cache-type-v q8_0 \
    --fit-target 3072 \
    --model gemma-4-31B-it-UD-Q4_K_XL.gguf \
    --mmproj mmproj-BF16.gguf \
    --temp 1.0 --top-p 0.95 --top-k 64 --reasoning off \
    --verbosity 4

# V only crash (rocm-kv-v-q8_0-crash.log)
./llama-server \
    --no-mmap --no-mmproj-offload --ctx-size 65536 \
    --cache-type-v q8_0 --fit off --gpu-layers 18 \
    --model gemma-4-31B-it-UD-Q4_K_XL.gguf \
    --mmproj mmproj-BF16.gguf \
    --temp 1.0 --top-p 0.95 --top-k 64 --reasoning off \
    --verbosity 4

Problem description & steps to reproduce

When using KV cache quantization (--cache-type-k q8_0, --cache-type-v q8_0) with the ROCm/HIP backend, VRAM continuously grows during prompt processing. This makes --fit completely wrong, for a simple ~20k tokens prompt, VRAM is growing by more than 2 GiB, at this time, KV cache quantization is unusable, if it's a know issue, then KV cache quantization for the ROCm/HIP backend should simply be disabled in release build or with several warning attached. I did try if it was only K or V related, I reproduced it with K only, but didn't manage to run server with only V quantized, it crashed even when manually setting gpu-layers with --fit off. Vulkan backend doesn't have this problem, fit correctly estimate VRAM needed and it doesn't grow during prompt processing. It does seem to happen with every models that I have tried, forcing me to use Vulkan backend which is slower on my system, but at least doesn't have that issue.

I'm using a RDNA 2 GPU with ROCm 7.2.3.

I did see some potentially related issue, notably #19979 which is closed as completed. But I do still see a similar problem.

First Bad Commit

No response

Relevant log output

rocm-kv-q8_0-vram-leak.log
rocm-kv-f16-no-leak.log
vulkan-kv-q8_0-no-leak.log
rocm-kv-v-q8_0-crash.log

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions