★ Reading this for free? Get 25 structured AI courses + per-chapter AI tutor — the first chapter of every course free, no card.Start free in 30 secondsOr own every course: $149 once
Models

Phi-4 14B Local Setup Guide: Microsoft's Reasoning Model on 12GB GPUs and Macs

May 1, 2026
22 min read
Barsha Mohapatra

Want to go deeper than this article?

Free account unlocks the first chapter of all 25 courses — RAG, agents, MCP, voice AI, MLOps, real GitHub repos.

📚AI Learning Path

Go from reading about AI to building with AI 25 structured courses. Hands-on projects. Runs on your machine. Start free.

Start free
Or own it for life — Lifetime $149, pay once

Phi-4 is Microsoft's December 2024 release of their efficient-LLM family — a 14.7B-parameter model trained on heavily curated synthetic and academic data rather than raw web crawl. The result: on Microsoft's published numbers, a MATH score above Meta's published figure for Llama 3.1 70B, from a model whose default Ollama build is a 9.1 GB file that fits a 12 GB consumer GPU. MIT licensed for unrestricted commercial use. For users who want strong reasoning capability without the VRAM cost of 70B-class models, Phi-4 is one of the best 14B-class options in 2026.

This guide covers the full Phi-4 family (base 14B, mini 3.8B, multimodal 5.6B), setup across Ollama / vLLM / llama.cpp, prompting techniques for reasoning workloads, fine-tuning with QLoRA / Axolotl / Unsloth, and published benchmark scores vs Llama 3.1 8B / Qwen 2.5 14B / DeepSeek-R1, with every speed given as a labelled bandwidth ceiling.

Table of Contents

  1. What Phi-4 Is
  2. The Phi-4 Family: Base, Mini, Multimodal
  3. What Makes Phi-4 Different (Synthetic Data)
  4. Hardware Requirements & Quantization
  5. Phi-4 vs Llama 3.1 8B vs Qwen 2.5 14B vs DeepSeek-R1
  6. Ollama Setup
  7. llama.cpp Setup with GGUF
  8. vLLM Setup
  9. LM Studio / oobabooga / KoboldCpp
  10. Phi-4-mini for Edge Devices
  11. Phi-4-multimodal for Vision + Audio
  12. System Prompts & Sampling
  13. Reasoning Tasks: Math, Code, Logic
  14. Fine-Tuning with QLoRA
  15. Function Calling and Structured Output
  16. Tuning Recipes by GPU
  17. Published Benchmarks and Speed Ceilings
  18. Licensing
  19. Troubleshooting
  20. FAQ

Reading articles is good. Building is better.

Free account = the first chapter of all 25 courses, with a per-chapter AI tutor. No card.

What Phi-4 Is

Phi-4 (microsoft/phi-4 on HuggingFace) is the December 2024 release of Microsoft's Phi family. Architecture: dense decoder-only transformer with 14.7B parameters, 16K context, a ChatML-style chat template. Trained on 9.8T tokens; released December 12, 2024 (per the model card). License: MIT — most permissive of recent major releases.

The Phi family thesis: small, well-trained models on curated data beat larger models on reasoning. Phi-4 is the best demonstration to date.


The Phi-4 Family: Base, Mini, Multimodal

VariantParametersContextVRAM (BF16 / Q4)Use
Phi-4 (base 14B)14.7B16K30 GB / 9 GBReasoning, math, code
Phi-4-mini (3.8B)3.8B128K8 GB / 2.5 GBEdge, mobile, real-time
Phi-4-multimodal (5.6B)5.6B128K12 GB / 4 GBVision + audio + text
Phi-4-mini-instruct3.8B128K8 GB / 2.5 GBMini for chat
Phi-3.5-MoE (legacy)42B total, 6.6B active (16 experts)128K~84 GB / ~25 GBMoE option

For most users the base 14B Phi-4 is the right starting point.


What Makes Phi-4 Different (Synthetic Data)

