Availit World How AI really works, in your language

Lesson 29 of 4622 minFacts checked October 20, 2026

Run AI on your own computer

You do not need a data centre to use a good model. A phone can run a small model with no internet at all, a gaming PC can run a 120-billion-parameter model, and nothing you type has to leave the machine. This lesson shows how to tell whether a model will fit and how fast it will be, which program to run it with, why mixture-of-experts models are a gift to home users, and how to plug a local model into your own apps.

In this lesson you will

  • Work out whether a model fits your device, and roughly how fast it will run
  • Choose between llama.cpp, Ollama, LM Studio and MLX
  • Split a model between a graphics card and system memory without wasting speed
  • Pick a model and quantization for a phone, a laptop or a desktop
  • Run a local model as a private server for your own programs
On this page
  1. Why run it yourself?
  2. Will it fit? Will it be fast?
  3. The programs
  4. Your first local model
  5. When it does not fit: splitting the model
  6. Choosing a model
  7. Use it from your own programs
  8. Remember
  9. Check yourself

Why run it yourself?

  • Privacy. Your words, files and photos never leave the device.
  • Offline. It works on a plane, in a village with weak signal, or when a service is down.
  • Cost. Once you own the hardware, there is no bill per token.
  • Control. The model never changes under you, there are no rate limits, and every setting in this course is yours to change.
  • Learning. You can watch prefill, decode, the KV cache and quantization happen on your own machine.

Will it fit? Will it be fast?

Two rules of thumb
memory ≈ parameters × bits ÷ 8 + KV cache + about 1 GB

The weights, the cache for your context, and working space.

Qwen3.8-27B at Q4_K_M: 27.78 billion × 4.89 ÷ 8 ≈ 17.0 GB

Before the KV cache. Q4_K_M averages 4.89 bits per weight.

tokens per second ≤ memory speed ÷ bytes read per token

A dense model reads every weight for each token: 17.0 GB at the RTX 4090’s 1,008 GB/s gives at most about 59 tokens per second.

Memory speed decides the speed
MemoryMemory speed
Ordinary PC, DDR5, two channels16–128 GBabout 90 GB/s
Apple M5Up to 32 GB153 GB/s
Apple M5 ProUp to 64 GB307 GB/s
Apple M5 MaxUp to 128 GB460 or 614 GB/s
Apple M5 Ultra (Mac Studio)Up to 512 GB1,200 GB/s
NVIDIA RTX 306012 GB360 GB/s
NVIDIA RTX 409024 GB1,008 GB/s
NVIDIA RTX 509032 GB1,792 GB/s

Apple’s figures are from its spec pages. DDR5-5600 with two channels moves 2 × 8 bytes × 5,600 million transfers per second, about 90 GB/s. On a PC, the graphics card’s own memory is many times faster than system memory.

Try itDoes it fit on yours?

Pick “Laptop with 16 GB” and Llama 3.1 8B at Q4_K_M: it fits with room to spare. Try Qwen3.8-27B: it does not. Now pick the RTX 4090 and gpt-oss-20b at MXFP4. Only 3.6 billion of its weights work on each token, so its speed limit is several times that of the dense 27B. Then raise the context to 131,072 tokens and watch the KV cache grow.

This interactive part needs JavaScript.

Quick check

A dense model file is 8 GB. Your laptop’s memory runs at 90 GB/s. What is the most you can expect?

Show the answer

Answer: About 11 tokens per second Every weight is read for each token: 90 ÷ 8 ≈ 11. Real speed will be a little lower.

The programs

Ways to run a model at home
What it isGood for
llama.cppThe C/C++ engine that many local apps build on. Reads GGUF files; runs on CPUs and on NVIDIA, AMD, Apple and other GPUsFull control, a local server, the newest models first
OllamaA small background service with one-command downloads and an API on port 11434Getting started; apps that expect a local API
LM StudioA desktop app with a chat window and a model browser. Runs llama.cpp, and Apple’s MLX on MacsPeople who would rather not use the command line
MLX (mlx-lm)Apple’s own framework for Apple siliconFast models, and fine-tuning, on a Mac
vLLM, SGLangThe serving engines from the last lessonOne strong GPU answering many requests
Phone appsGoogle AI Edge Gallery (Android and iPhone) runs Gemma 4 and other models offline; PocketPal AI runs GGUF filesTrying AI with no internet at all

Apps on Apple devices can also use Apple’s own on-device model, about 3 billion parameters, through its Foundation Models framework. Apple’s 2025 tech report describes how it was squeezed to fit: 2-bit quantization-aware training and a KV cache shared between layers.

