AiTechWorlds
AiTechWorlds
Side-by-side comparison of prompt engineering, LoRA fine-tuning, and RLHF/DPO β when to use each and full code examples.
When you need an LLM to do something specific, you have three main levers:
1. Prompt Engineering β craft the input to guide the model
2. Fine-Tuning β train the model further on your data
3. RLHF β align the model to human preferences via reward modeling
Each approach has a different cost, complexity, and effectiveness ceiling.
| Factor | Prompt Engineering | Fine-Tuning | RLHF |
|---|---|---|---|
| Cost | Free / API cost only | $10β$10,000+ | $100,000+ |
| Data needed | None | 100β100K examples | Human feedback pairs |
| Technical skill | Low | Medium | Very high |
| Latency | No change | No change | No change |
| Reversibility | Instant | Requires retraining | Requires retraining |
| Output consistency | Variable | High | Very high |
| Best for | Iteration, prototyping | Domain adaptation | Safety and alignment |
Writing system prompts, few-shot examples, and instruction structures that guide the base model's output without changing its weights.
| Technique | When to Use |
|---|---|
| Zero-shot | Simple, clear tasks |
| Few-shot | Format consistency, classification |
| Chain-of-thought (CoT) | Multi-step reasoning |
| Role prompting | Tone/persona control |
| Structured output (JSON) | Downstream parsing |
| Retrieval augmentation | Grounding responses in facts |
Continuing training on a pre-trained LLM using your own supervised dataset. The model's weights are updated to produce outputs matching your examples.
| Type | How It Works | Data Needed |
|---|---|---|
| Full fine-tuning | Update all weights | 10Kβ1M examples |
| LoRA (Low-Rank Adaptation) | Add small adapter layers, freeze base | 100β10K examples |
| QLoRA | LoRA on quantized (4-bit) model | 100β10K examples |
| Instruction tuning | Fine-tune on instruction-response pairs | 1Kβ100K examples |
| Domain adaptation | Fine-tune on domain corpus | 1M+ tokens |
# Standard layer: W is frozen
output = x @ W
# LoRA: train only A and B (small matrices)
output = x @ W + x @ (A @ B) * scale
# W shape: (d_in, d_out) β frozen
# A shape: (d_in, r), B shape: (r, d_out) β trainable
# r (rank) is typically 8, 16, or 64A three-phase process that aligns a model to human preferences, used to create the instruct/chat versions of GPT, Claude, and LLaMA.
Fine-tune the base model on human-written demonstrations.
Human annotators compare model outputs and rank them. A separate model is trained to predict these rankings β the reward model.
Use the reward model as a signal for RL (Proximal Policy Optimization) to update the LLM toward higher-reward outputs.
# DPO skips the explicit reward model
# Train directly on (preferred, rejected) response pairs
# Loss: maximize probability of preferred, minimize rejected
loss = -log(Ο(Ξ² * log(Ο_ΞΈ(y_w)/Ο_ref(y_w)) - Ξ² * log(Ο_ΞΈ(y_l)/Ο_ref(y_l))))DPO is now preferred over PPO-RLHF for most alignment tasks β simpler, stabler, and comparable quality.
Need to guide an existing capable model?
ββ Try prompt engineering first (zero cost)
Model is capable but inconsistent in format/style?
ββ Fine-tune with LoRA (100-1K examples often enough)
Model lacks domain knowledge?
ββ RAG for factual queries OR domain fine-tuning for reasoning
Need safety, refusal, and alignment?
ββ RLHF/DPO at scale (requires significant resources)
Need smallest possible model for edge deployment?
ββ Fine-tune + quantize (QLoRA β GGUF/ONNX)| Stage | Tool |
|---|---|
| Prompt testing | OpenAI Playground, PromptFlow, LangSmith |
| Fine-tuning | Hugging Face TRL, LLaMA-Factory, Axolotl |
| LoRA/QLoRA | peft library (HuggingFace) |
| DPO | HuggingFace TRL DPOTrainer |
| Reward models | trl + custom preference datasets |
Advertisement
Get more notes like this daily on Telegram!
Free study notes, cheat sheets & AI tips
Last reviewed on June 13, 2026 by the AiTechWorlds Notes Team. Free cheat sheet β no signup required.
Advertisement
Join AiTechWorlds on Telegram and get daily AI tips, prompt engineering templates, coding resources, and exclusive content β 100% free!
No spam. Leave anytime.