Running an existing model
What happens between sending a message and seeing the first word of the answer? Follow a single request through the tokenizer, the checkpoint and the program that runs it.
Open this chapter with experiments and audio
What do you actually download?
A downloaded language model normally comes with a configuration, one or more files containing weights, and a tokenizer. The configuration describes the structure to build. For example, the hidden size specifies how many components represent a token at each layer. The weights give the structure its learned behavior. The tokenizer specifies which sequence of integers represents a piece of text.
The runtime assembles these parts, puts the arrays in memory and performs the calculations. The first request can be slower because the runtime must read the files and prepare the model. Reusing the loaded model saves that work. Two files with the same name for a model family can contain different parameter counts, training revisions or quantizations. Record the exact model tag when comparing results.
Follow one chat message
The application creates a list of messages. A chat template marks who said what, using special tokens expected by the instruction-tuned model. After tokenization, the model reads the prompt and produces a score for each possible next token. A decoding rule selects one, appends it and repeats. Text appears on screen as the tokenizer decodes the new IDs.
A role is part of the model input. It helps the model distinguish a question from an earlier reply. A second request needs the relevant conversation history in its input, unless the service manages that history separately. Closing a local chat can therefore remove the earlier context while leaving every model parameter intact.
User asks for the area of a room.
Mark speaker roles and encode the text.
Read the prompt, score and select successive token IDs.
Display the generated answer.
Send a request from Python
Install Ollama on your own computer, start the local service and run ollama pull qwen3:0.6b once to fetch the checkpoint. Run the following Python 3 script after the download finishes. It sends one local request. Streaming is disabled so the complete response arrives as one JSON object. The small model is suitable for inspecting the protocol. The wording and accuracy of its reply can vary.
import json
from urllib.request import Request, urlopen
body = {
"model": "qwen3:0.6b",
"messages": [{"role": "user", "content": "What is 5 metres times 5 metres?"}],
"stream": False,
"think": False,
}
request = Request("http://localhost:11434/api/chat",
data=json.dumps(body).encode(),
headers={"Content-Type": "application/json"})
with urlopen(request, timeout=180) as response:
answer = json.load(response)
print(answer["message"]["content"])Which part would you change?
To change the question, edit the user message. To change the learned behavior persistently, load different weights or train an adapter. For a document update, supply new context. For exact arithmetic, let the application call a calculator. These choices change different parts of the same system.
Try asking the same question twice. Differences in wording can arise from token sampling. A confident-looking sentence can also contain a wrong number. Save the question, the model tag and the generated response before comparing an adjustment. If the local connection is refused, first check whether the service is running. A model-missing response instead points to the exact tag you downloaded.
Does shortening the prompt remove model parameters?
No. It reduces the number of input tokens and their temporary representations.
Weights, libraries and the process that holds them in memory
A downloaded checkpoint contains parameters. A configuration describes dimensions, layer types and related choices. The tokenizer and chat template map a conversation into token IDs. A compatible model implementation constructs the computation that gives the arrays their meaning. Swap the implementation for one expecting different shapes and loading may fail. Swap only the chat template and every array can load correctly while the generated behavior changes.
One possible stack uses Hugging Face Transformers to load a compatible model and run generation, with PyTorch providing tensor operations and automatic differentiation for training. A service can instead load a supported checkpoint in vLLM to schedule concurrent inference requests. A client library serializes a request and receives the result. Where the model runs determines whose device holds its weights. Importing a client library alone does not put those weights on your laptop.
Identical text, different answers after switching servers. What would you compare first?
Capture the exact model revision and formatted input IDs on both sides, including assistant and end markers. Then compare decoding settings and the first differing logits. This narrows the difference to formatting, model computation or token selection.
Count the positions available after instructions and history →
Sources · Hugging Face · Transformers · PyTorch · autograd · vLLM