Day 103 Β· The tool wall

The Model Landscape & Local Inference

You will be able to
  • Compare open-weights vs closed API models along cost, privacy, control, and capability axes
  • Navigate the Hugging Face ecosystem: models, model cards, licenses, and the transformers library
  • Run a small open model locally with the transformers pipeline and with Ollama
  • Explain what quantization does at a preview level and why it makes laptops viable
  • Read a model card and license critically enough to advise a customer
Today's ~120 minutes
Spaced-rep warm-up: due cards (decoding, scaling)10 min
ELI5 + tech read: the trade-off axes20 min
Guided: transformers local run + model card reading25 min
Guided: Ollama + local REST API15 min
Practice: three client memos20 min
Project: landscape worksheet + quiz + flashcards30 min

Builds on: Day 102 β€” Decoding & sampling Β· Day 100 β€” The training pipeline (base vs instruct) Β· Day 87 β€” PyTorch & tensors

The analogy

Walk into a good workshop and you see a tool wall: some tools you own outright β€” hang them wherever you like, modify them, no one can take them away β€” and for the huge specialized machines, you rent time at the machine shop across town. Neither is "better." Owning means control, privacy, and zero rental fees, but you maintain the tools and the biggest machines will not fit in your garage. Renting means instant access to the most powerful equipment on earth, but you pay per use, your workpiece leaves the building, and the shop can change its machines or prices.

Models are exactly this. Open-weights models (Llama, Mistral, Qwen, Gemma families) are tools you own: download the weights, run them on your hardware, fine-tune them, ship them in an air-gapped environment. Closed API models (Claude, GPT, Gemini) are the machine shop: frontier capability, zero ops burden, metered billing. A working AI engineer knows the whole wall β€” and today you hang your first owned tool by running a real open model on your own machine.

Why this matters on the job

"Should we use an API or host our own model?" is a top-three customer question, and the honest answer is a trade-off matrix, not a slogan β€” data-privacy rules, cost curves at volume, latency floors, and capability requirements all pull differently. FDEs meet customers with air-gapped environments (Day 170) where APIs are simply unavailable. And you cannot fine-tune (Day 128), quantize (Day 129), or serve with vLLM (Day 155) without today's Hugging Face and local-inference fluency. This lesson turns "I've heard of Llama" into "I've run it, read its license, and know when to recommend it."

Guided practice

guided 1

Run an open model with transformers

25 min
  1. Install: pip install transformers torch (in your venv, Day 17 habits).
  2. Paste the starter. It loads a deliberately small instruct model (Qwen2.5-0.5B-Instruct, ~1GB download) so it runs on CPU.
  3. Note the two-artifact pattern: tokenizer AND model must match β€” this is Day 96 made operational.
  4. Run the same prompt at temperature 0.3 and 1.2 β€” confirm your Day-102 knobs are back in your hands.
  5. Time the generation with time.perf_counter and compute tokens/second. Write it down; you will compare against a hosted API on Day 107.
  6. Open the model's page on huggingface.co and read its model card: license, training summary, limitations. Note all three.
🐍 python β€” editable, runs in your browser
Ctrl/⌘+Enter runs · Tab indents · numpy/pandas/sklearn auto-load on import (torch and network calls need a local run)
guided 2

Ollama: local inference as a service

15 min
  1. Install Ollama (see the repo README for your OS) and pull a small quantized model: ollama run llama3.2:1b (or another ~1B model).
  2. Chat with it in the terminal; ask the same context-window question and compare quality to the transformers run.
  3. Ollama also serves a local REST API on port 11434. Hit it with curl or httpx (Day 41 payoff): POST to /api/generate with a JSON body containing model and prompt fields, and watch the streamed responses.
  4. Check the model file size on disk versus the parameter count. Compute bits per parameter and confirm you are looking at a ~4-bit quantized model.
  5. One-line note: what did Ollama abstract away compared to the transformers workflow?

