Oussama Essamadi

Publications

Running language models on your own machine

Why I run language models locally, what actually fits on an ordinary machine, and where they still fall short of the hosted ones.

Publié

Temps de lecture

4 minutes

Article

Running a language model at home used to mean a serious GPU and a whole afternoon of setup, now it’s one command and a few gigabytes of disk. The models got smaller, the tools got simpler, and for a lot of what I do, I don’t need to send anything to someone else’s server anymore.

Why bother

Three reasons, in order of how much they matter to me:

  • Privacy, notes, code and documents stay on my machine, and for anything personal or under an NDA, that settles it.
  • Cost, after the hardware, every call is free, batch jobs that would cost real money through an API just cost electricity.
  • It works offline, on a train, on a bad connection, during an outage, you name it.

What fits

The rule of thumb is pretty simple, a model’s weights take roughly its number of parameters times the bits per parameter:

memory in bytes≈parameters×bits per parameter8\text{memory in bytes} \approx \text{parameters} \times \frac{\text{bits per parameter}}{8}
The weights alone, by the model's size
GBbillions of parameters
  • 16 bits
  • 8 bits
  • 4 bits
The numbers
Seriesbillions of parametersGB
16 bits12
16 bits36
16 bits816
16 bits1428
16 bits3264
16 bits70140
8 bits11
8 bits33
8 bits88
8 bits1414
8 bits3232
8 bits7070
4 bits10.5
4 bits31.5
4 bits84
4 bits147
4 bits3216
4 bits7035

Quantized to 4 bits (which costs surprisingly little quality), an 8-billion-parameter model needs around 5 GB of memory once you count the overhead, and a 3B model needs about half that.

Part of that overhead is the quantization’s own bookkeeping (a scale for every small block of weights), but part of it grows as you talk, the KV cache. For every token in the conversation, the model keeps a key and a value in every layer, so it doesn’t have to read everything again for each new word. For Llama 3.1 8B, with its 32 layers and 8 key-value heads of 128 numbers each, at 16 bits:

KV cache per token=2×32×8×128×2 bytes=131,072 bytes\text{KV cache per token} = 2 \times 32 \times 8 \times 128 \times 2 \text{ bytes} = 131{,}072 \text{ bytes}

That’s about 131 KB a token, nothing for a short chat, but at the 128K tokens Llama 3.1 can take in (a K of tokens is 1,024 of them), it’s over four times the weights:

An 8B model's memory, as the conversation grows
GBK tokens in the context
  • weights, at 4 bits
  • KV cache, at 16 bits
The numbers
SeriesK tokens in the contextGB
weights, at 4 bits04
weights, at 4 bits84
weights, at 4 bits164
weights, at 4 bits324
weights, at 4 bits644
weights, at 4 bits1284
KV cache, at 16 bits00
KV cache, at 16 bits81.07
KV cache, at 16 bits162.15
KV cache, at 16 bits324.29
KV cache, at 16 bits648.59
KV cache, at 16 bits12817.18

So on an ordinary laptop, the sweet spot right now is somewhere between 1B and 8B parameters, Llama 3.1 8B, the new Llama 3.2 1B and 3B, Qwen 2.5, Gemma 2. Anything bigger wants a real GPU, or a Mac with a lot of unified memory.

My own machine isn’t a laptop though, it’s a desktop with an i9-9900KF, 64 GB of DDR4 and an RTX 2080 Ti. The 2080 Ti has 11 GB of VRAM, so an 8B model at 4 bits fits entirely on the GPU with room to spare, and anything that doesn’t fit gets split between the GPU and the system RAM, which works (64 GB helps a lot there), just a lot slower.

The tools

llama.cpp does the heavy lifting, it runs quantized models on pretty much any CPU or GPU, and Ollama wraps it in something friendlier, ollama run downloads a model and drops you in a chat, and it also exposes a local API that speaks the same format as OpenAI’s. Now that last part matters more than it sounds, because code written against a hosted API can switch to a local model by changing a URL, that’s it.

Where they fall short

Small local models are not just small versions of the big hosted ones, they know less, they lose the thread in long contexts, and they’re worse at reasoning over several steps. Ask an 8B model a question that needs real knowledge, and it’ll answer just as confidently as GPT-4 would, only wrong a lot more often.

Where they shine though is narrow tasks where you hand them the context, summarize this, classify that, rewrite this paragraph, pull the dates out of this email. Give a small model the right text and a clear, small job, and it does just fine.

And that’s pretty much what I use them for day to day, sorting my emails, looking things up in a pile of unstructured files, autocompletion, that kind of stuff, small jobs I do a lot, where I’d rather not send anything out and where waiting on an API would just get in the way.

And that’s the pattern I keep seeing, the less a task depends on what the model knows, and the more on what you give it, the smaller the model can be.

Suivant

ouLes 21 publicationsouAu hasardouAccueil

ProjetsPublications

Chargement de la liste…

Chargement de la liste…

Raccourcis clavier

Recherche et commandes
Ctrl K⌘K
Passer du clair au sombre
T
Tous les projets
P
Toutes les publications
W
Chercher dans la liste ouverte
S
Accueil
H
M’écrire
C
Afficher ces raccourcis
?
Fermer ce qui est ouvert
esc

Les raccourcis sont activés.