text-generation · text · WebGPU · ~500 MB
A 500-million-parameter instruct LLM, small enough to load into a browser and stream tokens on your own GPU. Chat with it, steer it with a system prompt and sampling controls, then open the hood and watch the real probability distribution it samples each next token from — no server, no API key, nothing uploaded.
| Model | onnx-community/Qwen2.5-0.5B-Instruct |
|---|---|
| Task | text-generation (causal LM, chat-tuned) |
| Architecture | Qwen2 decoder-only transformer, 0.5B params, 151k-token vocab |
| Params / dtype | 0.5B · q4f16 on WebGPU (4-bit weights, fp16 compute) |
| Backend | WebGPU (required — gates on a real GPU adapter) |
| Download | ~500 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebGPU, Web Workers |
An LLM never "chooses a word" — every step it produces a probability over all 151,936 tokens in its vocabulary, and the sampler picks one. Below is the exact templated prompt the model receives, 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-device, not a mock-up.
Load the model and click "Show next-token distribution".
A capable instruct model that fits in a browser tab turns language into a client-side primitive: private, offline-capable, and free to run at any scale. No inference bill, no data leaving the device, no cold-start latency once it's cached.
Qwen uses the standard text-generation pipeline. Pass a messages array (the pipeline
applies the chat template for you), a TextStreamer for token-by-token output, and
your sampling settings:
import { pipeline, TextStreamer } from "@huggingface/transformers";
const generator = await pipeline(
"text-generation",
"onnx-community/Qwen2.5-0.5B-Instruct",
{ dtype: "q4f16", device: "webgpu" }, // WebGPU required
);
const messages = [
{ role: "system", content: "You are a helpful, concise assistant." },
{ role: "user", content: "Explain WebGPU in one sentence." },
];
const streamer = new TextStreamer(generator.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await generator(messages, {
max_new_tokens: 256, 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 and
gates on a real WebGPU adapter first; with none, it shows a labelled needs-WebGPU state instead of
faking tokens.