← All models

image-text-to-text Β· vision-language Β· WebGPU Β· ~1.8 GB

Moondream2 β€” ask a small model about a picture

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.

At a glance

ModelXenova/moondream2 (ONNX build of vikhyatk/moondream2)
Taskimage-text-to-text (vision β†’ text generation)
ArchitectureSigLIP vision encoder + Phi-1.5 text decoder (Moondream)
Params / dtype~1.86B Β· decoder q4f16, vision + embeddings fp16
BackendWebGPU (required β€” needs a GPU + shader-f16)
Download~1.8 GB, cached after first load
LicenseApache-2.0
Web APIsWebGPU, Web Workers, FileReader

Run it

A riverside at golden hour with a swan Two cats on a couch A cozy bedroom A cafΓ© receipt with items and a total
…or drop / choose your own image
Selected image
The model's answer will stream here.

See inside

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.

Constructed prompt

Run a generation to see the constructed prompt.

Token stream (value Β· ms since start)

Tokens appear here as they're generated.

Why it matters

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.

Use cases

Basics

Describe or ask about an image β€” the core "talk to a picture" loop.

Practical

Read a receipt or screenshot and extract answers β€” visual Q&A over documents.

Wild

Interrogate an image β€” keep asking follow-up questions in an open visual chat.

Multi-model

Moondream describes β†’ a summariser turns several images into one caption set.

How the API works

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.

References