Skip to main content
Back

Microsoft's Phi-3-Vision Beats Claude and Gemini at Chart Reading With 4.2B Parameters

Microsoft's 4.2B parameter multimodal Phi-3 variant handles images, charts, and OCR with a 128K context, running efficiently on a single GPU.

Pro

  • Microsoft's Phi-3-vision-128k-instruct is a 4.2B parameter multimodal model with 128K context, MIT licensed.
  • Beats Claude-3 Haiku and Gemini 1.0 Pro V on ChartQA, ScienceQA, and OCR benchmarks.
  • Trained on 500B vision and text tokens using 512 H100 GPUs over 1.5 days.
  • Built for OCR, chart and table understanding, and latency or memory constrained deployments.
  • Supports vLLM, SGLang, Docker, and standard Transformers with a single-image chat template.
  • Weaknesses: English-only focus, Python-biased code, and one image per prompt limitation.

Microsoft has quietly built one of the more interesting small multimodal models around, and it keeps climbing the trending charts. Phi-3-vision-128k-instruct packs image understanding, OCR, and chart reasoning into a 4.2B parameter model with a 128K token context window, all under an MIT license. It runs on a single consumer or workstation GPU while going toe-to-toe with much larger vision language models on a surprising number of benchmarks.

A pocket-sized multimodal with a very long memory

Phi-3-Vision-128K-Instruct is an open multimodal model trained on a mix of synthetic and filtered web data, weighted toward reasoning-dense examples across both text and vision. The headline spec is the 128K token context length, which is unusual at this size and lets the model chew through long documents, transcripts, or multi-turn conversations paired with an image without truncation.

Under the hood, the 4.2B parameter model wires an image encoder, connector, and projector into the same Phi-3 Mini backbone that powers the text-only Phi-3 releases. If you already fine-tune Phi-3 Mini, the vision variant behaves like a familiar cousin: patch embeddings from the vision tower flow through a projector and land in the same language model you know.

What it is actually good at

Microsoft targets memory and compute constrained environments, latency bound scenarios, general image understanding, OCR, and chart and table understanding. That last pair is where the model earns its keep. Phi-3-vision reasons over real-world images, extracts text from them, and has been tuned specifically to interpret charts and diagrams, generate insights, and answer questions about them.

Bar chart used as example input for Phi-3 vision showing meeting preparedness survey results

The benchmarks back this up. On zero-shot evaluations, Phi-3-vision-128k-instruct posts 90.8 on ScienceQA, 81.4 on ChartQA, 76.7 on AI2D, and 44.5 on MathVista, ahead of LLaVA-1.6 Vicuna-7B, QWEN-VL Chat, and Llama3-LLaVA-Next-8B across most vision reasoning tasks. It also edges out GPT-4V-Turbo on ScienceQA and ChartQA in Microsoft's internal harness, though GPT-4V still wins on MMMU and MMBench. At 4.2B parameters it also beats Claude-3 Haiku and Gemini 1.0 Pro V on general visual reasoning, OCR, and table and chart understanding.

How it was built

The training recipe follows the Phi playbook of quality over quantity. Microsoft trained on 500B vision and text tokens using 512 H100-80G GPUs over 1.5 days, between February and April 2024, with a data cutoff of March 15, 2024. Post-training combined supervised fine-tuning with direct preference optimization for instruction following and safety.

The dataset mix is where things get interesting. Microsoft leaned heavily on newly created synthetic, textbook-style data covering math, coding, common sense reasoning, and general world knowledge, alongside synthetic image data of charts, tables, diagrams, and slides. It is the same textbook-style approach that made the original Phi models punch above their weight, now extended to visual reasoning targets.

Getting it running

Inference is straightforward if you already work with Hugging Face Transformers. The model uses a chat template with a special image placeholder token:

from PIL import Image
import requests
from transformers import AutoModelForCausalLM, AutoProcessor
model_id = "microsoft/Phi-3-vision-128k-instruct"
model = AutoModelForCausalLM.from_pretrained(
    model_id, device_map="cuda", trust_remote_code=True,
    torch_dtype="auto", _attn_implementation="flash_attention_2"
)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
messages = [{"role": "user", "content": "<|image_1|>\nWhat is shown in this image?"}]
image = Image.open(requests.get(url, stream=True).raw)
prompt = processor.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(prompt, [image], return_tensors="pt").to("cuda:0")
out = model.generate(**inputs, max_new_tokens=500, temperature=0.0, do_sample=False)

A few practical notes worth knowing before you deploy:

  • Flash attention is on by default and requires A100, A6000, or H100 class GPUs. Pass _attn_implementation='eager' to run on other hardware.
  • The chat format is designed for a single image per prompt, formatted as <|user|>\n<|image_1|>\n{prompt}<|end|>\n<|assistant|>\n.
  • vLLM and SGLang both serve the model with an OpenAI-compatible API, so vllm serve microsoft/Phi-3-vision-128k-instruct gets you a production endpoint in one line.
  • Weights ship as roughly 4B parameters in BF16, which fits comfortably in a 16GB card with room for context.

The limitations worth knowing

Phi-3-vision has real weak spots that Microsoft is upfront about. The Phi models train primarily on English text, so other languages will see worse performance. Code generation is similarly narrow: most training data is Python using common packages like typing, math, random, collections, datetime, and itertools, so anything outside that stack needs manual verification.

The chat template also handles one image at a time. If your workflow involves comparing multiple images side by side, you will need to concatenate them into a single canvas or move to the follow-up Phi-3.5-vision-instruct, which added explicit multi-image support.

Where it fits in your stack

The practical wins are in edge and cost-sensitive scenarios where GPT-4V is overkill or impossible. Concrete use cases where Phi-3-vision earns its slot:

  1. Extracting structured data from screenshots of tables and dashboards without shipping images to a hosted API.
  2. OCR pipelines that need reasoning on top of raw text, like classifying receipts or parsing forms.
  3. Chart and diagram question answering for internal analytics tools.
  4. Local document assistants that ingest a scanned PDF page plus a long text prompt within the 128K window.
  5. On-device or on-premise deployment for regulated data that cannot leave your infrastructure.

Zooming out, the release backs Microsoft's bet that carefully curated synthetic data can close the gap between small open models and frontier closed ones. The Phi-3 technical report makes the case explicitly, and the vision variant is arguably the strongest evidence yet. A 4.2B parameter model that reads charts as well as some 70B contenders is exactly the kind of result that pushes teams to revisit whether a hosted multimodal API is still the right default.