image-text-to-text Β· vision-language Β· WebGPU Β· ~2.9 GB
PaliGemma is Google's task-steerable VLM: instead of a chat, you give it a short prefix β
caption en, ocr, detect car, segment dog,
answer en β¦ β and it captions, reads text, locates objects (with box coordinates), or
answers a visual question. All streaming, on your GPU, nothing uploaded.
Made by Paul Kinlan Β· Model runs locally in your browser by π€ Transformers.js Β· Source on GitHub
| Model | onnx-community/paligemma2-3b-pt-224 (ONNX build of google/paligemma2-3b-pt-224) |
|---|---|
| Task | image-text-to-text (task-prefixed vision β text) |
| Architecture | SigLIP-So400m vision encoder + Gemma 2 text decoder (PaliGemma 2) |
| Params / dtype | ~3B Β· decoder q4f16, vision fp16, embeddings q8 |
| Backend | WebGPU (required β needs a GPU + shader-f16) |
| Download | ~2.9 GB, cached after first load |
| License | Gemma license (see model card) |
| Web APIs | WebGPU, Web Workers, FileReader |
This is the pt (pretrained) checkpoint β it responds best to the documented task
prefixes (caption, ocr, detect, segment,
answer). Free-form questions work but are terser than an instruction-tuned VLM.
PaliGemma has no chat template β the whole instruction is a short task prefix
placed after the image tokens. Below is the exact prompt string the processor
receives (the <image> marker expands into 256 vision tokens), and the live
token stream with the time each token arrived. For detect the model
emits <locNNNN> coordinate tokens β the Practical demo decodes those into boxes.
Run a task to see the constructed prompt.
Most VLMs do one thing (chat about an image). PaliGemma is a Swiss-army vision model: the same weights caption, read, locate, and answer β you just change the prefix. Running that in a browser tab turns a stack of separate vision services into one on-device primitive.
detect {thing} returns box coordinates you can draw, no bespoke detection model or labels.Caption an image β the caption en prefix, streamed.
Detect objects by name and draw the boxes decoded from the model's <loc> tokens.
Free-form prefix lab β type any task string and see how the model responds.
PaliGemma captions β an OPUS-MT translator renders multilingual alt-text.
PaliGemma in Transformers.js uses a dedicated model class. You pass the image and a task-prefix prompt to the processor, then generate β streaming tokens as they come:
import { AutoProcessor, PaliGemmaForConditionalGeneration, load_image, TextStreamer }
from "@huggingface/transformers";
const model_id = "onnx-community/paligemma2-3b-pt-224";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await PaliGemmaForConditionalGeneration.from_pretrained(model_id, {
dtype: { embed_tokens: "q8", vision_encoder: "fp16", decoder_model_merged: "q4f16" },
device: "webgpu", // WebGPU required
});
const image = await load_image(imageURL);
const prompt = "<image>caption en"; // or "<image>ocr", "<image>detect car", "<image>answer en β¦"
const inputs = await processor(image, prompt);
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: 100, 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.