AI & LLM hosting

How to run an LLM locally: hardware, tools and your first model

Running a model on your own hardware keeps your data private and costs nothing per token. The catch is memory. This guide shows how to work out what your machine can run, then gets a model answering within minutes.

Illustration: a laptop and a compact desktop computer on a dark desk with a soft green glow rising from the laptop

To run an LLM locally you need three things: a model file, a program that runs it, and enough memory to hold the model. The quickest route for most people is Ollama: install it, type ollama run llama3.2, and a small model starts answering in your terminal a few minutes later. On a laptop with 8 GB of RAM that works. With a 12 to 24 GB graphics card or an Apple Silicon Mac with 16 GB or more, you can run models that are useful for writing, coding and summarising.

The rest of this guide covers what decides which models fit, why some machines are fast and others slow, and how to set things up properly.

Why run a model locally?

  • Privacy. Prompts and documents never leave your machine, which matters for client data, health records or source code.
  • No per-token bill. Once you own the hardware, heavy use adds only electricity.
  • Works offline, and nobody can change or withdraw the model you rely on.
  • Control. You choose the model, the context length and the system prompt, and you can connect it to your own tools.

The trade-off is quality and speed. The open models that fit on consumer hardware are good, but the largest hosted models are still stronger at hard reasoning. If you only need occasional answers, an API is often cheaper than new hardware; the API vs GPU cost tool shows where the break-even point is for your usage.

Memory decides which models you can run

A model's size is given in parameters: 3B, 8B, 14B, 70B (billions). Each parameter is stored as a number, and how many bits each number uses depends on quantization:

  • 16-bit (FP16 or BF16): the original precision. 2 bytes per parameter.
  • 8-bit (Q8): about 1 byte per parameter, with almost no loss in quality.
  • 4-bit (Q4, for example Q4_K_M): around 0.6 bytes per parameter. This is the usual choice for local use: much smaller, with a modest quality loss.

So the rule of thumb is memory ≈ parameters × bytes per parameter, plus room for the context. An 8B model is about 16 GB at 16-bit, about 8.5 GB at 8-bit and about 5 GB at 4-bit.

A model shaped block sitting on a memory module, just fitting within its length
A model has to fit in memory, with room left over for the context, before speed matters at all.
Model size 4-bit weights (approx.) Comfortable on
1B–4B 1–3 GB Any recent laptop, 8 GB RAM
7B–8B 4.5–5.5 GB 8 GB GPU, or 16 GB RAM / unified memory
12B–14B 7–9 GB 12 GB GPU, or 16–24 GB unified memory
24B–32B 14–20 GB 24 GB GPU, or 32 GB unified memory
70B 40–43 GB 48 GB of GPU memory (often two cards), or a 64 GB Mac (tight: keep the context short)

These are approximate. File sizes differ between quantization formats, and the table leaves headroom for the context cache described next. For a specific model and context length, the model hardware calculator does the arithmetic, and What can my computer run? starts from your hardware instead.

Context length uses memory too

While a model works through a conversation it keeps a KV cache: stored results for every token in the context window. The cache grows with the context length you set.

For Llama 3.1 8B, the cache takes about 128 KB per token at 16-bit precision. That is roughly 1 GB for an 8,000-token context, 4 GB for 32,000 tokens and 16 GB for the model's full 128,000 tokens. The cache can be bigger than the model itself.

If a model fits but crashes or slows to a crawl when you paste in a long document, the context is the reason. Use the context you actually need. Runtimes can also store the cache at 8-bit to halve it.

Speed: memory bandwidth matters more than processing power

To produce each new token, a dense model reads essentially all of its weights from memory. So the upper limit on generation speed is roughly:

tokens per second ≈ memory bandwidth ÷ model size

A wide glowing pipe carrying a stream of particles from a memory module to a processor
Every new token means reading the whole model from memory again, so the width of that pipe sets the speed.

That explains why the same model runs at very different speeds:

  • A desktop with dual-channel DDR5-5600 memory has about 90 GB/s of bandwidth. A 5 GB model therefore tops out below 18 tokens per second on the CPU, and real speeds are lower.
  • An RTX 4060 graphics card has 272 GB/s; an RTX 3090 936 GB/s; an RTX 4090 about 1,000 GB/s. The same 5 GB model is several times faster on these.
  • Apple Silicon shares one pool of memory between CPU and GPU. Bandwidth ranges from about 120 GB/s on a base M4 to over 500 GB/s on the top M4 Max, which is why Macs with a lot of memory are popular for larger models.

For chat, around 10 tokens per second is already faster than most people read; below about 5 it starts to feel slow. Processing your prompt (prefill) is faster than generating and depends more on raw compute.

Mixture-of-experts (MoE) models change the arithmetic. A model such as Qwen3-30B-A3B has 30B parameters in total but uses only about 3B for each token. It still needs memory for all 30B, but it generates at roughly the speed of a 3B model.

