Self-Hosted-AI

Self-Hosting AI Locally: A Walkthrough That Assumes Nothing

You can be a competent Linux user and still lose a weekend to this. Here is the sequence that works, in the order that avoids re-doing work, with the numbers that decide whether a model runs or swaps itself to death.

Pick the Box Before the Model

Everyone starts by choosing a model and then discovers their hardware cannot hold it. Reverse that. Decide what the machine is for — summarising documents, drafting text, answering questions over a folder of PDFs — and let that choose the memory budget. A 3B model handles classification and short rewriting. An 8B model is the practical floor for anything conversational. A 14B model is where instruction following feels reliable, and it wants about 10 GB for the weights at four bits. Then add room for the cache, the runtime and the operating system.

Operating System and Drivers

Install a minimal 64-bit Linux with a current kernel; Debian or Ubuntu server images are the safe choice because every guide assumes them. Skip the desktop environment unless the machine is also your workstation. The accelerator driver eats an evening: install the vendor driver from your distribution repository rather than the vendor's own installer, and verify it with a trivial compute test before building on top.

If the electricity meter matters more than peak speed, there is a useful comparison point in a low-wattage alternative — a device drawing 15 watts instead of 250 does less work per second, and is the difference between something you leave switched on and something you unplug.

Install the Runtime

The two sane choices are llama.cpp directly, or a wrapper around it. Running llama.cpp yourself means moving a quantised model into place and starting a server with an explicit context size: total control, a clear mental model, and you own every rebuild. The wrapper route reaches a working result faster: Ollama installs with one command, pulls models by name, keeps them in a content-addressed store, and exposes an HTTP API most existing tools already speak.

Whichever you choose, verify with a real prompt before building on top. Ask the model to summarise three paragraphs and count the seconds. That single measurement tells you whether the machine is usable for your workload, and no product page will give you that number.

Quantisation, in Plain Numbers

Quantisation is how you fit a model into memory. Full-precision weights are two bytes each; four-bit quantisation is roughly half a byte with overhead, so an 8B model drops from about 16 GB to about 5 GB. The cost is a small loss of reasoning quality that, at Q4_K_M and above, most people cannot detect in everyday use.

Q8_0
Nearly lossless, about one byte per weight. Only if memory is not a constraint.
Q5_K_M
Around 0.66 bytes per weight, quality very close to the original. The choice if you have headroom.
Q4_K_M
About 0.5 bytes per weight. The default for most people, with a good balance of size and coherence.
Q3 and below
Only for machines that cannot do better; models start repeating themselves.

The practical rule: pick the largest quantisation that still leaves two to three gigabytes free after loading. That headroom is what keeps a persistent self-hosted service responsive when several requests arrive at once, instead of the whole box stalling while the kernel hunts for pages.

Context Is Not Free

A model's advertised context window is a maximum, not a default, and it is paid for from the same memory pool. The key-value cache grows with every token, so a 32k context can add several gigabytes on top of the weights. On an 8 GB machine, an 8B model at 8k context is comfortable; at 32k it is not, and the failure mode is not an error but a device that becomes unusably slow. Set the context deliberately and be suspicious of any tool that silently requests the maximum.

Run It as a Service, Not a Terminal Command

A model server started by hand dies when you close the terminal, which is fine for a first test and useless for anything else. Write a systemd unit with a restart policy and the exact arguments you tested. If you run several components — model server, chat interface, document store — describe them in one Docker Compose file, so a rebuild after a disk failure is one command. Pin your image tags: moving tags are convenient until the day they move and your working setup stops booting.

Put a Proxy in Front of It

The model server should never be the thing exposed to your network. Run nginx in front of it, terminate TLS there, and add authentication at minimum. If the box is reachable from the internet, that is the difference between a personal tool and an open relay somebody will find. Better: keep it on the LAN and reach it over a VPN.

If you would rather not administer any of that, a sealed device that handles its own updates and networking is an offline AI appliance by design: less to configure, less to break, less to learn.

Backups and the Minimum Monitoring

Do not back up model weights; they are large and re-downloadable. Do back up your configuration, prompts, document store and compose files, and test a restore once, early, before you have anything worth losing. Most self-hosted AI disasters are a corrupted database with no copy.

For monitoring, three things are enough: free memory, disk usage and service uptime. Watch memory because the failure mode is a slow death rather than an error; disk because model files quietly fill a volume; uptime because a chat interface that dies silently at three in the morning is worse than one that never started. Add one log line per request with token count and duration.

What I Would Do Differently

I would buy the larger memory option and stop agonising over the faster chip: memory decides which models run at all, clock speed only decides how long you wait. I would write the systemd units on the first evening instead of the third. And I would fix the context size before benchmarking anything, because a context that is too large makes good hardware look broken.

If privacy is what brought you here, the companion piece on private self-hosted AI is the one to read next.