Your first local model

Three ways inbash
# Ollama: download and chat in one step
ollama run gpt-oss:20b

# What is loaded, and how much of it is on the GPU?
ollama ps

# llama.cpp: a server with a chat page at http://localhost:8080
llama-server -hf ggml-org/gpt-oss-20b-GGUF:MXFP4 --port 8080

# Apple silicon: MLX
pip install mlx-lm
mlx_lm.generate --model mlx-community/Llama-3.2-3B-Instruct-4bit --prompt "Hello"
  • Ollama picks a default context from your GPU memory: 4K tokens below 24 GiB, 32K up to 48 GiB, 256K above. Its guide says agents and coding tools need at least 64,000. If memory allows, start it with OLLAMA_CONTEXT_LENGTH=64000 ollama serve.
  • ollama ps shows 100% GPU when the model is entirely on the graphics card, or a split such as 48%/52% CPU/GPU when it is not. A split is the first thing to check when a model feels slow.
  • -hf downloads from Hugging Face; :MXFP4 picks the file. Newer llama.cpp installs from llama.app also give you a single llama command, and llama serve -hf … starts the same server.
  • mlx_lm.chat opens an interactive chat instead of a single answer.

When it does not fit: splitting the model

If a model is bigger than the graphics card’s memory, the rest can live in the computer’s own memory. That works, but each token then waits for the slow part. A card reads its memory at 360–1,792 GB/s; two channels of DDR5 manage about 90.

Qwen3.8-27B (17 GB) on a 12 GB RTX 3060
about 58 % fits on the card

After leaving room for the KV cache and working space.

0.58 × 17 GB ÷ 360 GB/s + 0.42 × 17 GB ÷ 90 GB/s ≈ 27 ms + 80 ms

The two-fifths in system memory take three-quarters of the time.

≈ 107 ms per token ≈ 9 tokens per second

Usable for chat, but far from the card’s own speed.

Mixture-of-experts models change the picture. Most of their weights are experts, and each token uses only a few of them. So keep everything else, attention, embeddings and the shared parts, on the card, and leave the experts in system memory. Each token then reads only its few experts from the slow memory. In llama.cpp, --cpu-moe keeps all the experts in system memory, and --n-cpu-moe N keeps only the first N layers’ experts there, so the rest can use spare room on the card.

Try itCard or system memory?

Start with Qwen3.8-27B on the RTX 3060: only 58 % fits, and you get about 9 tokens per second. Now pick gpt-oss-120b on the RTX 4090. With whole layers, about 26. Switch to “Everything but the experts”: about 53 with as many experts on the card as fit, and still about 41 with none. That is a 120-billion-parameter model on a gaming card, in a PC with 64 GB of memory.

This interactive part needs JavaScript.

gpt-oss-120b on one graphics cardbash
# Every expert in system memory, everything else on the card
llama-server -hf ggml-org/gpt-oss-120b-GGUF:MXFP4 --cpu-moe --port 8080

# Experts of the first 24 layers in system memory, the rest on the card
llama-server -hf ggml-org/gpt-oss-120b-GGUF:MXFP4 --n-cpu-moe 24 --port 8080
  • Recent builds try to do this for you: --fit is on by default and adjusts any settings you leave out so the model fits your memory.
  • Lower --n-cpu-moe step by step until the card is nearly full. Each layer of experts moved to the card makes every token a little faster.

Choosing a model

A starting point for each device
TryWhy
PhoneGemma 4 E2B in Google AI Edge Gallery, or a 1–4B model at Q4Small enough for phone memory and battery
Laptop with 16 GBAn 8B model at Q4_K_MAbout 5 GB of weights leaves room for a long context
Graphics card with 12–16 GBgpt-oss-20b, or a 12–14B dense model at Q4Mostly or entirely on the card
Graphics card with 24–32 GBQwen3.8-27B or Gemma 4 31B at Q4_K_MA strong dense model, entirely on the card
Any good card, plus 64 GB or more of system memorygpt-oss-120b with the experts in system memoryMixture-of-experts offloading
Mac with 128 GBgpt-oss-120b entirely in memory65 GB of weights, read at up to 614 GB/s
Mac Studio with 512 GBModels of a few hundred billion parameters at 4 bits, such as DeepSeek-V4-FlashUnified memory holds what no single graphics card can
  • Bigger and 4-bit beats smaller and 8-bit, when both fit, as the quantization lesson showed.
  • Test your own language. Small models are often much weaker outside English. Ask the same questions in your language before you trust one.
  • Read the licence. Open weights come with terms: gpt-oss uses Apache 2.0, while Gemma and Llama have their own licences.
  • Thinking models write a lot before they answer. At 10 tokens per second, 2,000 tokens of reasoning take more than three minutes.

