At a glance
| 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.
Checking for a local copy of Gemma 4 E2B…
Live streamed answer
Thinking trace (<|channel>thought)
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
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.
- Field and inspection apps: a technician photographs a gauge and speaks a memo; one pass returns structured JSON.
- Accessible interfaces: answer spoken questions about what is on screen or in a photo, offline.
- Private meeting and voice-note tools: transcribe and summarise raw audio without a cloud ASR bill.
- Cross-modal checking: catch when what was said disagrees with what is shown (see the Wild rung).
Use-case ladder
Basics · modality ablation
Text-only vs thinking vs vision vs direct audio vs the unified omni pass — TTFT, tok/s and live soft-token counts side by side.
Practical · site photo + voice memo queue
Pause / resume / cancel a multi-asset inspection queue that emits structured field JSON, with OWASP-safe CSV and Markdown export.
Wild · modality stress sweep
Tiny vs high-res images, noisy audio, an occluded chart and an audio-vs-sign contradiction probe, scored for grounded faithfulness.
Multi-model · Silero VAD → Gemma 4
Trim dead air with a 2.2 MB CPU VAD before Gemma hears it, and measure the exact audio-token and latency savings.
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.