Most LLMs train on web crawl (Common Crawl, Reddit, books). Phi family trains primarily on:

  • Synthetic textbooks generated by larger models with verification
  • Academic papers with chain-of-thought reasoning
  • Curated code from filtered GitHub
  • Math problem sets with verified solutions
  • Synthetic dialogues for instruction tuning

Smaller training corpus (9.8T tokens per the model card, vs 15T+ for Llama 3.1) but much higher data density. Result: better reasoning per parameter, weaker on raw knowledge breadth (less factual world coverage than Llama).


Own it instead of renting it

Run this on your own machine and stop paying every month

Pay once and keep it. No renewal, no per-token bill, and nothing you feed it ever leaves your hardware.

Hardware Requirements & Quantization

GPU VRAMPhi-4 QuantFile sizeBandwidth ceiling on RTX 4090
8 GBQ3_K_M (low quality)7.4 GB~137 tok/s ceiling (tight fit on 8 GB)
10 GBQ4_K_S8.4 GB~119 tok/s ceiling
12 GBQ4_K_M (phi4:14b) / Q5_K_S9.1 / 10.2 GB~111 / ~99 tok/s ceiling
16 GBQ5_K_M / Q6_K10.6 / 12.0 GB~95 / ~84 tok/s ceiling
24 GBQ8_0 (phi4:14b-q8_0) / FP1616 / 29 GB~63 tok/s ceiling / FP16 does not fit

File sizes: Ollama's phi4 tag list for Q4_K_M, Q8_0 and FP16; bartowski/phi-4-GGUF on Hugging Face for the other quants. The speed column is a ceiling, not a measurement: NVIDIA lists the RTX 4090 at 1,008 GB/s of memory bandwidth, and a dense model reads its whole weight file once per generated token, so 1,008 ÷ file size is the most it can produce. Real generation lands below that and falls as the context grows. On an RTX 3060 12GB (360 GB/s) the same Q4_K_M file has a ~40 tok/s ceiling; on an RTX 4070 (504 GB/s), ~55.

For most 12-16 GB consumer GPUs: Q5_K_M is the sweet spot. For RTX 4090 24 GB: Q8_0 if you want highest fidelity, or use the freed VRAM for longer context.


Phi-4 vs Llama 3.1 8B vs Qwen 2.5 14B vs DeepSeek-R1

BenchmarkPhi-4 14BLlama 3.1 8BQwen 2.5 14BLlama 3.1 70BDeepSeek-R1
MMLU84.873.0 (CoT)79.986.0 (CoT)90.8
GSM8K (math)not published84.5not published95.1not published
MATH80.451.975.668.097.3 (MATH-500)
HumanEval (code)82.672.672.180.5not published
MMLU-Pro70.448.363.266.484.0
GPQA56.130.442.946.771.5 (Diamond)
AIME 2024not publishednot publishednot publishednot published79.8
Speed ceiling, RTX 4090 (Ollama Q4_K_M file)~111 tok/s (9.1 GB)~206 tok/s (4.9 GB)~112 tok/s (9.0 GB)does not fit 24 GBMoE, no figure
Context length16K128K128K128K128K

Where the numbers come from: Phi-4 and Qwen 2.5 14B Instruct are from Microsoft's Phi-4 model card and technical report (one harness for both); Llama 3.1 8B and 70B Instruct from Meta's Llama 3.1 model card; DeepSeek-R1 from DeepSeek's R1 paper. Different labs use different prompts and shot counts, so compare within a column family, not to the decimal across them. "Not published" means the source for that column gives no figure. The speed row is a bandwidth ceiling (1,008 GB/s ÷ file size), not a measurement.

For everyday math/code/reasoning on a 12-16 GB card: Phi-4 is the strongest scorer per GB on these tables. For competition math: DeepSeek-R1. For long-context: Llama / Qwen. For code specifically: Qwen 2.5 Coder 14B.


Ollama Setup

# Pull Phi-4 14B
ollama pull phi4

