Zum Inhalt springen

Lektion 6 · Running Llama Locally

Run Llama Locally with Ollama

Install Ollama, download and chat with a small Llama model, use key commands, customize behavior with a Modelfile and keep the local server private.

Ollama is a popular program for downloading and running open models on your own computer. It manages the model files, runs a local server and gives you a simple command line. It is a separate product, not made by Meta. This lesson follows its official documentation as checked in December 2026.

Install and run

Download Ollama from its official website for macOS, Windows or Linux. Then open a terminal. These commands are real, but they cannot run in this page:

Terminal
ollama pull llama3.2:3b     # download the model
ollama run llama3.2:3b      # start chatting

As of December 2026, Ollama's library lists llama3.2:1b at about 1.3 GB and llama3.2:3b at about 2.0 GB to download. If your machine is modest, start with the 1B. Type a question at the prompt. The program shows how to leave the chat.

The library tag (llama3.2:3b) selects a specific packaged build, usually a quantized one. Read the model's library page to see which format it is and what license applies. Your license duties from the license lesson still apply.

Everyday commands

Command What it does
ollama pull <model> Download a model
ollama run <model> Chat, or answer one prompt
ollama ls List downloaded models
ollama ps List loaded (running) models
ollama stop <model> Unload a running model
ollama rm <model> Delete a model
ollama serve Start the server
ollama create <name> -f Modelfile Build a custom model

Run ollama --help to confirm the options in your version.

ollama ps is useful when replies are slow. It shows how much context was allocated and whether the model runs fully on the GPU or partly on the CPU.

Customize with a Modelfile

A Modelfile is a small text file that creates a named variant. It starts from a base with FROM, can add a SYSTEM message and sets runtime values with PARAMETER:

TEXT
FROM llama3.2:3b
PARAMETER temperature 0.2
PARAMETER num_ctx 8192
SYSTEM You are a patient helper for a gardening shop. Answer in short sentences. If you are unsure, say so.
Terminal
ollama create garden-helper -f Modelfile
ollama run garden-helper

A Modelfile changes settings, not knowledge. It does not train the model. Other instructions exist, such as TEMPLATE, MESSAGE and LICENSE. Be careful with TEMPLATE: a wrong template can badly damage answers (see chat templates).

Set num_ctx on purpose. Ollama's default context depends on your version, settings and hardware (its documentation, as of December 2026, ties the default to GPU memory and gives 4k tokens for under 24 GiB), and it can be far smaller than the model's maximum. ollama ps shows what was allocated. When long text does not fit, part of it is dropped, and the model then answers as if it never saw that part.

Practice reading a Modelfile

Python Stand-in: check a Modelfile for common problems

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This is not Ollama's own parser. It is a simple check that you might add to a project script. The thresholds are teaching choices.

Privacy and the network

By default Ollama listens on 127.0.0.1:11434, which is only reachable from your own machine. Its FAQ says that when you run models locally, your prompts are not sent to Ollama. It also offers cloud models, which do process your prompts on remote servers, so check which kind you are using. You can disable cloud features with the environment variable OLLAMA_NO_CLOUD=1, or in its server configuration file, and then restart.

Changing OLLAMA_HOST so that Ollama listens beyond your own machine can expose your model to your network. Do not treat the local API as protected. Keep it on localhost, or put authentication and a firewall in front.

Troubleshooting

  • Very slow: try a smaller model, close heavy apps and check ollama ps.
  • Out of memory: lower num_ctx, or use a smaller model.
  • Model forgets the start of a long text: the context window is too small.
  • Disk full: remove unused models with ollama rm.
  • First reply is slow, later ones are fast: the first request loads the model into memory.

A short first session

After your first chat, try a small experiment. Ask the same factual question three times and compare the answers. Then ask about something that happened very recently and see how the model responds. Finally, paste a long paragraph and ask for a three-line summary. Write down what went well and what failed. These three checks quickly show you the limits of a small model: variation, missing recent knowledge and trouble with detail.

Next, create the Modelfile from this lesson with a lower temperature and a clear system message, and repeat the same questions. Compare the two sets side by side. You are doing your first evaluation, and the same method scales up later.

Managing disk and memory

Model files are large, and several versions of a model add up quickly. Use ollama ls to see what you have and remove the ones you no longer test. A loaded model also occupies memory while it waits for the next request. If another program needs the memory, ollama stop unloads the model without deleting the file.

Keeping your setup reproducible

Save your Modelfiles in a Git repository next to the code that uses them. Note the Ollama version and the model tag in your project notes. A tag can be updated by its publisher, so when exact behavior matters, record the model identifier that ollama ls shows and rerun your tests after any download.

When to move beyond Ollama. Stay with Ollama while it meets your needs. If you need many simultaneous users, special serving features or tighter control, compare it with the options in serving Llama.

A habit for later lessons. Keep this local setup working. The Python, retrieval and project lessons use it for the read-only examples that you run on your own machine.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which command downloads a model without starting a chat?

    pull downloads. run starts a chat.
  2. 2. What does a Modelfile change?

    It packages configuration. It does not train the model.
  3. 3. Why set num_ctx explicitly?

    Defaults can vary, so long inputs can be cut.
  4. 4. What is the safest default network setting?

    Localhost keeps other machines from reaching your model server.

Summary

  • Ollama downloads, manages and serves open models locally.
  • pull, run, ls, ps, stop and rm cover daily work.
  • A Modelfile sets the system prompt and parameters.
  • Set the context size, and keep the server private.

Next: Run Llama with llama.cpp

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.