Skip to main content
Section 3

Getting a model running

The runtimes and quantization that turn a file into a chatbot.

5 lessons25-question quiz
3.1

The runtimes: Ollama, LM Studio, llama.cpp

6 min read

A model file on its own does nothing. Something has to load it into memory, run the actual math, and hand you a way to send it text and get text back. That something is a runtime. Three names come up constantly, and they are not really three competing choices so much as three layers of the same stack.

The three you will meet

RuntimeWhat it isBest for
llama.cppThe underlying inference engine, run from the command line and built to be embeddedPeople who want the engine directly, or who are building on top of it
OllamaA simple CLI and background service built on top of llama.cpp, with one-line model pullsGetting a model running fast, from a terminal, with the least setup
LM StudioA desktop app with a graphical interface for browsing, downloading, and chatting with modelsPeople who want a visual, point-and-click experience instead of a terminal
What each one is for

llama.cpp is where most of this ecosystem starts. It is an open-source inference engine written to run GGUF models efficiently on ordinary hardware, CPU included, without needing the heavier machine-learning frameworks a model was originally trained with. Both Ollama and LM Studio lean on the same kind of engine under their own interface.

Ollama wraps that engine in a small CLI and a background service. You type one command to pull a model and another to run it, and it handles finding a GPU, loading the model, and serving a local API without any extra configuration. It is the fastest path from nothing installed to a model answering questions, which is why the Ollama how-to in this Academy uses it as the walkthrough.

LM Studio covers the same ground with a graphical desktop app instead of a terminal: a searchable model catalog, a download manager, a chat window, and a settings panel for things like context length and GPU offload, all without typing a command.

Key idea
llama.cpp is the engine, Ollama is the fast CLI path, LM Studio is the GUI path. Pick based on whether you want a terminal or a window, not because one is fundamentally more capable than the other for everyday chatting.
This lesson is a map of the landscape. The next lessons and the Ollama how-to walk through actually doing it.
Key terms
Runtime
The software that loads a model file and runs it, turning it into something you can send text to.
llama.cpp
The open-source inference engine that Ollama, LM Studio, and much of the local-AI ecosystem are built on.
3.2

Quantization in practice

5 min read

When you pick a model to download, you are not just picking a model, you are picking a quantization level of that model: how much each weight has been compressed to save memory. A quick recap, since the full breakdown lives in its own guide.

A model trained at full precision stores each weight as a 16-bit number. Quantization shrinks that down to fewer bits, commonly 8, 6, 5, 4, 3, or 2, which shrinks both the download and the memory the model needs to run. Fewer bits costs some accuracy, but that loss is gradual, not a cliff, at least down to a point.

  • Q8_0 / Q6_K: close to full precision, and the largest of the practical sizes.
  • Q5_K_M: a notch of headroom above the everyday default.
  • Q4_K_M: the default most people should reach for first. Under 1% quality cost for a real cut in memory.
  • Q3_K_M and below: only when a smaller quant is the difference between the model fitting in memory or not.
Key idea
When in doubt, pick Q4_K_M. It is the standard recommendation because it gives up the least quality for the memory it saves.
The full picture, including the exact bit counts, measured sizes, and how to choose by your VRAM, is in Which GGUF quantization level should you pick? Read it once and you will not need to guess again.
Key terms
Quantization
Storing a model's weights with fewer bits per number to shrink its size, at some cost to precision.
GGUF
The file format llama.cpp and its ecosystem use to package a quantized model and its metadata in one file.
3.3

Pulling and running a model

6 min read

However you get there, getting a chatbot running locally follows the same basic flow every time. The names of the commands differ between tools, but the shape does not.

  1. 1Install a runtimeOllama, LM Studio, or llama.cpp itself
  2. 2Pull a modelDownload a specific model and quantization to disk
  3. 3Run itLoad the model into memory and start serving it
  4. 4ChatSend it text, get text back
The basic flow

With Ollama, each of those steps is a single command. Pulling downloads a model once and stores it on disk; running loads it into memory and drops you into a chat prompt right in the terminal.

The whole flow with Ollama
ollama pull qwen2.5-coder:7b
ollama run qwen2.5-coder:7b

The first line downloads the model, a one-time cost. The second loads it and opens a chat prompt: type a question, get a streamed reply, type /bye to leave. Run the same command again later and there is no download, it starts straight from the copy already on disk.

This is the same flow the Ollama how-to walks through step by step, including picking a model size for your hardware and proving to yourself that it really is running offline.
Key idea
Install once, pull each model once, run to load it, chat to use it. Every local runtime is some version of this same loop.
Key terms
Pull
Downloading a model to disk so it is ready to run, without loading it into memory yet.
3.4

The local API endpoint

6 min read

Chatting in a terminal or a chat window is only half of what a local runtime gives you. Most of them also run a local API, a network address on your own machine that other programs can send requests to, in the same request-and-response shape covered in the Building with AI course's lesson on calling a model. The difference is where that address points: instead of a cloud provider's servers, it points at your own hardware.

Ollama, for example, serves an OpenAI-compatible API at http://localhost:11434/v1 as soon as it is running. "OpenAI-compatible" means it accepts requests in the same shape as OpenAI's API, so any tool, editor, or SDK that lets you set a custom base URL can point at it instead of a cloud endpoint, with no other code changes.

Pointing an OpenAI-style client at a local model
from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
    model="qwen2.5-coder:7b",
    messages=[{"role": "user", "content": "Say this is a test"}],
)
print(reply.choices[0].message.content)

The api_key field still has to be present because the client library expects one, but a local server does not check it against anything. Nothing about this request leaves your machine: the model, the request, and the response all stay local.

  • localhost means "this machine", so the request never touches the network.
  • The base URL is the only thing that changes between a cloud setup and a local one; the rest of your code stays the same.
  • Other runtimes expose the same idea on their own port, so the pattern carries over even if the exact address differs.
Key idea
A local runtime is also a local server. Point anything that accepts an OpenAI-style base URL at it, and your editor, agent, or script talks to your own machine instead of the cloud.
Key terms
Local API endpoint
A network address on your own machine, served by a runtime like Ollama, that other software can send model requests to.
OpenAI-compatible
Accepting requests in the same shape as OpenAI's API, so existing tools can point at a different server with no other changes.
3.5

Performance: context, speed, and memory

6 min read

Once a model is running, two questions decide whether the experience is pleasant or painful: how much memory it needs, and how fast it replies. Both have straightforward explanations.

Context costs memory too

The weights are only part of what a running model holds in memory. As a conversation grows, the runtime keeps a running cache of everything in the context window so it does not have to reprocess the whole conversation on every reply. That cache grows with conversation length, so a long chat or a large pasted document uses noticeably more memory than a short question, on top of whatever the weights themselves need.

Speed is measured in tokens per second

How fast a model replies is usually measured in tokens per second: how many tokens it generates for each second of wall-clock time. That number depends mainly on two things: how big the model is, and how capable the hardware running it is. A smaller model on a fast GPU can be many times quicker than a larger model on the same hardware, or the same model on a CPU instead of a GPU.

FactorEffect
A bigger model (more parameters)More math per token, so generation is slower at the same hardware
Running on CPU instead of GPUUsually much slower; GPUs are built for exactly this kind of math
A long context (long conversation or a big pasted file)More to process before each reply, and more memory pressure
A lower quantizationSmaller and often faster, since there is less data to move
Other apps competing for the same memoryCan force part of the model off the GPU, or force it onto CPU entirely
What slows generation down
  • If a model that used to run fine suddenly loads onto CPU instead of GPU, another app is probably using the memory it needs.
  • A model that barely fits in memory with a short chat can run out of room once the conversation, and its cache, grows.
  • When speed matters more than a little extra quality, a smaller model or a lower quantization is usually the first thing to try, not more expensive hardware.
Key idea
Memory use grows with model size and conversation length, and speed depends on model size and hardware. When something slows down, check what changed in one of those three: the model, the context, or what else is using the memory.
Key terms
Tokens per second
How many tokens a model generates per second, the standard measure of local generation speed.
KV cache
The runtime's memory of the current conversation, which grows with context length on top of the model's own weights.

Section 3 quiz

25 questions. Pass at 75% to master this section. Retakes are unlimited, and the quiz is where the learning sticks.

Section 3 quiz · Getting a model runningQuestion 1 of 25

What is a "runtime" in the context of running a model locally?