# Or a specific quant from the Ollama library (q4_K_M is the default)
ollama pull phi4:14b-q8_0

# Q5_K_M is not in the Ollama library; pull the GGUF straight from Hugging Face
ollama pull hf.co/bartowski/phi-4-GGUF:Q5_K_M

# Run
ollama run phi4 "Solve: integral of sin(x)*e^x dx, show work."

Ollama Modelfile customization:

FROM phi4
PARAMETER num_ctx 16384
PARAMETER temperature 0.4
PARAMETER min_p 0.05
PARAMETER repeat_penalty 1.05
SYSTEM """You are a precise reasoning assistant. Show your work step by step."""

llama.cpp Setup with GGUF

# Download Q5_K_M from bartowski's quants
huggingface-cli download bartowski/phi-4-GGUF \
    phi-4-Q5_K_M.gguf \
    --local-dir ./models

./llama-cli \
    -m models/phi-4-Q5_K_M.gguf \
    -ngl 999 \
    -c 16384 \
    -fa \
    --temp 0.4 \
    --min-p 0.05 \
    -p "Solve this step by step: ..."

For server mode:

./llama-server -m phi-4-Q5_K_M.gguf -ngl 999 -c 16384 --port 8080

vLLM Setup

# BF16 (needs 32+ GB VRAM)
vllm serve microsoft/phi-4 \
    --max-model-len 16384 \
    --gpu-memory-utilization 0.92

# AWQ-INT4 (12+ GB VRAM): pick any phi-4 AWQ build on the Hugging Face hub
vllm serve <hf-user>/phi-4-awq \
    --quantization awq \
    --max-model-len 16384

For high-throughput serving, see vLLM Complete Setup Guide.


LM Studio / oobabooga / KoboldCpp

All major desktop UIs support Phi-4:

  • LM Studio: search "phi-4" in the model browser, download Q5_K_M, click Load
  • oobabooga: download GGUF, place in models/, llama.cpp loader
  • KoboldCpp (flags checked against v1.124.2, October 31, 2026): ./koboldcpp --model phi-4-Q5_K_M.gguf --usecuda --contextsize 16384 on NVIDIA, or --usevulkan on AMD/Intel; Metal is automatic on Apple Silicon. --usecuda is the current name (--usecublas still works as an alias), GPU layers default to autofit, and 16384 matches Phi-4's 16K context window.

See text-generation-webui guide and KoboldCpp guide.


Phi-4-mini for Edge Devices

Phi-4-mini (3.8B) is designed for tight resource budgets:

ollama run phi4-mini

The one speed we have measured ourselves: phi4-mini (Q4_K_M, 2.49 GB) generated a median 43.7 tok/s on an Apple M3 Pro with 18 GB, Ollama 0.40.13, 2 November 2026, against a 60 tok/s bandwidth ceiling (150 GB/s ÷ 2.49 GB). Other machines will differ.

Use cases:

  • Mobile via MLC-LLM (Android / iOS)
  • Browser via WebLLM
  • Raspberry Pi 5 for offline assistants (CPU-only, so expect single-digit speeds)
  • Embedded systems for on-device reasoning

Phi-4-mini is also the member of the family that supports function calling; Ollama lists phi4-mini with the tools capability.

128K context window is unusually long for a 3.8B model — useful for RAG over long documents on edge devices.


Phi-4-multimodal for Vision + Audio

from transformers import AutoModelForCausalLM, AutoProcessor

model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-4-multimodal-instruct",
    torch_dtype="auto",
    device_map="cuda",
    trust_remote_code=True,
)

processor = AutoProcessor.from_pretrained("microsoft/Phi-4-multimodal-instruct", trust_remote_code=True)

# Vision input
inputs = processor(
    images=[image],
    text="<|user|>\n<|image_1|>\nDescribe this image.<|end|>\n<|assistant|>",
    return_tensors="pt",
).to("cuda")

# Audio input similarly with audio_1 tag