On your own

The deployment-recommendation memo

20 min

Three clients, three recommendations. Write 3-4 sentences each, naming specific trade-off axes:

(1) A hospital network wants clinical-note summarization; patient data must never leave their datacenter, and they have budget for GPUs. (2) A 5-person startup prototyping a legal-research assistant, currently at ~200 requests/day, needs maximum answer quality. (3) A SaaS company runs 40M short classification calls/month on a frontier API and is bleeding money; tasks are narrow and well-defined.

Hints: (1) is a control/privacy story; (2) is a capability + zero-ops story β€” do not make them buy GPUs; (3) is the cost-shape crossover β€” a small open or distilled model on owned/rented infra, foreshadowing Day 129's selection matrix. State what you would verify before committing (license, eval on their data).

Ship before you stop

Model landscape worksheet

Create model-landscape.md: a comparison table of five models you researched today on the Hub or provider docs β€” at least two open (different license types) and one closed API model β€” with columns: params/tier, license, context length, instruct or base, where it can run, one sentence on when you would pick it. Below the table, record your measured local tokens/sec for both runs and the three client recommendations from practice. Commit it. Day 129 (model selection) and Day 170 (customer environments) both extend this worksheet.

Rubric β€” check what you completed (0/6)

Common mistakes & misconceptions

  • Treating "open" as one thing. Weights-available spans permissive Apache/MIT, conditional community licenses, and research-only releases β€” the license, not the download button, decides what a customer may ship.
  • Recommending self-hosting to save money at low volume. The cost crossover needs sustained utilization; idle GPUs are the most expensive way to serve 200 requests/day.
  • Loading a base model and judging it as a bad chatbot. Base models continue text (Day 100); grab the -Instruct variant for assistant behavior, and use the chat template.
  • Ignoring the tokenizer pairing. Loading model A with tokenizer B produces garbage β€” the vocabulary mapping is part of the model contract (Day 96).
  • Assuming quantization is free. 4-bit is remarkably good but not lossless; quality-sensitive workloads need evaluation at the target precision (Day 129).
  • Forgetting that APIs update models under stable-sounding names while self-hosted weights are frozen β€” pin versions and re-run evals on provider updates (Day 145).
Knowledge check

Q1. A customer with strict data-residency rules and steady high volume asks API vs self-hosted. The strongest self-hosting arguments are…

Q2. A 7B-parameter model file on disk is about 4.4GB. Its precision is roughly…

Q3. Why must you use apply_chat_template (or equivalent) with an instruct model?

Go deeper β€” curated resources

courseHugging Face LLM Course β€” using transformers & the Hub β†—30 minrepoOllama β€” repo, install & model library β†—20 mindocsClaude Docs β€” Models overview (the closed-API side of the wall) β†—10 minarticleChip Huyen β€” blog (open vs closed model economics posts) β†—15 min
If you have a third hour
  • Serve your transformers model behind FastAPI β€” Wrap today's pipeline in your Day-41 FastAPI skills: a /generate endpoint with a pydantic request model. This is a miniature of Day 155's serving lesson.
Done means
  • A real open model generated text on your machine via transformers
  • Ollama model pulled, chatted with, and hit via its REST API
  • Model card and license read and summarized for both models
  • Landscape worksheet committed with benchmarks and client memos
  • Quiz β‰₯ 2/3
How this connects

← Back: The chat template operationalizes Day 100's SFT format; the sampling flags you passed to generate() are Day 102's knobs; the tokenizer/model pairing is Day 96's lesson in production form.

Forward β†’: Day 106 crosses to the rented side of the wall β€” the Anthropic API. Day 128 fine-tunes an open model you can now run; Day 129 formalizes quantization and model selection; Day 155 serves open models properly with vLLM; Day 170 revisits all of this inside customer environments.

Unlocks: D129 Distillation, Quantization & Model Selection