Phi Models › Phi-3: Quality Meets Scale
Language AI HandbookAll chapters Phi Models › Phi-3: Quality Meets ScaleOne section · Sections in this chapter6 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Phi-3, released in 2024, represents the maturation of the textbook-quality approach. With 3.8B parameters in the mini variant, it was trained on an unprecedented 3.3 trillion tokens of heavily filtered and synthetic data. Phi-3 closed the gap with much larger models across nearly all benchmarks.
Data Pipeline Innovations
The Phi-3 training pipeline incorporated several innovations:
- Multi-stage filtering: Multiple rounds of quality filtering using trained classifiers
- Diverse synthetic generation: Using multiple large models (not just GPT-4) to generate diverse content
- Domain coverage expansion: Systematic coverage of academic subjects, professional domains, and world knowledge
- Instruction tuning: Post-training alignment using synthetic instruction-response pairs
# Phi-3 training stages
phi3_stages = {
"Stage 1: Web Filtering": {
"input": "Raw web data",
"process": "Quality classifiers, deduplication",
"output": "~1T high-quality tokens",
},
"Stage 2: Synthetic Generation": {
"input": "Topic outlines, skill maps",
"process": "Multi-model generation, verification",
"output": "~500B synthetic tokens",
},
"Stage 3: Data Mixing": {
"input": "All filtered and synthetic data",
"process": "Curriculum-based mixing, repetition tuning",
"output": "3.3T training tokens",
},
"Stage 4: Instruction Tuning": {
"input": "Pre-trained model",
"process": "SFT + DPO alignment",
"output": "Phi-3-instruct variants",
},
}Phi-3 Training Pipeline ================================================================= Stage 1: Web Filtering ---------------------------------------- Input: Raw web data Process: Quality classifiers, deduplication Output: ~1T high-quality tokens Stage 2: Synthetic Generation ---------------------------------------- Input: Topic outlines, skill maps Process: Multi-model generation, verification Output: ~500B synthetic tokens Stage 3: Data Mixing ---------------------------------------- Input: All filtered and synthetic data Process: Curriculum-based mixing, repetition tuning Output: 3.3T training tokens Stage 4: Instruction Tuning ---------------------------------------- Input: Pre-trained model Process: SFT + DPO alignment Output: Phi-3-instruct variants
Phi-3 Model Variants
Phi-3 comes in multiple sizes to suit different deployment scenarios:
phi3_variants = {
"Phi-3-mini": {
"params": 3.8,
"context": 128000,
"target": "Edge devices, mobile",
},
"Phi-3-small": {
"params": 7,
"context": 128000,
"target": "Balanced performance",
},
"Phi-3-medium": {
"params": 14,
"context": 128000,
"target": "High performance",
},
}Phi-3 Model Variants ======================================================= Variant Parameters Context Target Use ------------------------------------------------------- Phi-3-mini 3.8 B 128,000 Edge devices, mobile Phi-3-small 7.0 B 128,000 Balanced performance Phi-3-medium 14.0 B 128,000 High performance

The 128K context length is notable, achieved through RoPE scaling techniques. Standard RoPE is trained for a fixed context length, but the frequencies can be adjusted to extrapolate to longer sequences. Phi-3 uses a technique where the base frequency is modified:
where is a scaling factor that stretches the rotational frequencies, letting the model to handle longer sequences than it was originally trained on. This allows Phi-3 models to process long documents, complete codebases, or extended conversations while maintaining their small footprint.
Phi-3 Performance
Phi-3-mini matches or exceeds much larger models on key benchmarks:
phi3_comparison = {
"MMLU": {
"Phi-3-mini (3.8B)": 68.8,
"Mixtral-8x7B (47B)": 70.6,
"GPT-3.5-turbo": 70.0,
"LLaMA-3-8B": 66.6,
},
"GSM8K": {
"Phi-3-mini (3.8B)": 82.5,
"Mixtral-8x7B (47B)": 74.4,
"GPT-3.5-turbo": 57.1,
"LLaMA-3-8B": 79.6,
},
"HumanEval": {
"Phi-3-mini (3.8B)": 58.5,
"Mixtral-8x7B (47B)": 40.2,
"GPT-3.5-turbo": 48.1,
"LLaMA-3-8B": 62.2,
},
}