text-generation Β· text Β· WebGPU / WebAssembly Β· ~200 MB (q4f16) / ~1.05 GB (fp32)
Gemma 3 270M is the smallest model in Google's 2025 Gemma 3 family β a ~270M-parameter instruction-tuned chat model built to run anywhere. This page runs it entirely in your browser via Transformers.js: it streams tokens on WebGPU (dtype q4f16) when your device has an adapter, and falls back to the universal WebAssembly/CPU path (dtype fp32) otherwise. Chat with it, steer it with a system prompt and sampling controls, and watch the real probability distribution behind every token. Nothing is uploaded; there is no API key and no server.
Distinct from the other small chat models here: this is the Transformers.js build of
the tiniest Gemma 3, so it runs on the WASM/CPU path with no WebGPU required β where the
Gemma 3 1B (WebLLM) demo needs WebGPU. Because
the gemma3_text class is newer than the repo's shared Transformers.js pin, this one demo
loads Transformers.js 4.3.0 in its worker (an isolated version pin; every other page
stays on 3.7.5).
| Model | onnx-community/gemma-3-270m-it-ONNX (ONNX build of google/gemma-3-270m-it) |
|---|---|
| Task | text-generation (causal LM, instruction-tuned chat) |
| Architecture | Gemma 3 β a dense decoder-only transformer (model_type: gemma3_text), ~270M params, the smallest Gemma 3 |
| Params / dtype | ~0.27B Β· q4f16 on WebGPU (onnx/model_q4f16.onnx) Β· fp32 on WASM (onnx/model.onnx) |
| Backend | WebGPU (fast path) when a real adapter is present; otherwise the universal WebAssembly (CPU) path β no WebGPU required |
| Why fp32 on WASM? | The quantized exports (q4, q8) use the GatherBlockQuantized embedding op, which ORT-Web only implements on the WebGPU EP; on the WASM EP they abort at session creation. fp16/q4f16 likewise need WebGPU's fp16 kernels. So on the CPU path fp32 is the only export that runs β larger, but real coherent output. (Verified in headless Chrome.) |
| Runtime | Transformers.js 4.3.0, pinned locally in this worker only (the gemma3_text class is newer than the shared 3.7.5) |
| Download | ~200 MB (q4f16, WebGPU) or ~1.05 GB (fp32, WASM), cached after first load |
| License | Gemma Terms of Use |
| Web APIs | WebAssembly, Web Workers, ES module imports (WebGPU optional) |
Heads up: on WebGPU the first load transfers ~200 MB (q4f16); on the WASM/CPU path it transfers ~1.05 GB (fp32) β then it's cached. At ~0.27B this is one of the lightest real chat LLMs here β it's tiny, so expect small-model answers: fluent and on-topic on simple prompts, but less reliable than a multi-billion-parameter model.
An LLM never "picks a word" β every step it produces a probability over its whole 262k-token vocabulary, and the sampler chooses one. Below is the exact templated prompt the model receives (Gemma's chat markup), and β from one real forward pass over the current conversation β the actual top candidates for the very next token, with their probabilities. Raise the temperature and the tail fattens; drop it and the top token dominates. This is the real distribution, computed on your device, not a mock-up.
Load the model and click "Show next-token distribution".
Gemma 3 270M is the "runs anywhere" tier of a serious open family from Google. Because it is so small, it makes client-side language a universal primitive: it works on the locked-down work laptop, the older phone, the kiosk with the GPU blocklisted β on WebGPU it's a ~200 MB fast download, and even with no GPU at all it still runs (on the fp32 CPU path). Private, offline-capable once cached, free to run, no key. Its real strength is as a task-specific base: tiny models like this are cheap to fine-tune for one narrow job (classification, extraction, formatting) and then embed directly in a page.
Ask a question, watch the answer stream on your device β the core chat loop.
Structured extraction: free text β schema-shaped JSON, ready for a form or API.
Persona engine: the same tiny model role-plays a character you choose.
On-device RAG: GTE-small embeds and retrieves, Gemma answers with citations.
It's the standard Transformers.js text-generation pipeline β pass a messages array
(the pipeline applies Gemma's chat template), a TextStreamer for token-by-token output,
and your sampling settings. The only device-specific choice is device + dtype,
which this page picks by probing for a real WebGPU adapter. Note the pinned version β the
gemma3_text class needs Transformers.js β₯ 4.2.0:
import { pipeline, TextStreamer } from "@huggingface/transformers"; // v4.2.0+
// Probe for a real adapter β WebGPU (q4f16) fast path, else universal WASM (fp32) on the CPU.
const adapter = navigator.gpu && await navigator.gpu.requestAdapter().catch(() => null);
const [device, dtype] = adapter ? ["webgpu", "q4f16"] : ["wasm", "fp32"];
const generator = await pipeline(
"text-generation", "onnx-community/gemma-3-270m-it-ONNX", { device, dtype },
);
const messages = [
{ role: "system", content: "You are a helpful, concise assistant." },
{ role: "user", content: "Name three primary colors." },
];
const streamer = new TextStreamer(generator.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await generator(messages, {
max_new_tokens: 200, do_sample: true, temperature: 0.7, top_p: 0.9, streamer,
});
The "see inside" panel runs one raw forward pass β
generator.model(generator.tokenizer(prompt)) β reads the last position's
logits, softmaxes them, and shows the real top-k. Everything runs in a Web Worker so
generation never blocks the page; the loader auto-inits an already-cached copy and never silently
re-downloads.