webcentive


llama.cpp Tuning on the ODROID-HC1

By @tonycasanova, North Carolina, with Grok

Result in brief. On this board, locking the CPU at performance and stopping Grafana, Prometheus and node-exporter raised llama.cpp token generation of Qwen2.5-Coder-0.5B Q4_0 from 6.11 to 8.61 tokens/s (about +41%). Prefill stayed about the same. Q4_0 then beat Q8_0 by about 31% on generate and 7% on prefill. A companion to the assembly-versus-C matvec experiment on the same ODROID-HC1.

Hardware and method

Board: ODROID-HC1, Samsung Exynos 5422, 32-bit ARMv7, 2 GB RAM, Ubuntu 20.04, kernel 5.4.275 armv7l. All runs were pinned to the four Cortex-A15 cores with taskset -c 4-7. The tool was llama-bench from llama.cpp build 925e11799 (10642). The model is Qwen2.5-Coder-0.5B-Instruct, 630.17 million parameters, in GGUF form. Every run used -p 128 -n 128 -fa 1 (128-token prefill, 128-token generation, flash attention on). Times are reported as llama-bench’s mean ± standard deviation in tokens per second: pp128 is prefill, tg128 is token generation.

Results

1. Baseline

Governor ondemand, Grafana, Prometheus and node-exporter running, Q4_0, -t 4, -r 2 (two repetitions).

Baseline, Q4_0, four A15 threads, two reps
Testtokens/s
Prefill (pp128)21.32 ± 0.04
Generate (tg128)6.11 ± 0.02

2. Threads, with clocks locked and monitors stopped

Governor performance (A15 at 2.0 GHz; the A7 cluster was also set to performance, 1.4 GHz), Grafana, Prometheus and node-exporter stopped. Q4_0, 403.20 MiB, -r 3. Still taskset -c 4-7.

Q4_0, performance governor, monitors stopped, three reps
Threads (-t)pp128 (t/s)tg128 (t/s)
211.46 ± 0.016.16 ± 0.00
316.95 ± 0.057.68 ± 0.00
421.25 ± 0.128.61 ± 0.03

Token generation vs thread count (Q4_0, tuned state)

Bar length is linear in tokens/s (max 8.61). The baseline (ondemand, monitors on, -t 4) is the lighter bar.

baseline tg, t=46.11 t/s
tuned tg, t=26.16 t/s
tuned tg, t=37.68 t/s
tuned tg, t=48.61 t/s

Prefill vs thread count (Q4_0)

Bar length is linear in tokens/s (max 22.11, from the later Q4_0 comparison run). Prefill at four threads is essentially unchanged from the baseline.

baseline pp, t=421.32 t/s
tuned pp, t=211.46 t/s
tuned pp, t=316.95 t/s
tuned pp, t=421.25 t/s

3. Q4_0 vs Q8_0

Same tuned state (performance governor, monitors stopped), -t 4, -r 3. The Q8_0 file is from the official Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF repository (qwen2.5-coder-0.5b-instruct-q8_0.gguf). The Q4_0 file in this comparison is 403.20 MiB; Q8_0 is 638.74 MiB.

Q4_0 vs Q8_0, four A15 threads, three reps, tuned state
QuantFile sizepp128 (t/s)tg128 (t/s)
Q4_0403.20 MiB22.11 ± 0.188.59 ± 0.03
Q8_0638.74 MiB20.59 ± 0.106.58 ± 0.01

The Q4_0 prefill here (22.11 t/s) is a separate run from the 21.25 t/s in the thread table above. Generation is effectively the same (8.59 vs 8.61). The two Q4_0 rows are not averaged together in the findings.

Q4_0 vs Q8_0 at four threads

Bar length is linear in tokens/s. Prefill uses a 22.11 scale; generation uses an 8.61 scale, drawn as separate groups.

Prefill

Q4_0 pp22.11 t/s
Q8_0 pp20.59 t/s

Generate

Q4_0 tg8.59 t/s
Q8_0 tg6.58 t/s

Findings

Token generation rose about 41% after the machine was tuned. Going from the baseline (6.11 t/s) to the locked-clock, monitors-off, four-thread Q4_0 run (8.61 t/s) is 8.61 / 6.11 − 1 = 40.9%, which is the “about +41%” figure. Prefill at four threads was unchanged in any practical sense: 21.32 t/s in the baseline vs 21.25 t/s in the thread table (−0.3%). Prefill looks compute-bound and already saturated on the four A15 cores at this prompt length; generation was the part that had been leaving performance on the table.

