Run standardized benchmarks on GGUF models using llama.cpp's llama-bench tool.
bash
# Basic benchmark
llama-bench -m model.gguf -p 512,1024,2048 -n 128,256 -ngl 99
# With specific backend
LLAMA_BACKEND=vulkan llama-bench -m model.gguf -p 512,1024,2048 -n 128,256 -ngl 99
ParameterDescriptionDefault-mModel path (GGUF file)required-pPrompt sizes to test512-nGeneration lengths to test128-nglGPU layers to offload99-tCPU threadsauto-devDevice selectionauto
For consistent comparisons across models, use:
bash
-p 512,1024,2048 -n 128,256 -ngl 99
This tests:
MetricMeaningGood Performancepp512Prompt processing speed at 512 tokens>1000 t/spp1024Prompt processing speed at 1024 tokens>1000 t/spp2048Prompt processing speed at 2048 tokens>1000 t/stg128Token generation speed (128 tokens)>50 t/stg256Token generation speed (256 tokens)>50 t/s
llama-bench auto-detects available backends. Priority order:
To force a backend, set environment variable or check build:
bash
# Check available backends
llama-bench --help | grep -i "backend\|cuda\|rocm\|vulkan"
Use the provided script for benchmarking multiple models:
bash
./scripts/benchmark_models.sh /path/to/models/*.gguf
Output can be redirected to a file:
bash
llama-bench -m model.gguf -p 512,1024,2048 -n 128,256 -ngl 99 > results.txt
Or use the benchmark script which auto-saves to timestamped files.
-ngl (GPU layers) or test smaller prompt sizes-t matches CPU core countbash
./scripts/build_llamacpp.sh -v
Shows:
bash
# Interactive mode (prompts for backend selection)
./scripts/build_llamacpp.sh -u
# Specify backend directly
./scripts/build_llamacpp.sh -u -b vulkan # Vulkan (AMD/Intel GPUs)
./scripts/build_llamacpp.sh -u -b cuda # CUDA (NVIDIA GPUs)
./scripts/build_llamacpp.sh -u -b rocm # ROCm (AMD GPUs)
./scripts/build_llamacpp.sh -u -b cpu # CPU only
# Clean rebuild
./scripts/build_llamacpp.sh -c -b vulkan
# Custom build directory
./scripts/build_llamacpp.sh -u -b cuda -d /custom/path
FlagDescription-vShow version info and exit-uUpdate to latest from GitHub-cClean build (remove existing)-bBackend: vulkan, cuda, rocm, cpu-dBuild directory path-jParallel jobs (default: CPU count)
The benchmark script auto-detects llama-bench in these locations:
/DATA/Benchmark/llama.cpp/build/bin/llama-bench~/Repo/llama.cpp/build/bin/llama-bench~/lab/build/bin/llama-benchIf not found, it will search your home directory or you can build it using the script above.