any-to-any Β· unified understanding + generation Β· WebGPU Β· ~2.4 GB
Janus-Pro is a unified multimodal model: the same 1B network both understands images β hand it a photo and ask anything β and generates them β give it a prompt and it paints a picture, pixel by pixel. It pulls this off by decoupling the vision path: one encoder for seeing, a separate image tokenizer for drawing. Both run entirely on your GPU. Nothing is uploaded.
| Model | onnx-community/Janus-Pro-1B-ONNX (ONNX build of deepseek-ai/Janus-Pro-1B) |
|---|---|
| Task | any-to-any β image-text-to-text (understanding) + text-to-image (generation) |
| Architecture | SigLIP vision encoder (understanding) + VQ image tokenizer & decode head (generation) β shared autoregressive LLM |
| Params / dtype | ~1B Β· WebGPU w/ shader-f16: LLM q4f16, heads fp16; no f16: LLM q4, embeds/heads fp32 |
| Backend | WebGPU (required) Β· prepare_inputs_embeds runs on WASM (upstream op bug) |
| Download | ~2.4 GB (with shader-f16) / ~4 GB fallback β cached after first load |
| Image tokens | 576 (a 24Γ24 grid) per generated image, decoded to a 384Γ384 raster |
| License | MIT |
| Web APIs | WebGPU, Web Workers, Canvas, FileReader |
Janus samples 576 image tokens autoregressively, then a VQ decoder turns them into a 384Γ384 picture. Each run differs (sampling is on).
image-token grid (24Γ24)
The trick behind a unified model is two vision paths, one brain. For understanding, your image goes through a SigLIP encoder into ~576 vision tokens that sit in the prompt next to your words, and the shared LLM reads the whole sequence and writes an answer. For generation, there's no input image β the LLM instead emits 576 discrete image tokens one at a time, and a separate VQ decoder turns that grid back into pixels. Same weights, two front doors.
Ask about an image to see the templated prompt.
Until now, "read this image" and "draw this image" were two different models, two downloads, two APIs. Janus-Pro folds both into a single ~1B model you can ship to a browser tab β private, offline-capable after first load, free per call. One asset unlocks a round-trip: see β describe β imagine β draw.
Both core moves side by side: describe an image, and generate one from a prompt.
Visual Q&A on a document, and generate an app icon / illustration from a text brief.
Round-trip: Janus generates an image, then describes its own output.
Janus understands an image β a text model rewrites the caption into a polished blurb.
Both paths load the same processor and model. Understanding calls generate
with an image placeholder in the conversation; generation switches the chat template to
text_to_image and calls generate_images, which decodes the emitted image
tokens into a RawImage:
import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
const model_id = "onnx-community/Janus-Pro-1B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id); // β VLChatProcessor
const model = await MultiModalityCausalLM.from_pretrained(model_id, { device: "webgpu", dtype: {β¦} });
// (a) Understanding: image + text β text
const conv = [{ role: "<|User|>", content: "<image_placeholder>\nWhat is this?", images: [url] }];
const inputs = await processor(conv);
const out = await model.generate({ ...inputs, max_new_tokens: 200, do_sample: false });
console.log(processor.batch_decode(out.slice(null, [inputs.input_ids.dims.at(-1), null]), { skip_special_tokens: true })[0]);
// (b) Generation: text β image
const gconv = [{ role: "<|User|>", content: "a red fox in autumn leaves" }];
const ginputs = await processor(gconv, { chat_template: "text_to_image" });
const n = processor.num_image_tokens; // 576
const images = await model.generate_images({ ...ginputs, min_new_tokens: n, max_new_tokens: n, do_sample: true });
await images[0].save("out.png");
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 image.