Generation still scales with threads, so it is not bandwidth-saturated at four cores. In the tuned state, tg goes 6.16 → 7.68 → 8.61 t/s at 2, 3 and 4 threads: +25% from two to three, and +12% from three to four. The curve is flattening, but it has not gone flat. Prefill scales more steeply (11.46 → 16.95 → 21.25 t/s), which fits a compute-bound prefill.

Q4_0 beats Q8_0 by about 31% on generate and 7% on prefill. From the head-to-head at four threads: 8.59 / 6.58 − 1 = 30.5% on tg, and 22.11 / 20.59 − 1 = 7.4% on pp. The Q8_0 file is 638.74 / 403.20 − 1 = 58.4% larger, so Q8_0 moves about 58% more bytes per token if the weights are streamed from memory. That hurts generation, which re-reads the model for every token, more than it hurts a 128-token prefill, which can amortize the read. This is the same qualitative result as the assembly-versus-C matvec experiment on this board: SIMD, INT8 (here, a 4-bit quant vs 8-bit) and memory bandwidth matter more than writing a kernel in assembly. The large llama.cpp gain here came from clocks, background load, and the smaller quant — not from a new inner loop.

Recommended configuration

For this model on this board: performance governor, Grafana / Prometheus / node-exporter stopped, Q4_0, -t 4 -fa 1, and taskset -c 4-7. That is the 8.61 t/s generate / 21.25 t/s prefill setup (or the later 8.59 / 22.11 Q4_0 comparison run). Q8_0 is slower here and uses more RAM, so it is not the default on 2 GB.

When the measurement is finished, put the governor back to ondemand and start the monitors again, unless you want the board to stay at 2.0 GHz. The commands are below.

How to set and revert the governor

On this Exynos 5422, cpu0 is the A7 cluster governor and cpu4 is the A15 cluster governor. The bash brace in cpu{0,4} writes the same value to both. Check first with:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq

To lock performance (A15 2.0 GHz, A7 1.4 GHz) and stop the monitors:

echo performance | sudo tee /sys/devices/system/cpu/cpu{0,4}/cpufreq/scaling_governor
sudo systemctl stop grafana-server prometheus prometheus-node-exporter

To go back to ondemand (the usual day-to-day setting) and start the monitors again:

echo ondemand | sudo tee /sys/devices/system/cpu/cpu{0,4}/cpufreq/scaling_governor
sudo systemctl start grafana-server prometheus prometheus-node-exporter

ondemand lets the cores drop below their maximum, which is easier on heat and power. It is also the governor used in the slower baseline above.

Caveats

How to reproduce

Files: qwen2.5-coder-0.5b-instruct-q4_0.gguf (403.20 MiB in these runs) and, for the comparison, qwen2.5-coder-0.5b-instruct-q8_0.gguf (638.74 MiB) from Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF. Binary: llama-bench from llama.cpp build 925e11799 (10642). Work from the directory that holds the binary and the GGUF files, or pass full paths to -m.

# baseline (ondemand, monitors running)
taskset -c 4-7 ./llama-bench -m qwen2.5-coder-0.5b-instruct-q4_0.gguf \
  -p 128 -n 128 -fa 1 -t 4 -r 2

# lock clocks and stop monitors
echo performance | sudo tee /sys/devices/system/cpu/cpu{0,4}/cpufreq/scaling_governor
sudo systemctl stop grafana-server prometheus prometheus-node-exporter

# thread sweep, Q4_0
for t in 2 3 4; do
  taskset -c 4-7 ./llama-bench -m qwen2.5-coder-0.5b-instruct-q4_0.gguf \
    -p 128 -n 128 -fa 1 -t "$t" -r 3
done

# Q4_0 vs Q8_0 at four threads
taskset -c 4-7 ./llama-bench -m qwen2.5-coder-0.5b-instruct-q4_0.gguf \
  -p 128 -n 128 -fa 1 -t 4 -r 3
taskset -c 4-7 ./llama-bench -m qwen2.5-coder-0.5b-instruct-q8_0.gguf \
  -p 128 -n 128 -fa 1 -t 4 -r 3

# go back to ondemand and restart the monitors
echo ondemand | sudo tee /sys/devices/system/cpu/cpu{0,4}/cpufreq/scaling_governor
sudo systemctl start grafana-server prometheus prometheus-node-exporter

Related

Assembly vs C for AI: an ODROID-HC1 Experiment — seven matvec kernels on the same board. Its result, after three locked-clock runs, was that SIMD, INT8 and bandwidth explain the large speedups, and hand-written assembly over well-written NEON intrinsics mostly does not hold up. The llama.cpp numbers here point the same way: the win came from clocks, background load, and a smaller quant, not from a new assembly inner loop.