Will each one run well?

0 of 6 sorted
  • gpt-oss-20b on a laptop with 32 GB of memory

    Answer: Runs well

  • A dense 70B model at Q4 on a laptop with 16 GB

    Answer: Too big or too slow

  • Qwen3.8-27B at Q4_K_M on an RTX 4090

    Answer: Runs well

  • DeepSeek-V4-Flash on a phone

    Answer: Too big or too slow

  • A 1B model on a phone

    Answer: Runs well

  • A dense 27B model with half its layers in DDR4 system memory, for a coding agent

    Answer: Too big or too slow

Use it from your own programs

Each of these tools can act as a local server with an OpenAI-style API, so any app or agent that can talk to a cloud model can talk to yours instead. Point it at http://localhost:11434/v1 for Ollama, http://localhost:1234/v1 for LM Studio, or the port you gave llama-server.

Your model, from Pythonpython
from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
    model="gpt-oss:20b",
    messages=[{"role": "user", "content": "Explain the KV cache in two sentences."}],
)
print(reply.choices[0].message.content)
  • Ollama needs a key in this field but ignores it; any text works.
  • Ollama listens only on 127.0.0.1, so only programs on the same computer can reach it. OLLAMA_HOST changes that, for example to use it from your phone on the same Wi-Fi. Do that only on a network you trust: anyone who can reach the port can use your model.

Quick check

Your local server listens on 127.0.0.1. Who can reach it?

Show the answer

Answer: Only programs on the same computer 127.0.0.1 is the computer talking to itself. Other machines cannot connect unless you change the address it listens on.

Remember

  • Memory ≈ parameters × bits ÷ 8, plus the KV cache. Speed ≤ memory speed ÷ bytes read per token.
  • llama.cpp is the engine underneath many tools; Ollama and LM Studio make it easy; MLX is Apple’s own; phone apps run small models offline.
  • When a dense model does not fit on the card, the part in system memory sets the speed.
  • Mixture-of-experts models suit home computers: keep everything but the experts on the card (--cpu-moe, --n-cpu-moe). gpt-oss-120b runs on one gaming card this way.
  • Choose the biggest model that fits at about 4 bits, and test it in your own language.
  • Local servers speak the OpenAI-style API, so your apps and agents can use them privately.

Words to know

Local model
A model that runs on your own device instead of a company’s servers.
Open weights
A model whose weights you can download and run yourself, under its licence.
GGUF
The single-file model format used by llama.cpp and the tools built on it.
VRAM
The graphics card’s own memory. Fast, but limited in size.
System memory (RAM)
The computer’s main memory. Bigger than VRAM, but several times slower.
Offloading
Putting part of a model in system memory, or on the CPU, because it does not all fit on the GPU.
MoE offloading
Keeping a mixture-of-experts model’s experts in system memory and everything else on the GPU.
MLX
Apple’s framework for running and training models on Apple silicon.
localhost, 127.0.0.1
The computer’s address for itself. A server there is reachable only from the same machine.
OpenAI-style API
The request format most tools accept, so a program can switch between cloud and local models by changing one address.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

What mostly decides how fast a model writes on your own computer?

Show the answer

Answer: How fast memory can deliver the weights each token needs Decode reads the weights for every token, so memory speed ÷ bytes per token sets the limit.

A dense model is 17 GB and your graphics card has 12 GB. What happens if you split it?

Show the answer

Answer: It runs, but the part in system memory sets the speed System memory is several times slower, so even a small share there takes most of each token’s time.

Why do mixture-of-experts models suit home computers?

Show the answer

Answer: Each token reads only a few experts, so the experts can sit in slower system memory Only the few chosen experts are read per token, so keeping them in system memory costs much less than splitting a dense model.

Ollama runs on a card with 12 GB of memory. What context does it use unless you change it?

Show the answer

Answer: 4K tokens Below 24 GiB of GPU memory, Ollama defaults to 4K. Long documents and agents need more, so set it yourself.

Which tool gives a Mac user Apple’s own framework for running models?

Show the answer

Answer: MLX MLX is Apple’s framework for Apple silicon; LM Studio can use it too.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonAPIs: using a model over the internet
Previous lesson All lessons

Choose your language