AINexus
Tutorial2 min read16d ago·2 comments·966 views

Hands-on · step by step

Tutorial: quantise a model without wrecking its reasoning

by @marcus — Open-source maintainer · local inference

Four steps to local inference on consumer GPUs with llama.cpp and GGUF — checkpoints, tuning knobs and the failure to guard first.

Before you start — about 45 minutes · llama.cpp · GGUF · Ollama

Short version: one code path, explicit limits, a command that proves it works. Here is local inference on consumer GPUs, end to end.

Step 1 — Decide what "working" means

Before touching code, write down three numbers: worst acceptable latency, cost per request, and what should happen when the upstream is unavailable. Everything after this is implementation.

Step 2 — Wire llama.cpp

The whole flow is one path. No special branches for "large" inputs — express those as different limits, not different code.

# produce a 4-bit quantisation, then measure before you ship it
python convert_hf_to_gguf.py ./model --outfile model-f16.gguf
./llama-quantize model-f16.gguf model-Q4_K_M.gguf Q4_K_M
./llama-bench -m model-Q4_K_M.gguf -p 512 -n 128

Why this works

The limit is enforced before the expensive call, not after it. Reserving budget up front means a burst degrades the caller that caused it instead of everyone downstream.

Step 3 — Guard the failure path

quantising the wrong tensors hurts more than dropping a bit width

Write that guard before you write the feature. It costs an hour and saves a postmortem.

Step 4 — Verify it

./llama-cli -m model-Q4_K_M.gguf -p "summarise: ..." -n 128 --temp 0
  • Lower the limit and confirm the command fails loudly
  • Kill the upstream and confirm you get a typed error, not a timeout
  • Check the metric you emit per outcome: ok, throttled, upstream_error

Tuning knobs

KnobDefaultWhat we runWhy
concurrency824Most of the wait is network, not compute
retry budgetinfinite2, with jitterUnbounded retries turn an outage into an avalanche
timeout30s8s, inherited from the callerNobody waits 30s for a chat reply

That is it. No framework required.

Comments (2)

Log in to join the discussion.

@aiko·2h ago

Curious how this holds up at 10x volume — did the queue depth signal stay stable?

@samuel·2h ago

This matches what we saw, especially the part about defaults nobody questioned.