text-generation · text · WASM · ~576 MB
IBM's Granite 4.0 is a newer generation than the Granite-3.0 already in this showcase, and a genuinely different design: a hybrid architecture that interleaves Mamba-2 state-space layers with a few attention layers, for long context at a small memory footprint. This 350M "micro" chat model runs on the universal WebAssembly/CPU path with no GPU — distinct in both family and architecture from every LLM here. Everything runs on your device — no key, no server.
| Model | onnx-community/granite-4.0-350m-ONNX-web — ONNX export of ibm-granite/granite-4.0-350m |
|---|---|
| Task | text-generation — ChatML instruct/chat |
| Architecture | granitemoehybrid — hybrid Mamba-2 state-space + attention layers, ~350M params |
| Distinct | Granite 4.0 (vs the built Granite-3.0) AND hybrid Mamba (vs transformer) — new family + new architecture |
| Quantization | q4 (onnx/model_q4.onnx + external data). q4f16/fp16 are WebGPU-only |
| Runtime / backend | Transformers.js · WebAssembly (runs anywhere; WebGPU used as an optional accelerator) |
| Download | ~576 MB (q4), cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers, (optional WebGPU) — all Baseline widely available |
Ask something; the answer streams token by token. It's a tiny model, so facts can be wrong — the point is a distinct architecture running fully on-device.
The model computes a probability for every token in its vocabulary. This is the real top-12 distribution for the token right after your prompt — one forward pass, on your device.
Hybrid Mamba models trade some attention layers for state-space layers, which scale better with sequence length. Seeing one run in a browser at ~350M shows the architecture is practical for on-device, offline assistants — no GPU required.
import { pipeline, TextStreamer } from "@huggingface/transformers";
const generate = await pipeline("text-generation",
"onnx-community/granite-4.0-350m-ONNX-web", { dtype: "q4" }); // ~576 MB, cached once
const messages = [{ role: "user", content: "…" }];
const streamer = new TextStreamer(generate.tokenizer, { skip_prompt: true });
const out = await generate(messages, {
max_new_tokens: 200, do_sample: true, temperature: 0.7, streamer,
});
// out[0].generated_text.at(-1).content → the assistant's reply
This page runs exactly that in a Web Worker (so streaming never blocks the UI), and does one extra forward pass for the real next-token probabilities.