For pure vision use cases, Llama 3.2 11B Vision and Qwen 2-VL 7B are stronger; Phi-4-multimodal's strength is doing all three modalities in one small model.


System Prompts & Sampling

ChatML-style format with Phi-4's separator token (from the model card):

<|im_start|>system<|im_sep|>You are a precise reasoning assistant.<|im_end|>
<|im_start|>user<|im_sep|>[user message]<|im_end|>
<|im_start|>assistant<|im_sep|>

Recommended sampling:

  • Reasoning / math / code: temperature 0.0-0.3, min-p 0.05, no top-k
  • Chat / general: temperature 0.5-0.7, min-p 0.05
  • Creative writing: temperature 0.8-1.0, min-p 0.05

See LLM Sampling Parameters for full sampler reference.


Reasoning Tasks: Math, Code, Logic

For best reasoning output, use chain-of-thought prompting:

Solve this step by step. Show your work.

Problem: ...

Solution:

Or system-level CoT:

<|im_start|>system<|im_sep|>For every problem, work through the solution step by step before providing the final answer.<|im_end|>

Phi-4 was trained to produce CoT-style reasoning natively; it usually does this without explicit prompting.

For competition-grade math (AIME, Olympiad), use DeepSeek-R1-Distill variants — they outperform Phi-4 on hard problems with test-time compute.


Fine-Tuning with QLoRA

Using Unsloth (fastest):

from unsloth import FastLanguageModel
from datasets import load_dataset

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/phi-4-bnb-4bit",
    max_seq_length=4096,
    load_in_4bit=True,
)

model = FastLanguageModel.get_peft_model(
    model,
    r=32, lora_alpha=32, lora_dropout=0,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
)

# Train on your dataset

The 4-bit base fits a single 24 GB card; training time depends on sequence length, epochs and dataset size, so time a short run on your own data first. MIT license means fine-tuned derivatives can be redistributed without restriction.

See LoRA Fine-Tuning Local Guide.


Function Calling and Structured Output

The 14B Phi-4 model card documents no native tool-calling format, and Ollama's phi4 build carries no tools capability. If you need function calling, use phi4-mini (Ollama lists it with tools) or serve Phi-4 behind vLLM with a custom tool-call parser and --enable-auto-tool-choice. The request shape is the OpenAI one:

{
  "model": "phi-4",
  "messages": [...],
  "tools": [{"type": "function", "function": {...}}],
  "tool_choice": "auto"
}

For JSON mode constrained output, use response_format:

{"response_format": {"type": "json_schema", "json_schema": {...}}}

vLLM uses xgrammar for guaranteed schema-valid output.


Tuning Recipes by GPU

RTX 3060 12GB / RTX 4070 (12 GB)

ollama run phi4:14b-q4_K_M
# Or via Modelfile: Q4_K_M, num_ctx 8192, temperature 0.4

RTX 4070 / 4080 (16 GB)

Q5_K_M, num_ctx 16384.

RTX 4090 / 5090 (24-32 GB)

Q8_0 or FP16, full 16K context, batch multiple users via vLLM.

Mac M2 / M3 / M4

Q4_K_M (phi4:14b, 9.1 GB) via Ollama Metal fits a 16 GB Mac, which lets the GPU address roughly 11 GB. Bandwidth ceilings for the 9.1 GB file, from Apple's published bandwidth: ~13 tok/s on a base M4 (120 GB/s), ~16 on an M3 Pro (150 GB/s), ~22 on an M1/M2 Pro (200 GB/s), ~44 on an M1/M2 Max (400 GB/s).


Published Benchmarks and Speed Ceilings

Scores as published by each model's maker (Phi-4 and Qwen 2.5 14B from Microsoft's Phi-4 report; Llama 3.1 8B from Meta's model card). Speeds are bandwidth ceilings for the Q5_K_M GGUF on an RTX 4090 (1,008 GB/s ÷ file size), not runs we did.

