any-to-any · multimodal · WebGPU q2f16 / fp16 · 2,603.9 MB · Apache-2.0

Gemma 4 E2B Instruct QAT Mobile — text, vision & audio in one local pass

Google's 2-billion-effective-parameter Gemma 4 E2B, quantisation-aware-trained for phones and exported to four WebGPU ONNX subgraphs. It hears raw 16 kHz audio, sees images, reads text and can think out loud — all fused into one token stream that runs entirely on your GPU in a Web Worker.

At a glance

Verified against the Hugging Face Hub API (revision a7f19b0) and config.json.
Browser ONNX repo onnx-community/gemma-4-E2B-it-qat-mobile-ONNX (base google/gemma-4-E2B-it-qat-mobile-transformers)
Task any-to-any (text + image + audio in → text out) · Gemma4ForConditionalGeneration + Gemma4Processor
Download 2,603.9 MB (2,603,949,446 B): embed_tokens_q2f16 1,296.6 MB · decoder_model_merged_q2f16 995.4 MB · vision_encoder_fp16 187.5 MB · audio_encoder_q2f16 92.3 MB · tokenizer + configs 32.2 MB
Quantisation q2f16 (2-bit QAT weights, fp16 compute) for embeddings, decoder and audio; fp16 vision encoder
Architecture 35-layer decoder (28 sliding-window-512 + 7 global layers, 1536-d, 8 heads / 1 KV head, 20 KV-shared layers, per-layer 256-d embeddings) · 16-layer 768-d vision encoder (patch 16, 3×3 pooling, ≤280 <|image|> soft tokens) · 12-layer 1024-d conformer audio encoder (40 ms per <|audio|> token, ≤750 tokens = 30 s) · 262,144-token vocab · 128K context
Special tokens <|image|> 258880 · <|audio|> 258881 · reasoning channel <|channel>thought … <channel|> (enabled via enable_thinking)
Runtime & backend Transformers.js 4.3.2 pinned only inside worker.js (shared lib/webai.js stays on 3.7.5) · WebGPU (shader-f16 recommended) · weights cached in transformers-cache
License Apache-2.0
Web APIs used WebGPU · module Web Workers · Cache Storage · Canvas 2D · Web Audio · MediaRecorder (mic, on click only)

Run it — unified text + vision + audio console

Presets (each combines up to all three modalities):

Image input

No image attached.

Audio input (16 kHz mono)

No audio attached.

…or drop a file here. Files never leave this tab.

Checking for a local copy of Gemma 4 E2B…

Live streamed answer

The answer streams here token-by-token once Gemma 4 E2B runs.
Backend / dtype–
Preprocess–
TTFT–
Decode speed–
Output tokens–
Tensor NaN count–

See inside · prompt token breakdown

Gemma4Processor expands each attached image into a run of <|image|> soft tokens (patch 16 → 3×3 pooled) and each audio clip into one <|audio|> token per 40 ms. The bar is counted from the real input_ids tensor of your last run.

Run a pass to see the text / image / audio split.

Latency breakdown

Input tensors

–

Raw chat-template prompt

Run a pass to inspect the exact Gemma 4 turn markup (<|turn>user … <turn|>) and the soft-token runs.

Why it matters

One 2.6 GB download replaces an ASR model, a captioner/VQA model and a chat LLM — and none of your audio or images leave the device.

Use-case ladder

How the API works

The worker imports Gemma4Processor and Gemma4ForConditionalGeneration directly (the repo's preprocessor_config.json omits processor_class, so AutoProcessor would return a tokenizer-less base class). Messages put content parts in audio → image → text order; apply_chat_template expands them, processor(prompt, image, audio) builds the tensors and generate() streams tokens through a TextStreamer.

Show the code — worker.js: runGenerate() (unified text + image + audio streaming pass)
Show the code — gemma4-core.mjs: buildMessages() (audio → image → text content order)

References