Sub topic 1
Open-Weight Models and Why Run Them Locally
This chapter explains what an open-weight model is and how it differs from an open-source model or a hosted API. It also covers the costs and benefits of running a model on your own machine. The rest of the tutorial uses Ollama to do that. Here you only need the concepts that explain why the tool exists.
Prerequisites
This chapter assumes you have the following:
- A general idea of what a large language model (LLM) is: a neural network that predicts the next piece of text from the text so far.
- Comfort with a terminal. You will not run commands yet, but later chapters do.
- Basic familiarity with HTTP and JSON, since local models are usually called over a local HTTP API.
- Basic Python or another scripting language, for the API examples in later chapters.
What "open-weight" means
A trained model is two things: code that describes the network's structure, and a large file of numbers called weights (or parameters). The weights are what training produces. They hold everything the model has learned.
An open-weight model is a model whose weights are published for anyone to download. With the weights you can run the model on your own hardware, inspect it, and often fine-tune it. Examples include Llama, Mistral, Gemma, Qwen, and Phi.
A hosted model works the other way. You send text to a company's server, and the weights never leave it. You get an answer back, but you cannot download or inspect the model.
Open-weight versus open-source
The two terms are often mixed up, but they are not the same.
| Property | Open-source software | Open-weight model | Hosted (closed) model |
|---|---|---|---|
| Weights downloadable | Not applicable | Yes | No |
| Training data published | Not applicable | Usually no | No |
| Training code published | Yes | Sometimes | No |
| License allows any use | Yes (by definition) | Depends on the license | Terms of service only |
| Runs on your machine | Yes | Yes | No |
Most open-weight releases do not publish their training data. Many come with custom licenses that limit some uses. Some restrict very large commercial deployments. Some require you to display attribution. Some prohibit specific uses. Others, such as models under the Apache 2.0 license, are far more permissive. Read the license of each model before you build a product on it.
How local inference works
Inference means using a trained model to produce output. Training is the expensive process that creates the weights. Inference is what you do with them afterward.
When you run a model locally, three things happen:
- The weights are read from disk into memory (RAM, or GPU memory if you have a supported GPU).
- Your prompt is split into tokens, which are small pieces of text such as words or word fragments.
- The model produces the reply one token at a time, and each new token is computed from all the tokens before it.
Memory is usually the limiting factor. The weights must fit in memory, and the model also needs extra space for its working state while it generates. Chapter 7 covers how model size and quantization determine whether a model fits.
Why run a model locally
Local inference is a trade-off, not an upgrade. These are the reasons people choose it.
Privacy and data control
Your prompts and documents stay on your machine. This matters for source code under an NDA, medical or legal text, internal documents, and personal notes. You do not need to review a provider's data retention policy, because no provider is involved. You still need to secure the machine itself.
Cost structure
Hosted APIs usually charge per token. Local inference has no per-token fee. You pay for hardware and electricity instead. That favors steady, high-volume use, such as batch-processing thousands of documents. It does not favor occasional use of a large model that would need expensive hardware.
Offline use and availability
After the weights are downloaded, the model works without internet access. It also has no rate limits from a provider and no outage on a provider's side.
Control and reproducibility
You choose the exact model file, and it does not change unless you change it. Hosted models can be updated or retired, which can alter results you depended on. With local weights you can pin a version and get repeatable behavior. You can also set generation parameters and system prompts, and you can fine-tune the weights on your own data.
Learning and experimentation
Running a model yourself shows you things an API hides: how memory use grows with context length, how quantization trades quality for size, and how sampling settings change output. This tutorial depends on that visibility.
Costs and limits to expect
Be realistic about the downsides before you commit.
- Capability gap. The models that fit on a laptop or a single consumer GPU are small compared with the largest hosted models. They are good at many tasks, such as summarizing, extraction, drafting, and simple code help. They are weaker at difficult multi-step reasoning and broad factual recall. Test on your actual task rather than assuming.
- Hardware limits. A model that does not fit in memory will fail to load or run very slowly. Speed depends on your processor, memory bandwidth, and whether a GPU is used.
- Disk space. A single model commonly takes from a few gigabytes to tens of gigabytes. Several models add up fast.
- Maintenance. You are responsible for updates, for choosing between model versions, and for fixing problems.
- Safety and quality controls. Hosted services often add moderation and monitoring layers. A local model comes with only what is built into the weights, unless you add more.
Common misconceptions
- "Local means private by default." The model does not send your data anywhere, but any tool you connect to it might. Check what the surrounding software does.
- "Open-weight means free for any use." The license decides, and licenses differ.
- "A local model is as good as the best hosted one." Usually it is not. Smaller models trade capability for size.
- "I need a GPU." Many small models run acceptably on a CPU. A GPU makes generation much faster, but it is not always required.
Deciding between local and hosted
Use these questions as a rough guide.
| Question | Leans local | Leans hosted |
|---|---|---|
| Must data stay on your own machine? | Yes | No |
| Is usage high-volume and steady? | Yes | Low or occasional |
| Do you need the strongest possible model? | No | Yes |
| Do you need offline operation? | Yes | No |
| Do you have enough memory for the model? | Yes | No |
Many projects mix both. They use a local model for private or high-volume steps and a hosted model for the hardest requests. Because Ollama offers an OpenAI-compatible endpoint (covered in a later chapter), switching between the two can take little code change.
Where Ollama fits
Running an open-weight model by hand means finding weights in the right file format, loading them with an inference engine, setting up hardware acceleration, and exposing the result to your programs. Ollama bundles those steps. It gives you a command-line tool, a local server with an HTTP API, and a managed store of downloaded models. The next chapter describes how those parts fit together.
Exercise
A team wants to summarize 50,000 internal support tickets that contain customer names. They have a workstation with a capable GPU and no budget for per-token fees. List two reasons local inference suits this job and one risk they should check before starting.
Show answer
Reasons: (1) The tickets contain customer data, and local inference keeps the text on the team's own machine. (2) The workload is high-volume, and local inference has no per-token fee, only hardware and electricity costs. Risks to check (any one): whether the model's license permits this use, whether a small model summarizes accurately enough on a sample of real tickets, or whether the model fits in the GPU's memory.
Exercise
A colleague says, "This model is open-weight, so it is open-source and I can use it for anything." Identify what is wrong with this statement.
Show answer
Open-weight means the weights can be downloaded. It does not mean the training data or training code are published, and the license may restrict some uses. The colleague should read the model's license before relying on it.