← Back to Blog

Section 4: Fine-Tuning and Local Models

Know when to steer a hosted model with prompts and RAG, when to invest in parameter-efficient fine-tuning, and when to run open-weights models locally for privacy or cost control.

4.1 What Fine-Tuning Changes—and What It Does Not

  • Prompting: Steers behavior at inference time with zero weight changes. Fastest to iterate.
  • RAG: Injects external, dynamic, or private knowledge at query time. Best for factual grounding and fast-changing information.
  • Supervised Fine-Tuning (SFT): Teaches consistent task behavior, tone, strict formatting, domain jargon, or specialized tool-calling style—often letting a smaller, cheaper model match a larger model on a narrow task. It is a poor mechanism for memorizing frequently changing facts.
  • Continued Pretraining: Trains on massive unlabeled domain corpora to shift foundational language representation; expensive and rarely needed by application teams.

4.2 Data Preparation & Parameter-Efficient Fine-Tuning (PEFT)

Fine-tuning quality is governed by data quality, not just volume. Deduplicate examples, strip PII, balance edge cases (including abstentions), and lock a held-out evaluation split that never leaks into training.

  • LoRA (Low-Rank Adaptation): Freezes the base model weights and trains tiny low-rank adapter matrices injected into attention/projection layers—drastically cutting GPU memory and letting you swap lightweight task adapters atop one shared base model.
  • QLoRA (Quantized LoRA): Loads the frozen base model in 4-bit quantized precision while training LoRA adapters in higher precision, enabling fine-tuning on modest single-GPU hardware. Trade-off: can slightly trail full fine-tuning on complex reasoning, and still requires ongoing data curation and evaluation.

4.3 Running Models Locally with Ollama

Local inference is conceptually separate from fine-tuning: you can run an off-the-shelf open-weights model locally without fine-tuning it, or host a fine-tuned model in the cloud. Ollama provides a developer-friendly local runtime for pulling, quantizing, and serving open-weights models over a local HTTP API (localhost:11434).

Shell — Basic Local Model Workflow with Ollama
# Pull and interactively test an open-weights model locally
ollama pull llama3.2
ollama run llama3.2

# List installed models and call the local HTTP endpoint
ollama list
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [{"role": "user", "content": "Explain hybrid search in 2 sentences."}],
  "stream": false
}'

Key Local Serving Trade-Offs: Keeps sensitive data on-device or inside an air-gapped VPC and eliminates per-token API fees. However, it shifts operational burden onto you: VRAM/RAM sizing (a 4-bit quantized 8B model typically needs ~6–8 GB RAM/VRAM, whereas 70B models need ~40+ GB), lower peak reasoning capability than frontier cloud models, and concurrency scaling (where production teams often graduate to vLLM or TGI).

4.4 Decision Matrix: Prompting vs. RAG vs. Fine-Tuning vs. Local Inference

Approach Primary Problem Solved Best When... Avoid When...
Prompting Task steering & reasoning structure Starting out, iterating fast, general instructions suffice Context exceeds window or strict latency/cost demands a tiny model
RAG Up-to-date, private, citable knowledge Facts change frequently; citations & ACL permissions are required The issue is output style/format rather than missing facts
Fine-Tuning (LoRA/QLoRA) Consistent style, narrow skill, latency/cost compression You have 100s–1,000s of verified examples and want a small model to excel at a fixed task You need to inject changing facts or lack a held-out eval dataset
Local Inference (Ollama/vLLM) Data residency, zero per-token API cost, offline use Strict privacy/VPC rules, offline dev, predictable GPU capacity You need frontier reasoning immediately without managing GPU ops