image-text-to-text Β· vision-language Β· WebGPU Β· ~1 GB
nanoLLaVA is a ~1B-parameter LLaVA-style vision-language model: a SigLIP vision encoder bolted onto a small Qwen1.5 language model. Give it an image, a system persona, and a question β and it answers in a chat format, streaming token by token on your GPU with nothing uploaded.
| Model | Xenova/nanoLLaVA (ONNX build of qnguyen3/nanoLLaVA) |
|---|---|
| Task | image-text-to-text (vision β text generation) |
| Architecture | SigLIP-400M vision encoder + Qwen1.5-0.5B decoder (LLaVA-style projector) |
| Params / dtype | ~1B Β· decoder q4f16, vision + embeddings fp16 |
| Backend | WebGPU (required β needs a GPU + shader-f16) |
| Download | ~1 GB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebGPU, Web Workers, FileReader |
nanoLLaVA follows the LLaVA recipe: your image is encoded to a grid of visual tokens that replace
the <image> placeholder inside a ChatML template, alongside a
system persona and your question. Below is the exact templated prompt the
tokenizer receives, and the live token stream with the time each token arrived β
so you can watch it reason and see where the latency goes.
Run a generation to see the templated prompt.
nanoLLaVA brings the well-known LLaVA architecture down to a browser-friendly size. The system persona makes it steerable β the same image and question can produce a terse label, a marketing caption, or a careful accessibility description, just by changing the persona.
Describe or ask about an image β the core LLaVA "talk to a picture" loop.
Read a screenshot or receipt and answer questions β visual Q&A over documents.
Swap the system persona to change the voice β same image, many personalities.
nanoLLaVA captions β an OPUS-MT translator makes multilingual alt-text.
nanoLLaVA uses the LLaVA model class. You build a ChatML message list with a system line and a
user turn that embeds the <image> placeholder, template it, tokenize, run the
image through the processor, then generate β streaming tokens as they come:
import { AutoProcessor, AutoTokenizer, LlavaForConditionalGeneration, RawImage, TextStreamer }
from "@huggingface/transformers";
const model_id = "Xenova/nanoLLaVA";
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await LlavaForConditionalGeneration.from_pretrained(model_id, {
dtype: { embed_tokens: "fp16", vision_encoder: "fp16", decoder_model_merged: "q4f16" },
device: "webgpu", // WebGPU required
});
const messages = [
{ role: "system", content: "Answer the question." },
{ role: "user", content: `<image>\n${prompt}` },
];
const text = tokenizer.apply_chat_template(messages, { tokenize: false, add_generation_prompt: true });
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.