/dev/posts/

llama.cpp quickstart (part 2)

Published:

Updated:

How to quickly use llama.cpp for LLM inference (part 2). This is a follow-up of a previous post on the same topic.

Update 2026-08-14: add some info about using ROCm (for AMD GPUs) and add some benchmarks.

Update 2026-08-18: add benchmark for flash attention.

Table of content

Manual compilation

Compilation with Vulkan (generic GPU) support:

sudo apt-get install libvulkan-dev glslc spirv-headers cmake

git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
git checkout b10069

cmake -B build -DGGML_VULKAN=1 -DLLAMA_OPENSSL=ON -DCMAKE_INSTALL_PREFIX=/opt/llama.cpp-b10069
cmake --build build --config Release # -j12

sudo cmake --install build --config Release

addopt /opt/llama.cpp-b10069

where addopt is a script which sets up your environment variables (PATH, LD_LIBRARY_PATH, etc.).

Here I am compiling with Vulkan support in order to try hardware acceleration on integrated AMD GP. You can adapt your options to enable other hardware backends.

Run models

Download and execute with a single model:

llama-server --api-key-file keys.txt -hf ggml-org/gemma-4-E4B-it-GGUF:Q4_0

Execute in router mode which makes it possible to switch between all the models you have downloaded:

llama-server --api-key-file keys.txt --no-models-autoload

Security of llama-server

By default, you might see this message when starting llama-server:

CORS is set to allow all origins ('*') and no API key is set this can be a security risk (cross-origin attacks) more info: https://github.com/ggml-org/llama.cpp/pull/25655

By default,

You might want to use the following flags:

Useful parameters

Some small models

Gemma 4:

Qwen 3.6:

Bonsai:

Useful commands

References

Appendix, Compilation with ROCm (AMD)

For my iGPU (AMD Ryzen 5 5600G, targeting gfx900 architecture):

sudo apt-get install librocm-smi-dev rocm-device-libs-21 hip-utils hipcc libhipblas-dev librocblas-dev

export HIPCXX="$(hipconfig -l)/clang"
export HIP_PATH="$(hipconfig -R)"

cmake -S . -B build -DGGML_HIP=ON -DGPU_TARGETS=gfx900 \
  -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=1 \
  -DLLAMA_OPENSSL=ON \
  -DCMAKE_INSTALL_PREFIX=/opt/llama.cpp-b10069
cmake --build build --config Release # -j12
sudo cmake --install build --config Release

sudo setfacl -m u:$USER:rw /dev/kfd

# Needed at runtime for this GPU:
export HSA_OVERRIDE_GFX_VERSION=9.0.0 # etc.

I do not recommend using ROCm for this (integrated) GPU:

Appendix, benchmark

Benchmark on a AMD Ryzen 5 5600G with Radeon Graphics with 40 GiB of RAM (shared with the iGPU), on comparatively small models.

This is a integrated GPU so the result (memory shared with the CPU, somewhat weak GPU) so you should not expect to have similar results with other types of GPUs (such as discrete AMD GPUs). You should reproduce the benchmarks on your system.

Core benchmark

llama-bench -dev none,Vulkan0,Rocm0 -hf "$models" -ngl 5000
Speed in tokens per second (higher is better) of different LLMs with different backends and quantizations
model size params dev Prompt Generation
ggml-org/gemma-4-E2B-it-GGUF:Q4_0 2.63 GiB 4.63 B none 140.84 11.26
Vulkan0 248.26 9.46
ROCm0 133.25 9.67
ggml-org/gemma-4-E2B-it-GGUF:Q8_0 4.61 GiB 4.65 B none 126.09 8.15
Vulkan0 219.37 6.97
ROCm0 119.65 6.87
ggml-org/gemma-4-E4B-it-GGUF:Q4_0 4.26 GiB 7.46 B none 70.12 5.27
Vulkan0 117.08 5.23
ROCm0 57.63 5.21
ggml-org/gemma-4-E4B-it-GGUF:Q8_0 7.46 GiB 7.52 B none 63.88 4.82
Vulkan0 109.92 4.38
ROCm0 63.02 4.94
unsloth/gemma-4-E4B-it-GGUF:Q5_K_M 4.49 GiB 7.52 B none 68.52 6.73
Vulkan0 130.35 7.77
ROCm0 63.28 8.84
unsloth/gemma-4-E4B-it-GGUF:UD-IQ2_M 3.29 GiB 7.52 B none 21.22 12.24
Vulkan0 121.46 10.03
ROCm0 66.32 6.65
ggml-org/gemma-4-26B-A4B-it-GGUF:Q4_0 13.60 GiB 25.23 B none 71.52 9.88
Vulkan0 93.52 9.27
ROCm0 71.01 9.44
unsloth/gemma-4-26B-A4B-it-GGUF:UD-IQ2_M 9.31 GiB 25.23 B none 40.81 10.14
Vulkan0 94.01 7.96
ROCm0 50.66 7.04
unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_M 15.77 GiB 25.23 B none 56.95 6.36
Vulkan0 97.21 6.34
unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q3_K_M 15.45 GiB 34.66 B none 40.61 7.11
Vulkan0 91.96 6.61
unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M 20.60 GiB 34.66 B none 66.64 7.95
Vulkan0 OOM OOM
unsloth/Qwen3.8-27B-GGUF:UD-IQ1_M 6.26 GiB 26.90 B none 3.81 2.80
Vulkan0 20.81 2.57
unsloth/Qwen3.8-27B-GGUF:UD-Q2_K_XL 9.14 GiB 27.32 B none 3.33 2.41
Vulkan0 19.65 2.24

Take away:

MTP benchmark

Here I am checking the impact of using Multi-Token Prediction (MTP) on ggml-org/gemma-4-E4B-it-GGUF:Q8_0.

llama-cli -n 250 --perf -st --warmup --simple-io \
        -hf "$model" -sysf "$prompt_file" -p "$user_prompt" \
        --spec-type none

llama-cli -n 250 --perf -st --warmup --simple-io \
        -hf "$model" -sysf "$prompt_file" -p "$user_prompt" \
        --spec-type draft-mtp --spec-draft-n-max "$draft_n_max"
Speed in tokens per second (higher is better) with different MTP configurations
spec-draft-n-max none Vulkan0
OFF 4.0 4.0
1 5.8 6.2
2 4.5 7.2
3 8.4 8.3
4 5.4 8.0
5 8.1 9.1
6 4.9 8.0
7 7.7 5.7
8 5.3 6.1
9 7.8 7,8

MTP is only used for text generation to there is no impact on text ingestion.

Take away:

Given the relatively small output length, the stochasticity of speculation hits, and the noise of these results, this benchmark should be taken with some pinch of salt.

Flash attention

Here I am checking the impact of using flash attention.

llama-bench -hf "$models" -dev none,Vulkan0 -fa off,on -ngl 5000
Speed in tokens per second (higher is better) with and without flash attention
Model dev Flash Att. Prompt Generation
ggml-org/gemma-4-E4B-it-GGUF:Q8_0 none off 65.88 5.24
none on 65.42 5.32
Vulkan0 off 126.63 5.41
Vulkan0 on 128.55 5.53
ggml-org/gemma-4-26B-A4B-it-GGUF:Q4_0 none off 71.49 9.61
none on 71.07 9.79
Vulkan0 off 97.88 8.02
Vulkan0 on 104.76 8.03

Take away: