Ollama: Models as a Service
By the end of this lesson you will be able to install Ollama on your own track and say whether it is using the graphics processor or the central one, pull and run a model from its library, build your own variant of a model with a Modelfile, call it from both of its HTTP interfaces, and — the part that matters most — state what context length and keep-alive it is giving you, rather than finding out later from a conversation that has quietly forgotten its own beginning.
Everything below was read from the documentation of Ollama 0.33.3 · verified 2026-09-08.
What the one-line install actually gives you
Section titled “What the one-line install actually gives you”Part 6 left you with a binary, a GGUF file and a command with a dozen flags in it. Ollama
replaces all three with a name: ollama run qwen3:4b. The convenience is real, and it is
worth knowing which layers it is folding together.
What sits between your prompt and the arithmetic
- Your clientA chat front-end, an editor plugin, curl, or any library written for the OpenAI API.swap freely
- Two HTTP interfaces on port 11434Ollama's own /api/chat and /api/generate, and an OpenAI-compatible surface under /v1.the stable part
- SchedulerDecides which models are resident, how many run at once, how long they stay, and whether a model that does not fit is split with the CPU.the surprising part
- Bundled inference runtimeShips with the install, reads GGUF weights, and picks a backend: CUDA, ROCm, Vulkan or Metal.Part 6's ground
- Model storeContent-addressed blobs plus one manifest per tag, so two tags that share weights store them once.
- Driver and hardwareThe layer Part 5 made you check, and the one that decides whether any of this is fast.
The scheduler is the layer with no equivalent in Part 6, and it is where the defaults live.
Installing on your track
Section titled “Installing on your track”Track S — NVIDIA DGX Spark
DGX OS is Linux on aarch64, and the install script selects the right build:
RunnableTrack S · DGX Spark
curl -fsSL https://ollama.com/install.sh | shThe manual route, if you would rather see what lands where, is the ARM64 tarball the
Linux documentation lists: it is extracted into /usr/ and started with ollama serve.
The hardware-support page lists compute capability 12.1, GB10 (DGX Spark), among the
supported NVIDIA families, so the CUDA backend is the expected path here.
Track X — AMD Ryzen AI Max+ 395
The same install script. Whether you get the ROCm backend or the Vulkan one depends on what is on the machine, and the difference is worth a paragraph of its own below.
RunnableTrack X · Ryzen AI Max+
curl -fsSL https://ollama.com/install.sh | shThe Linux page also documents a separate ROCm package,
ollama-linux-amd64-rocm.tar.zst, for the manual install.
Track M — Apple silicon
The download page states macOS 14 Sonoma or later and Apple M-series silicon for GPU
support; the macOS page adds that an Intel Mac runs on the CPU only. The preferred
install is the disk image dragged to Applications, and on first start the application
offers to put the ollama command in your path.
Models live under ~/.ollama, on the volume your home directory is on. The macOS page
is explicit that this needs “additional space for storing the Large Language models,
which can be tens to hundreds of GB in size”.
Track N — NVIDIA desktop or laptop
On Linux and in WSL2, the install script. On Windows, the installer from the download page; Ollama runs natively there and does not need WSL2.
RunnableTrack N · NVIDIA GPU
curl -fsSL https://ollama.com/install.sh | shThe hardware-support page states compute capability 5.0 and newer with driver 550 or newer, and driver 570 or newer for the older 5.0 to 6.2 cards. If your card is not on that list, Ollama can still reach it through Vulkan.
Did it find the GPU?
Section titled “Did it find the GPU?”This is the first question and the one people skip. The answer is in one column of one command:
RunnableAll tracks
ollama run qwen3:4b "say hello"ollama psOutput — what you should see
NAME ID SIZE PROCESSOR CONTEXT UNTILqwen3:4b xxxxxxxxxxxx x.x GB 100% GPU 4096 4 minutes from nowThe FAQ documents that column exactly: 100% GPU means the model was loaded entirely into
the graphics processor’s memory, 100% CPU means it was loaded entirely into system
memory, and a form like 48%/52% CPU/GPU means it was split between them. A split is not
an error; it is the scheduler fitting what it could and running the rest slowly, and it is
the usual explanation for “why is this so much slower than the video I watched”.
The library, and what a tag means
Section titled “The library, and what a tag means”ollama pull qwen3:4b fetches from Ollama’s own library rather than from the Hugging Face
Hub. The part before the colon is the model, the part after is the tag, and the tag is
doing more work than a version number: it usually encodes the parameter count and the
quantisation together, so qwen3:4b and qwen3:30b-a3b are different models under one
name, and a tag that does not say a quantisation has a default one chosen for you.
RunnableAll tracks
ollama pull qwen3:4bollama listollama show qwen3:4b --licenseQwen3-4B is Apache-2.0 licensed, as the course’s model reference
records; ollama show --license prints the text that was packaged with the weights, which
is the habit Part 3’s licence lesson asked for, applied at the moment of download rather
than the moment of embarrassment.
Where the weights went
Section titled “Where the weights went”The FAQ gives three paths: ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models
on Linux, and C:\Users\%username%\.ollama\models on Windows. Note that the Linux path is
not in your home directory, because the installer creates a service user. Set
OLLAMA_MODELS to move it, and on Linux give the ollama user read and write access to
wherever you point it — the FAQ spells out sudo chown -R ollama:ollama <directory>.
Inside, the layout is blobs named by hash plus manifests, which is why the disk usage does
not obviously map to the model names in ollama list. Part 7’s storage lesson deals with
that properly, including how to stop this store from being a second copy of models you
already have in ~/models.
The two defaults that decide how your conversations go
Section titled “The two defaults that decide how your conversations go”Context length
Section titled “Context length”Here the documentation disagrees with itself, and saying so is more useful than picking a
winner. The Modelfile reference gives num_ctx a “(Default: 2048)”. The FAQ says “By
default, Ollama uses a context window size of 4096 tokens.” The dedicated context-length
page says something different again:
Ollama defaults to the following context lengths based on VRAM: < 24 GiB VRAM: 4k context; 24-48 GiB VRAM: 32k context; >= 48 GiB VRAM: 256k context
All three were read on 8 September 2026. They cannot all describe the version you have
installed, and none of them is a substitute for looking. The CONTEXT column of
ollama ps is the number your machine is actually using, and the reality check at the end
of this part turns that into a measurement rather than a reading.
Whatever the default turns out to be, you can set it. For the whole server:
RunnableAll tracks
OLLAMA_CONTEXT_LENGTH=8192 ollama serveInside a session, /set parameter num_ctx 8192. Through the native API, an options
object carrying num_ctx. And through the OpenAI-compatible API — not at all. The
compatibility page is blunt about it: “The OpenAI API does not have a way of setting the
context size for a model”, and the documented workaround is to bake the value into a model
of your own with a Modelfile. That limitation matters as soon as a chat front-end is
involved, because front-ends talk /v1.
Keep-alive
Section titled “Keep-alive”“By default models are kept in memory for 5 minutes before being unloaded.” For a laptop
that is polite. For a household service that gets a question every twenty minutes, it means
almost every question pays the load time again. OLLAMA_KEEP_ALIVE sets it for the whole
server, the keep_alive request field overrides it per call, a negative value keeps the
model loaded indefinitely, and 0 unloads it as soon as the answer is finished.
RunnableAll tracks
ollama stop qwen3:4bollama psThe trade is memory against latency, and it is a genuine choice rather than a setting with a right answer. The lab later in this part sets it to thirty minutes for exactly this reason, and says so in the file.
Making a model your own
Section titled “Making a model your own”A Modelfile is a small text file that produces a new model name from an existing one. The
reference lists seven instructions: FROM (required), PARAMETER, TEMPLATE, SYSTEM,
ADAPTER, LICENSE, MESSAGE and REQUIRES.
Pseudocode — not a real command
FROM qwen3:4bPARAMETER num_ctx 8192PARAMETER temperature 0.4SYSTEM """You answer in British English, briefly, and say when you do not know."""Save that as Modelfile and build it:
RunnableAll tracks
ollama create house-assistant -f Modelfileollama show house-assistant --parametersollama run house-assistant "what is a KV cache?"Three things this is genuinely good for. It is the documented way to give an
OpenAI-compatible client a larger context, since the client cannot ask for one. It pins a
system message so that every caller gets the same behaviour without every caller having to
send it. And ADAPTER attaches a LoRA adapter to a base model, which is how the fine-tune
you produce in Part 13 becomes something the rest of the house can talk to — with the
reference’s warning attached, that an adapter applied to a base model it was not trained
from behaves erratically.
FROM also accepts a path to a GGUF file, which is the hook the storage lesson uses to
make Ollama read a model you already downloaded instead of pulling a second copy.
Two APIs, and when the difference bites
Section titled “Two APIs, and when the difference bites”Ollama serves its own API and an OpenAI-compatible one on the same port. The native one
carries the things the OpenAI shape has no room for: options with num_ctx and the
sampling parameters, keep_alive, and per-request counters such as prompt_eval_count and
eval_count that tell you how many tokens were actually read and written.
RunnableAll tracks
curl http://localhost:11434/api/chat -d '{ "model": "qwen3:4b", "messages": [{"role": "user", "content": "In one sentence, what is a KV cache?"}], "stream": false, "options": {"num_ctx": 8192, "temperature": 0}}'The compatible one is what every other tool in this course expects. The base URL is
http://localhost:11434/v1/, the API key is “required but ignored”, and the documentation
lists which request fields are supported and which are not: tools yes, tool_choice no,
seed, response_format, stop, stream_options and reasoning_effort yes, logit_bias
and n no. There is a /v1/responses endpoint too, non-stateful only.
By default the server “binds 127.0.0.1 port 11434”, so none of this is reachable from
another machine until you change OLLAMA_HOST — which the lab does deliberately, and
behind a proxy rather than in the open.
More than one graphics processor
Section titled “More than one graphics processor”The FAQ describes the rule plainly: if the model fits entirely on one device it goes on that device, “as this reduces the amount of data transferring across the PCI bus during inference”, and only if it does not fit is it spread across all of them. That is pipeline placement, not tensor parallelism; Part 18 draws the distinction and Part 20 measures it.
Restricting which devices Ollama may use is per vendor: CUDA_VISIBLE_DEVICES for NVIDIA
(the page recommends UUIDs from nvidia-smi -L over numeric ids, because “ordering may
vary”), ROCR_VISIBLE_DEVICES for AMD, GGML_VK_VISIBLE_DEVICES for Vulkan. Two more
scheduler knobs are worth knowing before they surprise you: OLLAMA_MAX_LOADED_MODELS,
whose default the FAQ gives as three times the number of GPUs, and OLLAMA_NUM_PARALLEL,
default one, with the warning that required memory “will scale by OLLAMA_NUM_PARALLEL *
OLLAMA_CONTEXT_LENGTH”. Four parallel slots at 8,192 tokens is a 32,768-token cache
allocation, and a machine that was fine yesterday is not fine today.
Distinguish a model tag from resident server state
Section titled “Distinguish a model tag from resident server state”A model tag identifies a configured artefact in the model library. The server may have no copy resident, one model warming up, or several models competing for memory. A cold request therefore measures loading and initialisation as well as inference; a warm request measures a different path.
When comparing tags, keep the template, sampling settings and context allocation visible. A customised model definition can change behaviour without changing the base tensors. Record the definition alongside the model identity so a colleague can reproduce both the weights and the prompt wrapper.
Exercise the service with a cold request, a warm repeat and a request after using another model. Observe which transitions reload weights and how long the application waits. This exposes the operational cost of keeping a large collection on a small machine. Downloaded capacity is a disk question; simultaneous residency is a memory question. A library can contain many useful models while the serving policy deliberately permits only one large model at a time.
- Ollama is a scheduler, a model store and two HTTP interfaces wrapped around an inference runtime. The runtime is the part Part 6 taught; the scheduler is the part that has opinions.
ollama psanswers the only two questions that matter after an install: which processor is running the model, and what context length it was given.- The context default is documented three different ways in three different places. Read the machine, not the page.
- Models are kept in memory for five minutes by default. For a shared service that is usually the wrong number, in the direction that costs latency.
- A Modelfile is how you change a context length for clients that cannot ask for one, pin a system message, or attach a LoRA adapter.
- The OpenAI-compatible endpoint is what front-ends and agent frameworks speak, and it cannot set the context size. Everything else in this part inherits that fact.
Check your understanding
Sources for this lesson
11 verified · checked 2026-09-08
- 01Ollama — Downloadollama.com/download2026-09-08
- 02Ollama documentation — Linux§ Install; ARM64 install; AMD GPU install; startup service; customisingraw.githubusercontent.com/ollama/ollama/main/docs/linux.mdx2026-09-08
- 03Ollama documentation — macOS§ System requirements; filesystem requirements; troubleshootingraw.githubusercontent.com/ollama/ollama/main/docs/macos.mdx2026-09-08
- 04Ollama documentation — Hardware support§ Nvidia; AMD Radeon; Metal; Vulkan GPU support; GPU selectionraw.githubusercontent.com/ollama/ollama/main/docs/gpu.mdx2026-09-08
- 05Ollama documentation — FAQ§ Context window size; where models are stored; keep alive; concurrency; multiple GPUs; K/V cache quantisationraw.githubusercontent.com/ollama/ollama/main/docs/faq.mdx2026-09-08
- 06Ollama documentation — Context lengthraw.githubusercontent.com/ollama/ollama/main/docs/context-length.mdx2026-09-08
- 07Ollama documentation — Modelfile reference§ Instructions; PARAMETER; TEMPLATE; SYSTEM; ADAPTER; LICENSE; REQUIRESraw.githubusercontent.com/ollama/ollama/main/docs/modelfile.mdx2026-09-08
- 08Ollama documentation — CLI referenceraw.githubusercontent.com/ollama/ollama/main/docs/cli.mdx2026-09-08
- 09Ollama API documentation§ Generate a chat completion; Show model information; List running modelsraw.githubusercontent.com/ollama/ollama/main/docs/api.md2026-09-08
- 10Ollama API documentation — OpenAI compatibility§ Supported request fields; Setting the context sizeraw.githubusercontent.com/ollama/ollama/main/docs/api/openai-compatibility.mdx2026-09-08
- 11Ollama documentation — Dockerraw.githubusercontent.com/ollama/ollama/main/docs/docker.mdx2026-09-08
Every technical claim on this page was checked against the official documentation of the tool, vendor or model publisher on the date shown, at the version pinned for the course. Where the course disagrees with folklore, the source is how you can tell which one to trust.