Run LLMs on Your Own Computer
Why and when to run an open-weight model locally, how much memory it needs and why, what quantisation and GGUF files are, the main tools (Ollama, LM Studio, llama.cpp), and calling a local model from Python.
Why run a model locally?
An open-weight model is one whose trained weights you can download, such as Llama, Qwen, Gemma or Mistral. Running one on your own computer has real advantages:
- Privacy: nothing you type leaves your machine, which matters for health, legal or company data.
- Cost: no charge per token, so it suits big batch jobs such as labelling 50,000 documents.
- Offline and under your control: it works without internet, and the model never changes under you.
The trade-offs: local models that fit on ordinary hardware are smaller and weaker than the best hosted models at hard reasoning and long tasks, and you are responsible for the hardware and setup. A common pattern is a small local model for simple, private or high-volume steps, and a hosted model for the hard ones.
How much memory does a model need?
Almost everything comes down to memory, usually the VRAM on a graphics card, or the unified memory on an Apple Silicon Mac. A model needs room for three things:
- Weights: parameters × bits per weight ÷ 8. An 8-billion-parameter model at 16 bits is 8 × 16 ÷ 8 = 16 GB.
- KV cache: the keys and values for every token in the conversation (see transformers): 2 × layers × KV heads × head size × tokens × bytes. For Llama 3.1 8B at 8,192 tokens it is about 1 GB, and it grows in a straight line with the context length.
- Runtime: the program and its working buffers, roughly 0.5–1 GB.
Speed when writing is limited mainly by memory bandwidth: to produce each token, the whole model has to be read from memory once. So tokens per second ≈ bandwidth ÷ model size. A graphics card with 900 GB/s writes far faster than a laptop CPU with 60 GB/s, even when both can hold the model.
Try your own hardware in the LLM VRAM calculator.
Try it: what fits in memory?
Change the model size, the bits per weight and the context length, and compare with common memory sizes.
Interactive: this part runs in your browser.
Quantisation and GGUF files
Quantisation stores each weight with fewer bits. Weights are trained in 16 bits, but rounding them to 8 or about 4 bits loses surprisingly little quality, while cutting memory by two to four times and making the model faster.
| Level | Bits per weight (about) | 8B model | Quality |
|---|---|---|---|
| FP16 / BF16 | 16 | 16 GB | the original |
| Q8_0 | 8.5 | 8.5 GB | practically identical |
| Q5_K_M | 5.7 | 5.7 GB | very close |
| Q4_K_M | 4.85 | 4.9 GB | the usual sweet spot: a small drop |
| Q3_K_M, Q2_K | 3–4 | 3–4 GB | noticeably worse; a last resort |
These names come from GGUF, the file format used by llama.cpp and the tools built on it. "K" quantisations store weights in small blocks, each with its own scale, and give some sensitive layers more bits, which is why the bits per weight are a little above the number in the name.
A rule of thumb: a bigger model at Q4 usually beats a smaller model at Q8 of the same file size. Below Q4, quality falls off faster.
The main tools
| Tool | Best for | Getting started |
|---|---|---|
| Ollama | the quickest start from the terminal, and a local API for your code | install from ollama.com, then ollama run qwen3:8b |
| LM Studio | a desktop app: search, download and chat, with a hint about what fits your machine | install, search for a model, click download |
| llama.cpp | full control: the engine many other tools use underneath | llama-server -m model.gguf -c 8192 |
| vLLM | serving many users at once on a server GPU | a Python package for Linux servers |
Ollama and LM Studio also start a local server with an OpenAI-compatible API, so code written for a hosted API can use a local model by changing the address.
Choosing a model
- Start small: try a 3B–8B model first. For summarising, extracting fields, classifying and simple chat, it is often enough.
- Match the task: use an instruction-tuned ("instruct" or chat) version, a coder model for code, and an embedding model for search (see embeddings).
- Check the licence: open-weight does not always mean free for any use. Read the model card for commercial limits.
- Test on your own examples: public leaderboards are a starting point, but a small test set of your real inputs (see evaluation) is what tells you if it is good enough.
Code: call a local model from Python
With Ollama running and a model pulled (ollama pull qwen3:8b), the ollama package talks to it. The second example uses the openai package against Ollama's OpenAI-compatible endpoint, so the same code could later point at a hosted model.
# pip install ollama (Ollama must be running: it listens on http://localhost:11434)
import ollama
reply = ollama.chat(
model="qwen3:8b",
messages=[
{"role": "system", "content": "You summarise clinic notes in one plain-English sentence."},
{"role": "user", "content": "Pt c/o 3/7 productive cough, afebrile, chest clear. Advised fluids, review if worse."},
],
options={"temperature": 0.2, "num_ctx": 8192}, # low temperature for steady output; context length in tokens
)
print(reply["message"]["content"])# pip install openai the same client works with Ollama, LM Studio and llama-server
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama") # local servers ignore the key
resp = client.chat.completions.create(
model="qwen3:8b",
messages=[{"role": "user", "content": "Give three tips for a good night's sleep, one line each."}],
temperature=0.3,
)
print(resp.choices[0].message.content)Quiz
1. Roughly how much memory do the weights of a 14-billion-parameter model need at 8 bits per weight?
2. You double the context length. What happens to the KV cache?
3. What mostly limits how fast a local model writes each token?
4. Your files are the same size: a 14B model at Q4_K_M or a 7B model at Q8_0. Which is usually better?
📚 Further reading
Trusted, mostly free sources: official documentation, well-known textbooks and courses. When you want to confirm or go deeper on anything here, start with these.
- Ollama ↗ run open-weight LLMs on your own computer
- llama.cpp ↗ the engine behind GGUF files and many local LLM tools
- LM Studio ↗ a desktop app for downloading and running local models