If the model does not fit entirely in GPU memory, runtimes can keep part of it in system RAM. It still works, but speed drops towards the CPU figure.

Choose a tool

  • Ollama (Windows, macOS, Linux). A command-line tool and background service with a built-in model library. It downloads models, picks a GPU automatically and offers a local API. The easiest start, and simple to put on a server.
  • LM Studio (Windows, macOS, Linux). A desktop app with a model browser and chat window, for people who prefer not to use a terminal. It can also run a local API server.
  • llama.cpp. The engine underneath many local tools. Running it directly gives you the most control over GPU offload, context size and quantization, and its llama-server provides a web interface and an OpenAI-compatible API.

For a ChatGPT-style interface on top of Ollama or llama.cpp, many people add Open WebUI, which runs in Docker.

Most local tools use GGUF model files, the format created for llama.cpp. Hugging Face hosts GGUF versions of most open models in several quantization levels.

Set up Ollama and run your first model

Install. On Windows and macOS, download the installer from ollama.com. On Linux:

curl -fsSL https://ollama.com/install.sh | sh

On Linux the script installs Ollama as a systemd service.

Run a model. Start with a small one to check that everything works:

ollama run llama3.2

The first run downloads the model (about 2 GB), then opens a chat prompt. Type /bye to leave. Then try a model that matches your memory, for example ollama run qwen3:8b for 8 to 16 GB, or gemma3:12b with 12 GB of GPU memory or more. Model names and sizes are listed in the Ollama library.

Useful commands:

ollama list          # models you have downloaded
ollama ps            # models loaded now, and whether they run on GPU or CPU
ollama pull qwen3:8b # download without starting a chat
ollama rm qwen3:8b   # delete a model to free disk space

ollama ps is the quickest way to see whether a model actually fits on your GPU. If it shows a CPU/GPU split, choose a smaller model or a shorter context.

Set the context length. Ollama uses a default context window that can be shorter than the model supports. Inside a chat, /set parameter num_ctx 16384 changes it for that session; the OLLAMA_CONTEXT_LENGTH environment variable sets the default for the service. On Linux the service does not read your shell's variables: run sudo systemctl edit ollama, add Environment="OLLAMA_CONTEXT_LENGTH=16384" under [Service], then sudo systemctl restart ollama. OLLAMA_HOST is set the same way.

Use it from your own code. Ollama listens on http://localhost:11434:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Explain DNS in two sentences.",
  "stream": false
}'

It also offers an OpenAI-compatible endpoint at http://localhost:11434/v1, so many existing apps and libraries work once you change the base URL.

Or run llama.cpp directly

If you want full control, build llama.cpp or download a release, then start the server with a GGUF file:

llama-server -m ./models/model-Q4_K_M.gguf -c 8192 -ngl 99 --port 8080

-c sets the context length and -ngl 99 offloads as many layers as possible to the GPU (lower it if you run out of GPU memory). Open http://localhost:8080 for the built-in chat page, or point an OpenAI client at http://localhost:8080/v1.

Running it on a server instead

The same tools run on a VPS or a rented GPU server, which is useful when your own machine is too small or you want the model available to a team.

  • CPU-only VPS. Workable for small models (1B to 8B at 4-bit) and light use. Choose memory first: an 8B model at 4-bit needs about 8 GB of RAM to run comfortably. Generation will be slow, limited by the server's memory bandwidth, so test with your own prompts before committing.
  • GPU server. Rented by the hour, often cheaper than buying a card if you only need it for a project. Our GPU price pages compare hourly rates by card and provider.

Keep the API private. By default Ollama listens only on 127.0.0.1. Setting OLLAMA_HOST=0.0.0.0 exposes it to the network, and the API has no login of its own. On a server, keep it on localhost and put an authenticated reverse proxy or a VPN in front. Our guide to setting up an Nginx reverse proxy covers the proxy part.

Common problems

  • "Out of memory" or a very slow first answer. The model plus context does not fit. Use a smaller model, a lower quantization or a shorter context.
  • It runs on the CPU although you have a GPU. Update the GPU driver, then check ollama ps. On Linux with NVIDIA, make sure the driver is installed and nvidia-smi works before installing Ollama.
  • Answers get cut off or the model forgets earlier messages. The context window is too small for the conversation; raise num_ctx.
  • The disk fills up. Each model is several GB. Remove ones you no longer use with ollama rm.

Where to start

  1. Check your memory: RAM and GPU memory on Windows or Linux, unified memory on a Mac.
  2. Pick the largest model from the table that fits with a few GB to spare.
  3. Install Ollama and run it. Use ollama ps to confirm it is on the GPU.
  4. Set a context length that suits your documents, and see whether the speed is acceptable.

If you want a second opinion on your hardware, enter it into What can my computer run? and the tool lists the models that fit.

Sources