Sub topic 4
Running Your First Model
This chapter assumes you have a terminal, Ollama installed, and the server running. It also assumes you know what a large language model is. If ollama --version prints a version number, you are ready.
What happens when you run a model
ollama run <name> does several things in sequence. The CLI is a client of the local server, so it sends requests to the server over HTTP.
- The CLI asks the server whether the model exists in the local store.
- If it does not, the server downloads it. This step is the same as
ollama pull. - The server loads the model weights into memory. It uses GPU memory if a supported GPU is present, and system RAM otherwise.
- The CLI opens an interactive prompt and sends each message you type to the server.
The first run is slow for two reasons: the download, and the load into memory. Later runs skip the download. If the model is still in memory, they also skip the load.
Pulling and chatting
You can pull first and run later, or let run pull for you. Pulling separately is useful on a slow connection, because you can see the progress and retry on its own.
ollama pull llama3.2
ollama run llama3.2When the >>> prompt appears, type a message and press Enter. The reply streams in token by token. A token is a small chunk of text, often a word or part of a word.
>>> Why is the sky blue?To end the session, type /bye or press Ctrl+D. Ending the session does not unload the model right away. The server keeps it in memory for a short time so the next request is fast.
Slash commands inside the chat
Lines that start with / are commands for the CLI, not messages to the model. Type /? to list them. The most useful ones are:
| Command | What it does |
|---|---|
| `/?` | Lists the available commands |
| `/show info` | Prints details about the loaded model |
| `/set parameter temperature 0.2` | Changes a generation parameter for this session |
| `/set system "Answer briefly."` | Sets a system prompt for this session |
| `/clear` | Clears the conversation context |
| `/bye` | Exits the session |
Changes made with /set last only for the current session. They do not change the stored model. Later chapters cover how to make such changes permanent with a Modelfile.
One-shot prompts and pipes
You do not have to use the interactive prompt. If you pass the prompt as an argument, Ollama prints the reply and exits.
ollama run llama3.2 "Explain what a context window is in one sentence."This form works in scripts. You can also feed in text from a file or another command through standard input.
cat notes.txt | ollama run llama3.2 "Summarize this text in three bullet points."When standard input and an argument are both present, the model sees them combined as one prompt. Keep the input small at first. Very long input can exceed the context window, and the model may then ignore the start of it without any error. The context window is covered in a later chapter.
Checking what is loaded
Two commands show the state of your local setup.
ollama list
ollama psollama list shows the models stored on disk. ollama ps shows the models currently loaded in memory. Its output includes the model size and a PROCESSOR column. That column reports where the model is running, for example 100% GPU, 100% CPU, or a split such as 30%/70% CPU/GPU.
The split matters. If part of the model sits in system RAM because it did not fit in GPU memory, generation is much slower. You can use ollama ps as your first check when a response feels slow.
Conversation memory
The model does not remember anything between requests. The CLI keeps the conversation history and sends all of it with each new message. This is why the model can refer to your earlier question in the same session.
Two consequences follow:
- Each turn costs more than the last, because the history keeps growing.
- When the history exceeds the context window, the oldest messages are dropped. The model then behaves as if it never saw them.
Use /clear when you switch topics. It resets the history, so old text does not take up context or influence the next answers.
Common first-run problems
| Symptom | Likely cause | What to do |
|---|---|---|
| `could not connect to ollama server` | The server is not running | Start the Ollama app or run `ollama serve` |
| `pull model manifest: file does not exist` | The name or tag is wrong | Check the spelling and the tag in the library |
| Download stalls or restarts | Network interruption | Run `ollama pull` again. It resumes from the layers it already has |
| Very slow replies | The model runs on the CPU, or is split | Check `ollama ps`, then try a smaller model |
| Out-of-memory error on load | The model is too large for your memory | Choose a smaller size or a more compressed quantization |
The last two rows are explained in the chapter on model size and quantization. The connection errors are covered again in the troubleshooting chapter.
Reproducible behavior
Replies vary between runs because the model samples its output. If you need similar replies from run to run, lower the temperature in the session.
>>> /set parameter temperature 0A temperature of 0 makes the output close to deterministic for the same prompt, but it does not guarantee identical output across different hardware or versions. Treat it as a way to reduce variation, not remove it.
Exercise
You run ollama run llama3.2 and the reply is very slow. In another terminal, ollama ps shows 40%/60% CPU/GPU in the PROCESSOR column. What does that mean, and what are two ways to fix it?
Show answer
It means only about 40% of the model fits in the CPU's share and 60% runs on the GPU, so part of the model sits in system RAM and the slow CPU-side layers limit the speed. The fixes are to use a smaller model or a more compressed quantization so that the whole model fits in GPU memory, or to free GPU memory by closing other programs that use it.
Exercise
You ask a question in an interactive session, then switch to an unrelated topic and get answers that mention your earlier subject. Why does this happen, and which command helps?
Show answer
The CLI sends the whole conversation history with each message, so the earlier text still influences the reply. Type /clear to reset the history before you change topics.