Run local Large Language Models (LLMs) on a Raspberry Pi Zero 2W (512 MB RAM) using llama.cpp, swap memory, and aggressive quantization.
This repository documents a real, reproducible setup where an LLM runs fully offline on extremely constrained hardware (no GPU, no cloud, just patience).
- Compiling llama.cpp on Raspberry Pi Zero 2W
- Running GGUF LLMs with 512 MB RAM using swap
- Practical limits, performance numbers, and pitfalls
- A reference setup that actually works
| Component | Details |
|---|---|
| Board | Raspberry Pi Zero 2W |
| RAM | 512 MB |
| CPU | ARM Cortex-A53 (aarch64) |
| OS | Raspberry Pi OS Lite / Debian 13 (trixie) |
| Kernel | 6.12.62+rpt-rpi-v8 |
| Storage | microSD (swap-heavy) |
- Compilation takes ~24 hours on Pi Zero 2W
- Swap is mandatory (2 GB or more)
- Heavy swap usage will wear SD cards. So use a good one
- This is for experimentation & learning, not production
This repo uses a very small, heavily quantized model:
- SmolLM2-135M-Instruct
- Format: GGUF
- Quantization: Q4_K_M
Larger models may not run on this hardware.
free -hExpected (approx):
- RAM: ~416 MB available
- Swap: small or disabled by default
Create a dedicated swap configuration:
sudo mkdir -p /etc/rpi/swap.conf.d/
sudo tee /etc/rpi/swap.conf.d/80-use-swapfile.conf > /dev/null <<EOF
[Main]
Mechanism=swapfile
[File]
FixedSizeMiB=2048
EOFReboot:
sudo rebootVerify:
free -hExpected:
- Swap: ~2.0 GB
sudo apt update
sudo apt install -y build-essential cmake gitmkdir -p ~/projects
cd ~/projects
git clone https://github.com/ggml-org/llama.cpp
cd llama.cppcmake -B buildNo special flags are required for Pi Zero 2W.
cmake --build build --config Release -j3- Build time: ~24 hours
- Swap usage: 1–1.5 GB
- System remains responsive but slow
cd models
wget https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf$ ./build/bin/llama-cli \
-m models/SmolLM2-135M-Instruct-Q4_K_M.gguf \
-p "Can you tell me a short joke?" \
-n 128 \
-t 4
Loading model...
▄▄ ▄▄
██ ██
██ ██ ▀▀█▄ ███▄███▄ ▀▀█▄ ▄████ ████▄ ████▄
██ ██ ▄█▀██ ██ ██ ██ ▄█▀██ ██ ██ ██ ██ ██
██ ██ ▀█▄██ ██ ██ ██ ▀█▄██ ██ ▀████ ████▀ ████▀
██ ██
▀▀ ▀▀
build : b7898-89f10baad
model : SmolLM2-135M-Instruct-Q4_K_M.gguf
modalities : text
available commands:
/exit or Ctrl+C stop or exit
/regen regenerate the last response
/clear clear the chat history
/read add a text file
> Can you tell me a short joke?
Sure, here is a joke for you:
Do you get paid to play _with_ your parents?
To which joke is it funny?
[ Prompt: 10.3 t/s | Generation: 9.5 t/s ]
> yeah
That's a good question. Here's the joke:
Why do people get married? Because their parents want to spend their lives together.
But here's a funny one:
Why do people get divorced? Because their parents want to spend their lives together.
So let's summarize the joke:
Why do people get married? Because their parents want to spend their lives together.
This joke is funny because it uses humor to make the answer more interesting and interesting-sounding. It also has a humorous twist, and the humor in this joke is very fun and silly.
[ Prompt: 18.4 t/s | Generation: 10.9 t/s ]
>
Exiting...
llama_memory_breakdown_print: | memory breakdown [MiB] | total free self model context compute unaccounted |
llama_memory_breakdown_print: | - Host | 377 = 98 + 180 + 98 |- Prompt processing: ~10–18 tokens/sec
- Generation: ~9–11 tokens/sec
- RAM usage: ~300–350 MB
- Swap usage: active but stable
Memory breakdown example:
Host memory ~377 MiB
Model ~180 MiB
Context + compute ~200 MiB
- Small model (135M params)
- Aggressive quantization (Q4_K_M)
- GGUF format optimized for llama.cpp
- Swap-backed virtual memory
- ARM64 build with minimal background services
- Very small context window
- Responses can be repetitive or incoherent
- No parallel workloads
- SD card wear due to swap
- Embedded / edge AI enthusiasts
- Raspberry Pi hackers
- People curious about the absolute lower bound for LLMs
- Anyone who asked: “Will this even run?”
This repo documents usage of llama.cpp, which is licensed under MIT.
Models are subject to their respective licenses. Please check Hugging Face before redistribution.
- llama.cpp by ggml-org
- SmolLM2 model authors
- Raspberry Pi community for enabling questionable ideas like this
If this repo saved you time, confusion, or disbelief, please feel free to ⭐ it.