01. Why Fine-Tune?
Large language models arrive pre-trained on massive text corpora containing billions of tokens. This pre-training teaches the model statistical patterns, grammar, world knowledge, and reasoning capabilities. However, the model's behavior reflects the aggregate patterns of its training data, not the specific requirements of any particular use case. A model trained on internet text may generate responses with incorrect formatting, unexpected tone, or factual inaccuracies on domain-specific topics.
Fine-tuning addresses this gap by continuing the training process on data specific to the target application. Instead of training every parameter in the model (full fine-tuning), parameter-efficient techniques modify only a small subset of weights while preserving the vast majority of pre-trained knowledge. This approach offers several advantages: reduced computational cost, lower memory requirements, faster iteration cycles, and the ability to maintain multiple specialized adapters for different tasks without storing complete model copies.
The decision to fine-tune versus prompting typically depends on three factors. First, consistency requirements: fine-tuned models produce more uniform outputs across diverse inputs. Second, data availability: fine-tuning requires labeled examples specific to the target behavior. Third, deployment constraints: adapters add minimal latency and memory overhead compared to extensive prompt engineering at inference time.
For many practical applications, fine-tuning achieves capabilities that are difficult or impossible to replicate through prompting alone. Teaching a model a specific output format, adapting it to a particular writing style, or calibrating its behavior on domain-specific classification tasks often requires direct parameter adjustment.
Generate a prompt that tries to elicit consistent JSON output from an instruction-tuned model using only prompting techniques. Observe the failure modes when input variations occur. Document findings as baseline comparison for later fine-tuning experiments.
# baseline_prompt_test.py
import json
def test_json_consistency(model, test_cases):
"""Test JSON output consistency across varied inputs."""
results = []
for case in test_cases:
prompt = f"Extract the name and age: {case['input']}"
response = model.generate(prompt)
try:
parsed = json.loads(response)
results.append({"success": True, "parsed": parsed})
except json.JSONDecodeError:
results.append({"success": False, "raw": response})
return results