ThisCalculator

Everyday

Benchmark LLMs on Raspberry Pi 5 with llama.cpp

Updated · Standard formula, shown below

This guide explains how to benchmark large language models (LLMs) on a Raspberry Pi 5 using llama.cpp, a C/C++ inference engine optimized for local hardware. You will learn how to install the software, download quantized models, run standardized performance tests, and interpret the results to choose the best model for your Pi.

Why Benchmark on a Raspberry Pi 5?

The Raspberry Pi 5, with its quad-core Arm Cortex-A76 CPU and up to 8 GB of RAM, is a surprisingly capable platform for running small LLMs. Unlike cloud-based AI, local inference on a Pi offers privacy, offline availability, and zero per-request costs. However, the Pi’s limited memory and lack of a powerful GPU mean that only quantized models (e.g., 1-3 GB in size) run comfortably. Benchmarking tells you which model gives the best balance of speed (tokens per second) and quality for your specific use case, such as chatbots, code completion, or text summarization.

What Is llama.cpp and Why Use It?

llama.cpp is an open-source library that runs LLMs on CPUs and GPUs with a focus on efficiency. It supports quantization formats like GGUF, which reduce model size by lowering the precision of weights (e.g., from 16-bit to 4-bit). This makes it possible to run models that would otherwise require gigabytes of VRAM on a device with only 8 GB of shared memory. The project also includes a simple benchmarking tool called llama-bench that measures tokens per second for prompt processing and text generation.

Step-by-Step Benchmarking Guide

Follow these steps to benchmark an LLM on your Raspberry Pi 5. The process assumes a 64-bit OS (e.g., Raspberry Pi OS Lite 64-bit) and an internet connection.

  1. Update your system: Open a terminal and run sudo apt update && sudo apt upgrade -y to ensure all packages are current.
  2. Install build tools: Run sudo apt install -y git cmake build-essential to get the compiler and build tools.
  3. Clone llama.cpp: Run git clone https://github.com/ggerganov/llama.cpp and then cd llama.cpp.
  4. Build with benchmark support: Run cmake -B build followed by cmake --build build --config Release. This compiles the main executables, including llama-bench.
  5. Download a quantized model: Choose a GGUF model from Hugging Face, such as Qwen2.5-0.5B-Instruct-Q4_K_M.gguf or Llama-3.2-1B-Instruct-Q4_K_M.gguf. Use wget to download it into a models/ folder.
  6. Run the benchmark: Execute ./build/bin/llama-bench -m models/your-model.gguf. This will run default tests for prompt processing and generation.
  7. Read the output: The tool prints a table with columns like model size, test, t/s (tokens per second), and memory. The t/s for generation is the key metric for interactive use.

Choosing the Right Model for Your Pi

Not all models run well on a Raspberry Pi 5. The primary constraint is RAM: the Pi 5 has 4 GB or 8 GB, but the OS and other processes use some of that. For smooth operation, the model file should be at least 1 GB smaller than total RAM. For example, on an 8 GB Pi, a 3 GB model leaves enough room for the OS and overhead.

Here are practical guidelines:

  • 0.5B to 1B parameter models (quantized to Q4) are the sweet spot for speed, often achieving 10-20 tokens per second on a Pi 5.
  • 2B to 3B models run but may be slower (5-10 tokens per second) and may cause memory pressure if the file is large.
  • 7B models are generally too slow (under 2 tokens per second) and may not fit in RAM unless heavily quantized (Q2 or Q3).

Use the llama-bench results to compare models with the same quantization level. Higher tokens per second means faster responses, but quality also matters—a 1B model may be faster but less capable than a 3B model.

Interpreting the Benchmark Results

The benchmark output has two main sections: prompt processing (how fast the model reads input) and text generation (how fast it produces output). For most interactive applications, generation speed is what you feel. A value of 10 tokens per second is roughly 10 words per second, which is acceptable for chat. Prompt processing speed is less critical unless you are doing batch processing.

Also note the memory column: it shows the peak RAM usage. If this exceeds your Pi’s available memory, the system will swap to disk, causing severe slowdowns. In that case, try a smaller model or a lower quantization (e.g., Q4 to Q3).

Common Problems and Fixes

Here are typical issues you might encounter and how to resolve them:

  • Build fails due to missing packages: Ensure you installed build-essential and cmake. Also check that you have enough free disk space (at least 2 GB).
  • Model downloads too slowly: Use a wired Ethernet connection or download during off-peak hours. Some models are several gigabytes.
  • Out of memory errors: Reduce the model size or quantization. Also close other applications and run the benchmark in a terminal without a desktop environment.
  • Benchmark runs but no output: Ensure the model path is correct and that the file is a valid GGUF format. Some models may require a specific context size; try adding -c 512 to reduce memory usage.
  • Slow performance: Overclocking the Pi 5 (via raspi-config) can improve speed, but monitor temperatures to avoid throttling.

Comparing with Other Devices

The Raspberry Pi 5 is not the fastest device for LLM inference, but it is one of the cheapest and most accessible. For comparison, a modern desktop CPU can achieve 50-100 tokens per second with the same model, while a smartphone with a neural processing unit might be faster or slower depending on the model. The Pi’s advantage is its low power consumption (around 5-10 watts) and silent operation, making it ideal for a dedicated local AI assistant.

Cost and Power Considerations

The Raspberry Pi 5 itself costs around $60-80 for the 8 GB model, plus a power supply and microSD card. Running an LLM continuously draws about 5-10 watts, which is negligible on an electricity bill. Compared to cloud APIs, which charge per token, a Pi is a one-time cost. However, you must factor in the time spent configuring and the limited model quality compared to large cloud models.

Safety and Responsible Use

Running LLMs locally means you are responsible for the content they generate. Models can produce biased or harmful text, so use them with caution, especially in public-facing applications. Also, be aware that downloading models from the internet carries a supply-chain risk; only download from trusted sources like Hugging Face. Finally, ensure your Pi is properly cooled (a fan or heatsink) to prevent thermal throttling during long benchmarks.

Frequently Asked Questions

Can I use a GPU with the Raspberry Pi 5?

No, the Pi 5 does not have a discrete GPU. It uses a VideoCore VII GPU that is not supported by llama.cpp for acceleration. All inference runs on the CPU, which is why model size and quantization are so important.

What is the best quantization level for the Pi?

Q4_K_M is a good balance between quality and speed. Q8 is higher quality but uses more memory and is slower. Q2 or Q3 are smaller but may degrade quality noticeably. Start with Q4_K_M and adjust based on your RAM and speed needs.

How do I measure tokens per second accurately?

Use the built-in llama-bench tool, which runs multiple iterations and averages results. Do not rely on manual timing, as it includes overhead. Run the benchmark at least three times and take the median.

Can I run a 7B model on an 8 GB Pi?

Technically yes, if you use a heavily quantized version (e.g., Q2_K) that fits in memory, but it will be very slow (under 2 tokens per second) and may cause swapping. It is not recommended for interactive use.

Does the microSD card speed affect benchmark results?

Yes, but only during model loading. Once the model is in RAM, the SD card speed does not affect inference. Use a fast A2-rated card to reduce load times, but benchmark results will be similar.

Why does my benchmark show different results than others?

Variations can come from ambient temperature (thermal throttling), background processes, and the specific model file. Ensure your Pi is well-cooled and close all other applications before benchmarking.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.