Sub topic 3
Open-weight models: weights you can download and run
This chapter covers what open-weight models are, what you receive when you download one, and what running one involves. It assumes you have called a hosted LLM API before, can read basic Python, and know the terms prompt, token, and context. Parameter counts, memory sizing, and licenses get their own chapters, so this chapter only introduces them.
What "open-weight" means
A language model is a large set of numbers called weights (also called parameters). Training adjusts these numbers until the model predicts text well. An open-weight model is one whose trained weights the publisher lets you download. After that, you can run the model on hardware you control.
A hosted API works differently. The provider keeps the weights on its servers, and you send requests over the network. You never see the weights.
What you download usually includes:
- Weight files. Large files, often in the
safetensorsorGGUFformat. A 7-billion-parameter model is several gigabytes. - Configuration. A small file describing the architecture, such as the number of layers and the vocabulary size.
- Tokenizer files. The rules that turn text into token IDs and back. You must use the tokenizer that matches the model.
- A license and a model card. The license states what you may do. The model card describes the intended use, training notes, and known limits.
What you usually do not get is the training data, the full training code, or the exact recipe. That gap matters for the next chapter, which covers why open-weight is not the same as open-source.
What you gain
- Control over the model version. A hosted provider can update or retire a model. A file on your disk does not change. If a prompt works today, the same weights give you the same behavior next month, as long as you keep the same runtime settings.
- Control over where data goes. Prompts stay inside your network if you host the model there. The privacy chapter covers the compliance side.
- Freedom to customize. You can fine-tune the weights on your own data, or change decoding settings the hosted API does not expose.
- Cost that scales differently. You pay for hardware by time, not by token. At steady high volume this can be cheaper. At low or spiky volume it is usually more expensive, because idle hardware still costs money.
- Offline use. The model can run with no internet connection.
What you give up
- Operational work. You choose hardware, install a serving program, monitor it, and fix it when it fails.
- Capacity planning. A hosted API absorbs traffic spikes for you. Your server has a fixed capacity, and requests queue or fail when you exceed it.
- The strongest models. The largest and most capable models have often been available only as hosted APIs. Open-weight models have been closing the gap, but check current results on your own task rather than assuming.
- Hardware limits. A model must fit in memory. Larger models need expensive GPUs or several of them.
The path from download to answer
Three pieces take part in running an open-weight model. The weights hold the learned numbers. A runtime (also called an inference engine) loads the weights and does the math for each token. A server wraps the runtime in an HTTP interface so your application can call it.
Many serving tools expose an OpenAI-compatible endpoint. This means your application can use the same client library and request format it would use for a hosted API, and only the base URL changes. The portability chapter builds on this.
A first look at running one
The sketch below shows the application side. It assumes a local server is already running and listening on port 11434 (the default for Ollama) and that you have pulled a model. The code reads its settings from environment variables, so the same program can point at a hosted provider later.
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["LLM_BASE_URL"],
api_key=os.environ.get("LLM_API_KEY", "not-needed-for-local"),
)
MODEL = os.environ["LLM_MODEL"]
def ask(prompt: str) -> str:
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0,
)
return response.choices[0].message.content
if __name__ == "__main__":
print(ask("Name three uses of a hash map."))Set the variables before running it, for example LLM_BASE_URL=http://localhost:11434/v1 and LLM_MODEL set to the name of a model you pulled. Local servers generally ignore the API key, but the client library requires some value, which is why the code supplies a placeholder.
Variants of the same model
One model family is usually published in several forms. Knowing the names helps you pick the right file.
| Variant | What it is | Typical use |
|---|---|---|
| Base | Trained only to predict the next token | Starting point for fine-tuning |
| Instruct or chat | Further trained to follow instructions | Most applications |
| Quantized | Weights stored with fewer bits | Fitting on smaller hardware |
| Fine-tuned | Adjusted on extra data for a task | Specialized behavior |
If you want an assistant that answers questions, pick an instruct or chat variant. A base model will often continue your text instead of answering it, which surprises many first-time users.
Common errors
- Using the wrong tokenizer or chat template. Instruct models expect messages wrapped in a specific format. Serving tools usually apply it for you, but if you build prompts by hand with a mismatched template, quality drops sharply with no error message.
- Running out of memory. The weights plus the working memory for the context must fit. The memory chapter shows how to estimate this before you download anything.
- Judging the model by a leaderboard alone. Public scores measure general tasks. Your task may differ. The evaluation chapter shows how to test candidates on your own examples.
- Treating "open" as "free to use for anything". Each model has its own license, and some restrict commercial use or very large deployments.
- Comparing against the wrong baseline. A small open-weight model run on your laptop is not comparable with a very large hosted model. Compare models of similar capability, or compare by cost for a fixed quality level.
When open-weight is a good fit
Open-weight models tend to suit these situations:
- Data cannot leave your environment.
- Request volume is high and steady, so hardware stays busy.
- You need a fixed model version for reproducibility.
- You need fine-tuning or low-level control over generation.
- You need to run offline or at the edge.
Hosted APIs tend to suit low or unpredictable volume, a need for the most capable models, and teams without capacity to operate servers. Later chapters turn this into a structured comparison.
Exercise
Your team wants to move a working prototype from a hosted API to a local open-weight model. List what you must download besides the weight files, and name the one change the application code needs if the local server is OpenAI-compatible.
Show answer
Besides the weights, you need the tokenizer files and the configuration file, and you should read the license and model card. Use the instruct or chat variant if the application is conversational. If the server is OpenAI-compatible, the code changes only in its settings: the base URL (and the model name, plus a placeholder API key if the client requires one). The request and response handling stays the same.
Exercise
A colleague downloads a base model, sends it the prompt "What is the capital of France?", and gets a long, rambling continuation instead of a short answer. What is the likely cause and the fix?
Show answer
The colleague loaded a base model, which only predicts the next token and was not trained to follow instructions. The fix is to use the instruct or chat variant of the same model family, with the correct chat template applied.