Microsoft's Phi-2 Beats Models 25x Its Size on Reasoning
Microsoft's 2.7B parameter Phi-2 punches far above its weight, matching 13B and even 70B models on reasoning, math, and coding benchmarks.
ProTakeaways
- Phi-2 is a 2.7B parameter Microsoft small language model released under MIT license.
- Matches or beats Mistral 7B, Llama-2 13B and 70B on reasoning, math and coding.
- Scores 61.2% HumanEval, 59.2 BBH, 68.8 commonsense reasoning, 61.1 GSM8k.
- Trained on 1.4T tokens of textbook-quality synthetic plus filtered web data.
- Base model with no RLHF or instruction tuning, aimed at research and fine-tuning.
- Runs via transformers, vLLM, SGLang, Ollama on modest consumer GPUs.
Small language models have quietly become one of the most practical corners of the field, and Microsoft's Phi-2 remains a canonical example of why. The 2.7 billion parameter Transformer was built by Microsoft Research to test how far careful data curation can push a base model, and the numbers still hold up as a reference point for anyone building compact assistants, on-device features, or fine-tuning experiments.
A tiny model that keeps beating bigger ones
The headline claim is that size is not destiny. With only 2.7 billion parameters, Phi-2 surpasses Mistral and Llama-2 at 7B and 13B on various aggregated benchmarks, and beats the 25x larger Llama-2-70B on multi-step reasoning tasks like coding and math. It also matches or outperforms Google Gemini Nano 2 despite being smaller.
The concrete numbers give a good sense of where it lands:
- Big Bench Hard: 59.2 in 3-shot evaluation with chain-of-thought, against 40 to 47.8 for the 7B and 13B Llama-2 models.
- Commonsense reasoning: 68.8 averaged across PIQA, WinoGrande, ARC and SIQA, higher than the 62.2 to 69.2 range from 7B to 70B Llama-2.
- GSM8k grade-school math: 61.1, versus 16.5 to 64.1 for Llama-2 and 46.4 for Mistral.
- HumanEval Python coding: 61.2%, outperforming most 7B to 13B models.
The trick is the training data
Phi-2 is not a new architecture story. Under the hood sits a next-word-prediction Transformer with a 2048-token context window, trained on 1.4 trillion tokens using 96 A100-80G GPUs over 14 days. The interesting part is what those tokens were.
Microsoft focused on textbook-quality data, following on from their earlier Textbooks Are All You Need work. The training mixture contains synthetic datasets specifically created to teach common sense reasoning and general knowledge, including science, daily activities, and theory of mind, augmented with carefully selected web data filtered for educational value and content quality. The synthetic portion was generated with GPT-3.5 and GPT-4, and the filtered web data was drawn from Falcon RefinedWeb and SlimPajama.
The second lever is knowledge transfer. Microsoft used techniques to scale up from the 1.3 billion parameter Phi-1.5 and embed its knowledge inside the 2.7 billion parameter Phi-2, which both accelerates training convergence and produces a clear boost in benchmark scores. The result is a base model that skipped the usual finishing touches: Phi-2 reaches its scores without any reinforcement learning from human feedback or instructional fine-tuning.
Where it fits and where it does not
Phi-2 is best treated as a research and prototyping base rather than a finished chatbot. The model card is candid about the tradeoffs:
- It can generate inaccurate code and facts, so outputs should be treated as starting points.
- Its coding data is mostly Python with common packages like
typing,math,random,collections,datetime, anditertools. Other languages or libraries need manual verification. - Without instruction fine-tuning, it can struggle with nuanced multi-step prompts.
- It is primarily English and tends to be verbose, often producing extra text after its first answer because its training was textbook-like.
Getting it running is straightforward. It is integrated in transformers 4.37.0 and above, and works with vllm serve microsoft/phi-2 or SGLang for an OpenAI-compatible endpoint. A minimal snippet:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tok = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"microsoft/phi-2", torch_dtype="auto", device_map="auto", trust_remote_code=True
)
prompt = "Instruct: Write a Python function to check if a number is prime.\nOutput:"
out = model.generate(**tok(prompt, return_tensors="pt").to("cuda"), max_new_tokens=200)
print(tok.decode(out[0]))
One practical gotcha worth flagging: Phi-2 has a known attention overflow issue in FP16, and Microsoft recommends toggling autocast in PhiAttention.forward() if you hit it.
Why it still matters
Phi-2 is released under the MIT license, which is part of why it has become such a common base for experimentation. Hugging Face lists roughly 411 fine-tunes, nearly a thousand adapters, and 61 quantized variants derived from it, plus more than a hundred Spaces built on top. That ecosystem is the practical payoff of the release. If you are shipping an assistant that runs on modest hardware, studying alignment on a clean pretrained checkpoint, or benchmarking your own data recipe against a strong small baseline, Phi-2 remains an easy first stop before reaching for something ten times larger.