How to Run Phi-4 Locally with Ollama (Setup and Usage Guide)

Phi-4 is Microsoft’s answer to a deceptively simple question: how capable can a small model get? At 14 billion parameters, it competes with — and often beats — models two to four times its size on reasoning and coding benchmarks. On a Mac with 16GB unified memory or a PC with a decent GPU, Phi-4 runs fast and fits comfortably. It’s one of the most interesting models you can run locally right now.

This guide covers pulling Phi-4 with Ollama, what it’s actually good at, how it compares to larger alternatives, and how to get the best out of it.

Pulling and Running Phi-4

Phi-4 is in the Ollama library under the name phi4:

ollama run phi4

This pulls the default 14B Q4 quantized version — around 8.9GB. Download time depends on your connection; on a decent broadband line you’re looking at 10–20 minutes. Once downloaded, the model loads in about 15–20 seconds on a mid-range machine.

You can also pull without running:

ollama pull phi4

There’s currently one primary Phi-4 size in the Ollama library (14B). Microsoft also released Phi-4-mini (3.8B) which is available as:

ollama pull phi4-mini

The mini is worth knowing about — at 3.8B it runs on almost any hardware including 8GB RAM machines, and it punches above its weight class for simple reasoning and Q&A tasks.

What Makes Phi-4 Different

Most LLMs are trained on internet-scale text scraped from the web. Phi-4 took a different approach: Microsoft trained it heavily on synthetic data — carefully generated, high-quality text created specifically for training rather than scraped from wherever. The idea is that quality of training data matters more than quantity, and that a 14B model trained on exceptional data can outperform a 70B model trained on noisier data for specific task types.

The results back this up on structured tasks. Phi-4 is notably strong at:

Mathematical reasoning. On MATH and competition-level math benchmarks, Phi-4 scores higher than Llama 3.1 70B. For a 14B model, this is remarkable. If you’re using a local LLM for any kind of quantitative reasoning, structured problem-solving, or step-by-step mathematical work, Phi-4 is worth trying before reaching for a much larger model.

Logical reasoning and puzzles. It handles multi-step logical deduction, constraint satisfaction problems, and analytical reasoning better than most models its size. The synthetic training data appears to have pushed it toward careful, structured thinking.

Code generation. Python, JavaScript, and common algorithmic problems come out clean. It’s not as strong as a dedicated coding model like Qwen 2.5 Coder on pure code benchmarks, but it holds its own and the code explanations are particularly good.

Instruction following. Phi-4 follows multi-part instructions more reliably than many larger models. If your prompts have several specific constraints, it tends to respect all of them rather than selectively ignoring the less common ones.

Hardware Requirements and Performance

At Q4 quantization, the 14B model needs about 10–11GB of memory to run. In practice:

Mac with 16GB unified memory: Runs smoothly — about 5–6GB free for macOS after the model loads. Expect 30–45 tokens per second on M3/M4 chips. This is a comfortable interactive speed.

NVIDIA GPU with 12GB VRAM: Fits entirely in VRAM with a little room to spare. Inference runs at 50–80 tokens per second on an RTX 3080/4070.

NVIDIA GPU with 8GB VRAM: Too tight for the full 14B Q4. Use Phi-4-mini instead, or wait for a Q3 quantized version of the full model.

CPU only with 16GB RAM: Loads and runs, but slowly — 3–6 tokens per second. Usable for batch tasks, uncomfortable for interactive use.

Figure 1 — Phi-4 14B vs Comparable Local Models

Model Params Size (Q4) MATH bench HumanEval t/s GPU Phi-4 ★14B8.9GB80.4%82.6%55–80 Llama 3.1 8B8B4.7GB51.9%72.6%70–100 Mistral 7B7B4.1GB28.0%40.2%80–110 Qwen 2.5 14B14B9.0GB75.5%79.9%50–70 Llama 3.1 70B70B43GB68.0%80.5%20–35 Phi-4 beats Llama 3.1 70B on MATH despite being 5× smaller

Where Phi-4 Falls Short

No model is perfect for everything, and Phi-4 has some genuine weak spots worth knowing about before you commit to it as your main local model.

General knowledge breadth. The synthetic training data approach gives it exceptional reasoning skills but at the cost of some breadth. It sometimes has gaps in knowledge about niche topics, obscure historical events, or domain-specific facts that a web-crawl-trained model would have absorbed. It’s not bad at factual recall — just occasionally spotty in ways that feel unexpected given its reasoning strength.

Creative and open-ended tasks. Phi-4 is a reasoning-focused model and it shows. It’s not a natural storyteller. For creative writing, brainstorming, or generating diverse ideas, a general instruction-tuned model like Llama 3.1 or Qwen 2.5 often produces more interesting, varied output. Phi-4 tends toward structured, predictable responses even when asked to be creative.

Conversation over many turns. With the default context length in Ollama (2048 tokens), long conversations can become choppy as earlier context drops out. Increase num_ctx if you’re planning extended sessions:

ollama run phi4 --parameter num_ctx 8192

Multilingual tasks. The training data was heavily English-focused. For non-English tasks, Qwen 2.5 (which has strong multilingual training) or a dedicated multilingual model will serve you better.

Best Use Cases for Phi-4

Given its strengths and limitations, Phi-4 fits best in a few specific scenarios:

If you’re doing math-heavy work — tutoring, checking calculations, working through quantitative problems — it’s the clear choice at the 14B scale. The gap over Llama 3.1 70B on math is significant enough to matter in practice.

For structured analysis and reasoning — breaking down arguments, evaluating logical consistency, working through decision trees — Phi-4’s training shows. It’s methodical and precise in a way that feels qualitatively different from most open-source models.

As a fast, capable model for coding and code explanation on hardware that can’t handle the full Qwen 2.5 Coder 7B comfortably. On a machine with 12GB VRAM, Phi-4 runs fast and produces good code with excellent explanations.

For document Q&A and summarisation where you need accurate, careful responses rather than creative ones. Phi-4’s tendency toward structured answers is a feature here.

Figure 2 — Pick Your Model: Phi-4 vs Alternatives by Task

Task Best Pick Why Math / logic / reasoningPhi-4Best-in-class at 14B, beats 70B models Code generation (8GB RAM)Phi-4-miniFits anywhere, surprisingly capable Code generation (16GB+ RAM)Qwen 2.5 Coder 7BCoding-tuned, slightly stronger on code Creative writing / brainstormLlama 3.1 8BMore diverse, less predictable output Multilingual tasksQwen 2.5 7BMuch stronger non-English coverage

Running Phi-4 via the API

Like all Ollama models, Phi-4 is available through the REST API at http://localhost:11434. Using the Python library:

import ollama

response = ollama.chat(
    model='phi4',
    messages=[
        {'role': 'system', 'content': 'You are a precise, step-by-step reasoning assistant.'},
        {'role': 'user', 'content': 'A train leaves at 9am travelling at 80mph. Another leaves at 10am from the same station going the same direction at 100mph. When does the second train catch the first?'}
    ]
)
print(response['message']['content'])

Phi-4 particularly benefits from a system prompt that emphasises step-by-step reasoning — it’s already inclined that way, but an explicit instruction reinforces it and tends to produce cleaner, more verifiable reasoning chains.

Phi-4 Mini: When Smaller Is Better

Phi-4-mini deserves a mention on its own. At 3.8B parameters and around 2.2GB in Q4, it runs on literally any machine that can run Ollama — including machines with 8GB RAM, older laptops, and even some Raspberry Pi configurations. For its size, the reasoning quality is genuinely impressive.

ollama run phi4-mini

If you have a lower-powered machine and have been dismissing local LLMs as impractical, phi4-mini is worth trying. It won’t match the full 14B on hard tasks, but for quick reasoning questions, code snippets, and structured analysis it’s better than you’d expect from a model that fits in 2GB. It’s also the right choice for edge deployment scenarios where you need an LLM in a constrained environment — embedded in an application, running on a server with limited RAM, or as a fast classification layer in a pipeline that routes harder tasks to a larger model.

Microsoft has committed to the Phi series as an ongoing research direction, so future Phi releases are likely. Phi-4 is the strongest version yet of the bet that quality-focused training can close the gap with scale — and so far, at least on reasoning-heavy tasks, the bet is paying off.

Prompting Phi-4 Effectively

Phi-4’s reasoning strengths show most clearly when you give it structure to work with. A few prompting patterns that work particularly well. For complex problems, explicitly ask for step-by-step reasoning: “Work through this step by step, showing your reasoning at each stage.” Phi-4 is already inclined to do this, but the instruction makes it more consistent. For code tasks, specify the constraints clearly upfront — language, version, dependencies, and what the function should and shouldn’t do — rather than iterating with corrections. For analysis tasks, break the question into specific sub-questions rather than asking a broad “what do you think about X?” A prompt like “analyse this argument: (1) is the logic valid? (2) are the premises true? (3) what’s the strongest counterargument?” gets more useful structured output than a general analysis request. Phi-4 rewards precision in prompting more than most models — the clearer and more structured your input, the more carefully structured and accurate the output tends to be. This makes it excellent for systematic work but slightly less forgiving for casual, open-ended conversations where a looser model might be more comfortable.

Is Phi-4 Right for You?

Phi-4 is the right choice if you’re doing reasoning-heavy work, you have 16GB of RAM or 12GB of VRAM, and you want a model that’s fast enough for interactive use. It’s not the right choice if you primarily need creative diversity, broad world knowledge, or strong multilingual support. For most developers and analysts working with structured problems — code, math, logic, document analysis — it’s one of the most impressive models at the 14B scale available right now. The fact that it outperforms Llama 3.1 70B on math while running on consumer hardware that can’t touch the 70B is a genuine achievement, and it makes it worth keeping in your local model toolkit even if you also run larger models for other tasks.

Leave a Comment