/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_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llama.cpp-b10069
cmake --build build # -j12

sudo cmake --install build

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:

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 # -j12
sudo cmake --install build

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
modelsizeparamsdevPromptGeneration
ggml-org/gemma-4-E2B-it-GGUF:Q4_02.63 GiB4.63 Bnone140.8411.26
Vulkan0248.269.46
ROCm0133.259.67
ggml-org/gemma-4-E2B-it-GGUF:Q8_04.61 GiB4.65 Bnone126.098.15
Vulkan0219.376.97
ROCm0119.656.87
ggml-org/gemma-4-E4B-it-GGUF:Q4_04.26 GiB7.46 Bnone70.125.27
Vulkan0117.085.23
ROCm057.635.21
ggml-org/gemma-4-E4B-it-GGUF:Q8_07.46 GiB7.52 Bnone63.884.82
Vulkan0109.924.38
ROCm063.024.94
unsloth/gemma-4-E4B-it-GGUF:Q5_K_M4.49 GiB7.52 Bnone68.526.73
Vulkan0130.357.77
ROCm063.288.84
unsloth/gemma-4-E4B-it-GGUF:UD-IQ2_M3.29 GiB7.52 Bnone21.2212.24
Vulkan0121.4610.03
ROCm066.326.65
ggml-org/gemma-4-26B-A4B-it-GGUF:Q4_013.60 GiB25.23 Bnone71.529.88
Vulkan093.529.27
ROCm071.019.44
unsloth/gemma-4-26B-A4B-it-GGUF:UD-IQ2_M9.31 GiB25.23 Bnone40.8110.14
Vulkan094.017.96
ROCm050.667.04
unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_M15.77 GiB25.23 Bnone56.956.36
Vulkan097.216.34
unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q3_K_M15.45 GiB34.66 Bnone40.617.11
Vulkan091.966.61
unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M20.60 GiB34.66 Bnone66.647.95
Vulkan0OOMOOM
unsloth/Qwen3.8-27B-GGUF:UD-IQ1_M6.26 GiB26.90 Bnone3.812.80
Vulkan020.812.57
unsloth/Qwen3.8-27B-GGUF:UD-Q2_K_XL9.14 GiB27.32 Bnone3.332.41
Vulkan019.652.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-maxnoneVulkan0
OFF4.04.0
15.86.2
24.57.2
38.48.3
45.48.0
58.19.1
64.98.0
77.75.7
85.36.1
97.87,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
ModeldevFlash Att.PromptGeneration
ggml-org/gemma-4-E4B-it-GGUF:Q8_0noneoff65.885.24
noneon65.425.32
Vulkan0off126.635.41
Vulkan0on128.555.53
ggml-org/gemma-4-26B-A4B-it-GGUF:Q4_0noneoff71.499.61
noneon71.079.79
Vulkan0off97.888.02
Vulkan0on104.768.03

Take away: