image-text-to-text Β· vision-language Β· WebGPU Β· ~2.5 GB
Phi-3.5-vision is Microsoft's compact reasoning VLM, tuned for reading and comparing: strong OCR, chart and table understanding, and β unusually for a small model β genuine multi-frame input, so you can hand it two screenshots or a page of thumbnails and ask it to compare. Give it image(s) and a question and the answer streams out token by token on your GPU β nothing uploaded.
| Model | onnx-community/Phi-3.5-vision-instruct (ONNX build of microsoft/Phi-3.5-vision-instruct) |
|---|---|
| Task | image-text-to-text (vision β text generation) |
| Architecture | CLIP ViT-L/14-336 vision encoder + HD image transform (multi-crop) β Phi-3.5 (Phi3) text decoder |
| Class | Phi3VForCausalLM + AutoProcessor (Phi3VProcessor) β three ONNX sessions: vision_encoder, prepare_inputs_embeds, model |
| Params / dtype | ~4.2B Β· all three sessions q4f16 (needs shader-f16) |
| Backend | WebGPU (required β needs a GPU + shader-f16) |
| Download | ~2.5 GB, cached after first load |
| License | MIT |
| Web APIs | WebGPU, Web Workers, FileReader |
A VLM doesn't "see" β it reads a sequence of tokens where your image has been turned into a block
of vision tokens and slotted into a chat template. Phi-3.5-vision uses an HD image
transform: it splits each picture into a grid of 336Γ336 crops plus a global thumbnail, so
a detailed chart or a dense page becomes hundreds of image tokens (its edge on OCR and
fine print). In the prompt you write <|image_1|>; the processor expands that to
the right number of <|image|> tokens and negates their ids so the decoder splices
in the real vision features. Below is the exact templated prompt, the live
image-token count, and the token stream with per-token timing.
Run a generation to see the templated prompt.
Phi-3.5-vision is the "reasoning reader": small enough to run in a tab, but tuned to pull structure out of charts, tables, and documents β and to look at several images together. Running that privately, offline-capable, and free per call turns a lot of server-side document and analytics plumbing into a client-side primitive.
Describe or ask about a single image β the core "talk to a picture" loop.
Read a chart, receipt, form, or screenshot and extract the answer β chart Q&A and OCR-with-reasoning.
Hand Phi-3.5-vision two images at once and ask it to compare β multi-frame reasoning.
Phi-3.5-vision reads a chart β a summariser turns the extract into a one-line digest.
Phi-3.5-vision in Transformers.js is a causal-LM VLM (Phi3VForCausalLM). You write
<|image_N|> placeholders in the message, template it, run the processor over the
templated text plus the image(s), then generate β streaming tokens as they come:
import { AutoProcessor, Phi3VForCausalLM, RawImage, TextStreamer }
from "@huggingface/transformers";
const model_id = "onnx-community/Phi-3.5-vision-instruct";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await Phi3VForCausalLM.from_pretrained(model_id, {
dtype: { vision_encoder: "q4f16", prepare_inputs_embeds: "q4f16", model: "q4f16" },
device: "webgpu", // WebGPU required (shader-f16)
});
const image = await RawImage.read(imageURL);
const messages = [{ role: "user", content: "<|image_1|>\nWhat is the highest quarter?" }];
const text = processor.tokenizer.apply_chat_template(messages,
{ tokenize: false, add_generation_prompt: true });
const inputs = await processor(text, image); // HD transform β hundreds of image tokens
const streamer = new TextStreamer(processor.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await model.generate({ ...inputs, max_new_tokens: 220, do_sample: false, streamer });
This page runs exactly that, in a Web Worker, and gates on a real WebGPU adapter first β if none exists it shows a labelled needs-WebGPU state instead of a fake answer. For multiple images, add <|image_2|>β¦ and pass an array of images.