TestPhi-4 14BLlama 3.1 8BQwen 2.5 14B
GSM8Knot published84.5%not published
MATH80.4%51.9%75.6%
HumanEval82.6%72.6%72.1%
MMLU84.8%73.0% (CoT)79.9%
Speed ceiling, Q5_K_M on RTX 4090~95 tok/s (10.6 GB)~177 tok/s (5.7 GB)~96 tok/s (10.5 GB)

Phi-4 reads almost twice the weights per token that Llama 3.1 8B does, so its ceiling is roughly half; on these published scores it answers math and code correctly more often, which is the trade.


Licensing

MIT license — most permissive among recent major model releases. You can:

  • Use commercially without restriction
  • Modify and redistribute
  • Bundle into proprietary products
  • Sell as paid service
  • Train derivative models without restriction

Compare to Llama 3.1 (Meta Llama Community License with monthly active user thresholds), Qwen 2.5 (Tongyi Qianwen License with EU restrictions). For strictest commercial cleanliness, Phi-4 is the safest choice.


Troubleshooting

SymptomCauseFix
Wrong chat formatMissing ChatML tokensUse Modelfile / config that loads phi-4 template
Repetitive outputNo min-pSet min-p 0.05
Verbose / over-explainsNo system promptAdd "be concise" to system
OOMContext too long16K max for Phi-4; lower if needed
Slow on MacM1 baseUse Phi-4-mini instead
Worse than Llama on chatPhi-4 is reasoning-tunedUse Llama for chat, Phi-4 for math/code

FAQ

See answers to common Phi-4 questions below.


Sources: Phi-4 on Hugging Face | Phi-4 technical report | Microsoft Research | bartowski quants | Ollama phi4 tags | Llama 3.1 model card | DeepSeek-R1 paper. Speeds are bandwidth ceilings except the one measured phi4-mini row (Apple M3 Pro).

Related guides:

🎯
AI Learning Path

Go from reading about AI to building with AI

25 structured courses. Hands-on projects. Runs on your machine. Start free.

Or own it for life — Lifetime $149 $599, pay once

Liked this? 25 full AI courses are waiting.

From fundamentals to RAG, agents, MCP servers, voice AI, and production deployment with real GitHub repos. First chapter free, every course.

Reading now
Join the discussion
Tagsphi-4microsoft phireasoning14b modellocal llm setupmit license

Barsha Mohapatra

Local AI Master writes hands-on courses and hardware guides for running AI on machines you own. Content is checked against current releases and corrected when readers tell us it is wrong.

Build Real AI on Your Machine

RAG, agents, NLP, vision, and MLOps - chapters across 25 courses that take you from reading about AI to building AI.

Want the structured version?

Hands-on courses on local AI, from $8.99 a month. The first chapter of each is free.

AI Learning Path
More on Local AI Hardware
See the full AI Hardware Guide 2026 guide.

Comments (0)

No comments yet. Be the first to share your thoughts!

📅 Published: May 1, 2026🔄 Last Updated: November 2, 2026✓ Manually Reviewed

Bonus kit

Ollama Docker Templates

10 one-command Docker stacks. Includes Phi-4 + Open WebUI reasoning assistant deploy. Included with paid plans, or free after subscribing to both Local AI Master and Little AI Master on YouTube.

See Plans →

Build Real AI on Your Machine

RAG, agents, NLP, vision, and MLOps - chapters across 25 courses that take you from reading about AI to building AI.

Was this helpful?

Barsha Mohapatra

Written by

Barsha Mohapatra

Founder and Editor, Local AI Master · Founder, Little AI Master

Founder of Little AI Master and the editor behind every course and guide on Local AI Master. Years of tutoring students taught her where AI education actually fails.

📚
Free · no account required

Grab the AI Starter Kit — career roadmap, cheat sheet, setup guide

No spam. Unsubscribe with one click.

🎯
AI Learning Path

Go from reading about AI to building with AI

25 structured courses. Hands-on projects. Runs on your machine. Start free.

Or own it for life — Lifetime $149 $599, pay once
Free Tools & Calculators