image-text-to-text · vision-language · WASM · ~1.4 GB
FastVLM is Apple's efficient vision-language model. Its trick is the vision encoder — a hybrid conv/transformer called FastViTHD that emits far fewer, higher-quality visual tokens, so the model starts answering quickly. Give it an image and a question and the 0.5B version answers in plain language, streaming token by token — on your GPU, or on the CPU when there's no GPU, with nothing uploaded.
| Model | onnx-community/FastVLM-0.5B-ONNX (ONNX build of apple/FastVLM-0.5B) |
|---|---|
| Task | image-text-to-text (vision → text generation) |
| Architecture | FastViTHD vision encoder + Qwen2-0.5B decoder (llava_qwen2) |
| Params / dtype | ~0.5B decoder · q4 (embeds, vision + decoder) — runs on the WASM CPU backend |
| Backend | WASM (CPU) — no GPU required; runs on mobile + desktop. (The model's WebGPU exports are numerically unreliable in Transformers.js today, so we run on the CPU.) |
| Download | ~1.4 GB, cached after first load |
| License | apple-amlr (Apple ML Research — non-commercial; check terms before shipping) |
| Web APIs | Web Workers, WebAssembly, FileReader |
FastVLM wraps your question in a Qwen2 chat template with an <image> placeholder
that the FastViTHD encoder fills with visual tokens. Below is the exact prompt
string the processor builds, and the live token stream with the time
each token arrived — so you can watch time-to-first-token (the encoder's whole selling point) and
see where the latency goes.
Run a generation to see the constructed prompt.
FastVLM's contribution is speed: a vision encoder designed so the model can start answering about a high-resolution image quickly, at a size (0.5B) that fits in a browser tab — on a GPU or, more unusually for a VLM, on the CPU.
Describe or ask about an image — the core "talk to a picture" loop.
Read a receipt or screenshot and extract answers — visual Q&A over documents.
Interrogate an image — keep asking follow-up questions in an open visual chat.
FastVLM describes an image → an OPUS-MT model translates it: multilingual alt-text.
FastVLM loads through the generic image-text-to-text auto classes. You build a chat prompt with an
<image> marker, run the image + prompt through the processor, then generate —
streaming tokens as they come:
import { AutoProcessor, AutoModelForImageTextToText, RawImage, TextStreamer }
from "@huggingface/transformers";
const model_id = "onnx-community/FastVLM-0.5B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await AutoModelForImageTextToText.from_pretrained(model_id, {
// all-q4 keeps every IO tensor float32; runs on the WASM CPU backend.
dtype: { embed_tokens: "q4", vision_encoder: "q4", decoder_model_merged: "q4" },
device: "wasm",
});
const messages = [{ role: "user", content: "<image>Describe this image in detail." }];
const text = processor.apply_chat_template(messages, { add_generation_prompt: true });
const image = await RawImage.fromURL(imageURL);
const inputs = await processor(image, text, { add_special_tokens: false });
const streamer = new TextStreamer(processor.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await model.generate({ ...inputs, do_sample: false, max_new_tokens: 120, streamer });
This page runs exactly that in a Web Worker, runs on the WASM CPU backend and reports the real latency + backend, never a fake answer.