image-text-to-text Β· vision-language Β· WebGPU Β· ~1.8 GB
Moondream2 is a compact vision-language model with a reputation punching well above its size: give it an image and a question and it answers in plain language. Describe a scene, read a receipt, count objects, reason about what's happening β streaming token by token on your GPU, with nothing uploaded.
| Model | Xenova/moondream2 (ONNX build of vikhyatk/moondream2) |
|---|---|
| Task | image-text-to-text (vision β text generation) |
| Architecture | SigLIP vision encoder + Phi-1.5 text decoder (Moondream) |
| Params / dtype | ~1.86B Β· decoder q4f16, vision + embeddings fp16 |
| Backend | WebGPU (required β needs a GPU + shader-f16) |
| Download | ~1.8 GB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebGPU, Web Workers, FileReader |
Moondream doesn't use a chat template like larger VLMs β it frames the task in plain text.
Your image is turned into a block of image tokens that fill the <image>
placeholder, and your words are wrapped in a simple Question: β¦ Answer: frame.
Below is the exact prompt string the tokenizer receives, and the live
token stream with the time each token arrived β so you can watch it think and
see where the latency goes.
Run a generation to see the constructed prompt.
Moondream2 shows how far a small VLM has come: a couple of gigabytes of weights, running in a browser tab, that can read text in a photo and answer open questions about it β privately, offline-capable, and free to run.
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.
Moondream describes β a summariser turns several images into one caption set.
Moondream in Transformers.js uses a dedicated model class. You tokenize a simple
Question/Answer prompt, run the image through the processor, merge the two, then
generate β streaming tokens as they come:
import { AutoProcessor, AutoTokenizer, Moondream1ForConditionalGeneration, RawImage, TextStreamer }
from "@huggingface/transformers";
const model_id = "Xenova/moondream2";
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await Moondream1ForConditionalGeneration.from_pretrained(model_id, {
dtype: { embed_tokens: "fp16", vision_encoder: "fp16", decoder_model_merged: "q4f16" },
device: "webgpu", // WebGPU required
});
const text = `<image>\n\nQuestion: ${prompt}\n\nAnswer:`;
const text_inputs = tokenizer(text);
const image = await RawImage.fromURL(imageURL);
const vision_inputs = await processor(image);
const streamer = new TextStreamer(tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await model.generate({ ...text_inputs, ...vision_inputs, do_sample: false, max_new_tokens: 150, 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.