GuideLocal AI

CPU-only inference with llama.cpp, from a bare VPS

A practical guide. Every command below was run on the system described in the prerequisites, and the date it was last checked is in the line above.

A working local model on a server with no GPU, in five commands — the prebuilt binary, the quantised file, the server flags that matter, and how to measure what you actually got.

You do not need a GPU to run a language model, and you do not need to compile anything. What you need is a small model, a quantised file, a prebuilt binary, and a realistic idea of the speed you will get.

These are the steps that produced the measurements in the CPU inference lab, in the order they were run on a 4-core VPS.

What you need

  • A Linux x86-64 machine with at least 2 GB of free RAM for a 0.5B model.
  • ~600 MB of disk for the binary and the model.
  • No GPU, no CUDA, no Python bindings, no build toolchain.

If you have 8 GB of RAM and a 7B model in mind, stop and do the arithmetic first: a 7B at Q4 is about 4.4 GB of weights, plus KV cache, plus your other services. On a small VPS that does not fit.

1. Get a prebuilt llama.cpp

Releases are published per commit. Take the plain ubuntu-x64 build — the CUDA, ROCm and Vulkan variants are for hardware you do not have.

VER=b12994
curl -L -o /tmp/llama.tar.gz \
  https://github.com/ggml-org/llama.cpp/releases/download/$VER/llama-$VER-bin-ubuntu-x64.tar.gz
sudo mkdir -p /opt/llama
sudo tar xzf /tmp/llama.tar.gz -C /opt/llama

The binaries land at the root of the extracted directory, not in a `bin/` subdirectory. The archive contains llama-server, llama-cli, llama-bench and the shared libraries side by side. Calling /opt/llama/bin/llama-server fails with "No such file or directory" and reads like a broken download.

/opt/llama/llama-server --version

If the loader complains about a missing libggml-*.so, you extracted only some files, or you are running the binary from somewhere it cannot see its own libraries.

2. Get a quantised model

A GGUF file is the whole model in one file. Q4_K_M is the usual starting point: a quarter of the size of FP16 with most of the quality on most tasks.

mkdir -p /srv/models && cd /srv/models
curl -L -o qwen2.5-0.5b-instruct-q4_k_m.gguf \
  https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf
ls -l qwen2.5-0.5b-instruct-q4_k_m.gguf    # expect 491,453,280 bytes

Check the size against the published file, not against "it finished". A truncated GGUF loads far enough to allocate memory and then fails, or worse, produces garbage. If a download stalls, resume it rather than restarting: curl -C - -o <same-name> <url>.

3. Run the server

/opt/llama/llama-server \
  -m /srv/models/qwen2.5-0.5b-instruct-q4_k_m.gguf \
  -c 2048 -t 3 -b 512 -ub 512 \
  --host 127.0.0.1 --port 8081 --no-webui

The flags that matter:

  • `-c 2048` — context window. This is the KV cache size; raising it costs memory linearly.
  • `-t 3` — threads. On a 4-vCPU box, three is the sweet spot: the fourth added 0% in our measurements and takes a core from the web server.
  • `-b 512 -ub 512` — prompt batch and micro-batch. Smaller values use less peak memory during prompt processing.
  • `--host 127.0.0.1` — do not expose the model to the internet. It has no authentication.

/health returns 200 when the model is loaded. On this machine a 0.5B Q4 model loads in 1.6 seconds from page cache.

4. Call it

The server speaks the OpenAI chat-completions shape, so any client that can point at a base URL works:

curl -s http://127.0.0.1:8081/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"local","messages":[{"role":"user","content":"Name three uses for a local model."}],"max_tokens":128,"temperature":0}'

The response carries a timings object with prompt_ms, predicted_ms and predicted_per_second. Treat those as the server's own claim: measure wall time yourself if you are going to publish a number.

5. Measure what you got

Three numbers decide whether this is useful for your workload:

  • Tokens per second — total tokens divided by wall time, not the server's estimate.
  • Time to first token — send the same request with "stream": true and time the first content chunk. This is what a user perceives as latency.
  • Peak resident memory — read VmHWM from /proc/<pid>/status, or sample it while the request runs. The model file is not the answer; on our run it was 491 MB on disk and 605 MB resident.

Our measurements on this box: 17.8 tokens/s, 78–190 ms to first token, 605 MB peak for Qwen2.5 0.5B Q4_K_M at three threads.

What breaks, and why

The model is slower than you expect on a shared vCPU. One thread gave 9.1 tokens/s, two gave 14.1, three 17.8, four 17.6. If your numbers plateau early, the hypervisor's CPU allocation is the limit, not the model.

A 4-bit file is not 4 bits per parameter. Our 0.5B Q4_K_M file is 6.2 bits per parameter, because the token embedding and output layers are stored at higher precision. On small models that difference is most of the file.

Long prompts hurt more than long answers. Prompt processing is a big matrix multiply and it is fast; but every token generated has to attend to the whole context, so a 4,000-token prompt makes each subsequent token slower. Keep the context as small as the task allows.

A local model is not an API. There is no rate limit, no retry, no versioning and no safety layer. Everything the provider did for you — queues, timeouts, concurrency limits — you now own. Run it under systemd with MemoryMax, and put a timeout on the client.

Limitations

  • Tested with one model family and one runtime. A different quantisation recipe can change both speed and quality substantially.
  • Three requests per configuration. The between-request spread was up to 30% on this shared vCPU, so small differences are not measurable with this method.
  • Quality was not evaluated. Speed tells you nothing about whether the output is good enough for your task — test that separately, with your own examples.

Sources

Related

Keep reading

All guides →
PreviousWhat a 4-core VPS can actually do with a local model

Comments

0 comments

Sign in to join the discussion, or create an account.

No comments yet

Be the first to say something useful.