Running a model on your own machine vs calling an API
Lesson opener
In one line: Local means you load weights on hardware you control; API means you send bytes to someone else's hardware — pick with RAM, privacy, and who wakes up at 2 a.m.
Why it matters: A Chennai hospital that sends discharge summaries to a public API, or a startup that buys a GPU for a 20-row-a-day classifier, picked the place before the ticket.
Before this lesson: Free tiers vs paid vs API.
Before you start
| Resource | Link |
|---|---|
| Previous | Free tiers vs paid vs API |
| Next | Evaluate for your task |
| Prerequisites | aim4 |
| Time | ~50 minutes |
What you will learn
By the end of this lesson you will be able to:
- Contrast local load vs remote call in one sentence each.
- List what local needs (RAM / VRAM, engine, licence file).
- List what API needs (key, region, DPA, retry).
- Decide from constraints without naming a brand.
- Refuse local when VRAM is short, and refuse API when data must not leave.
- Stop cost: power off the GPU box, or revoke the key and stop the job.
Two places the weights live
| Place | You send | You run | You pay |
|---|---|---|---|
| Local | nothing off-box (if the box is yours) | engine + weights | hardware, power, people |
| API | the prompt (and maybe files) | a client | tokens / requests |
Local is not automatically private (a laptop can still sync a folder). API is not automatically leaky (a private region plus a DPA can be acceptable). Write the constraint, then pick.
WHY "We will just host it" without VRAM is a stalled laptop. "We will just call the API" without a region is an InfoSec reject.
WHEN After you know the job (aim1) and the pay shape (aim4).
Cost. A local GPU that stays on overnight is a power and cloud-VM bill. An API key in a cron job is a token bill. Stop: deallocate or shut the box; revoke the key and disable the cron.
This lesson does not download weights and does not call a network. The blocks decide.
Constraints that actually decide
| Constraint | Tips toward |
|---|---|
| Data must stay on the laptop / VPC | local (or a private-region API you have in writing) |
| No GPU, 8 GB RAM, 7B-class card | API, or a tiny local model after a fit check |
| 2 a.m. pages nobody can restart | API with a vendor SLA, or local with an on-call |
| Burst of 100k rows this week | API or a rented GPU, not a quiet laptop |
| Licence forbids hosting | API only |
Demo 1 — Place from constraints
def pick_place(ticket: dict) -> str:
if ticket.get("must_stay_on_box"):
if ticket.get("vram_ok"):
return "local"
return "refuse-local-no-vram"
if ticket.get("no_key_allowed"):
return "refuse-api-no-key-policy"
return "api"
print(pick_place({"must_stay_on_box": True, "vram_ok": True}))
print(pick_place({"must_stay_on_box": True, "vram_ok": False}))
print(pick_place({"must_stay_on_box": False, "no_key_allowed": False}))
assert pick_place({"must_stay_on_box": False, "no_key_allowed": True}) == "refuse-api-no-key-policy"Expected output:
local
refuse-local-no-vram
apiDemo 2 — Fit a 7B-class file
A rough planning rule (not a vendor spec): 16-bit weights need about 2 GB per billion parameters, plus overhead for the engine and the context. If the card says 7B at 16-bit, plan more than 14 GB VRAM. Quantised files use less; measure after load.
def vram_fit(params_b: float, bytes_per_param: float, overhead_gb: float, vram_gb: float) -> str:
need = params_b * bytes_per_param + overhead_gb
return "ok" if need <= vram_gb else "refuse-too-big"
print(round(7 * 2 + 2, 1))
print(vram_fit(7, 2.0, 2.0, 24.0))
print(vram_fit(70, 2.0, 4.0, 24.0))
assert vram_fit(7, 2.0, 2.0, 16.0) == "ok"Expected output:
16.0
ok
refuse-too-bigDemo 3 — Stop each place
def stop_place(place: str) -> str:
if place == "local":
return "unload-and-power-off-or-deallocate"
if place == "api":
return "revoke-key-and-stop-job"
return "unknown"
print(stop_place("local"))
print(stop_place("api"))
assert stop_place("local").startswith("unload")Expected output:
unload-and-power-off-or-deallocate
revoke-key-and-stop-jobGuided practice: private data, small GPU
def pick_place(ticket: dict) -> str:
if ticket.get("must_stay_on_box"):
if ticket.get("vram_ok"):
return "local"
return "refuse-local-no-vram"
if ticket.get("no_key_allowed"):
return "refuse-api-no-key-policy"
return "api"
print(pick_place({"must_stay_on_box": True, "vram_ok": False}))
assert pick_place({"must_stay_on_box": True, "vram_ok": False}) == "refuse-local-no-vram"Expected output:
refuse-local-no-vramThe next move is not "send it to a public tab." It is a smaller local model, a quantised file, or a written private-region API.
Independent practice: 8-bit 7B on 12 GB
Deliverable: 8-bit is 1 byte per parameter. Print the fit result.
def vram_fit(params_b: float, bytes_per_param: float, overhead_gb: float, vram_gb: float) -> str:
need = params_b * bytes_per_param + overhead_gb
return "ok" if need <= vram_gb else "refuse-too-big"
print(vram_fit(7, 1.0, 2.0, 12.0))
assert vram_fit(7, 1.0, 2.0, 12.0) == "ok"Expected output:
okCommon mistake
The deliberate mistake
Symptom: the laptop fans scream, then the process is killed, then someone pastes the same prompt into a consumer tab.
Diagnosis: VRAM was never checked; the fallback ignored privacy.
Correction: fit the file first. If it does not fit, change the file or the place in writing, not in a panic paste.
Prevention: run
vram_fiton the card before download. Keep customer text out of consumer tabs.
Snapshot — checked September 2026
Engines and cards move. Confirm the current install docs.
- Common local engines: llama.cpp, Ollama, vLLM, Hugging Face Transformers. Each has its own quant formats.
- Common API hosts: OpenAI platform, Anthropic API, Google AI Studio / Vertex, Azure OpenAI, AWS Bedrock, plus open-weight hosts that still meter.
- A 7B 4-bit file often fits in 8 GB class cards; a 70B 16-bit file does not. Measure after load.
- Cloud GPU list prices and consumer-GPU stock change. They are not in the quiz.
Where this connects
What you can now do:
- Pick local vs API from constraints.
- Fit a parameter count to VRAM.
- Name how to stop each place.
Next lesson: Evaluate for your task. Twenty examples beat a screenshot of a leaderboard.