text-generation Β· chat LLM Β· WebLLM (MLC) Β· WebGPU Β· ~880 MB
This is a real large-language-model chat, running entirely in your browser. Meta's Llama 3.2 1B is compiled to WebGPU by MLC's WebLLM engine β you get streaming tokens, sampling controls, a system prompt and full conversation history, with nothing uploaded and no API bill. It's a different runtime from the rest of the catalogue: no WASM fallback, so it needs a real GPU.
| Model | meta-llama/Llama-3.2-1B-Instruct |
|---|---|
| MLC build | Llama-3.2-1B-Instruct-q4f16_1-MLC |
| Runtime | WebLLM / MLC β not Transformers.js. Weights are precompiled to WebGPU shaders. |
| Task | text-generation (instruction-tuned chat) |
| Params / dtype | 1.24B Β· q4f16_1 (4-bit weights, fp16 compute) |
| Backend | WebGPU only β no WASM fallback. Gated on a real GPU adapter. |
| Download | ~880 MB, cached after first load |
| Context window | 4096 tokens (MLC prebuilt config) |
| License | Llama 3.2 Community License |
| Web APIs | WebGPU, Web Workers, ES module imports |
An LLM does two very different jobs per turn: it prefills your whole prompt (fast, parallel) and then decodes the answer one token at a time (the part you watch stream). The split below is measured live β time-to-first-token is essentially the prefill cost; everything after is decode. WebLLM reuses a KV cache across turns, so later replies in the same conversation reprocess less of the history.
Send a message to see the messages array that WebLLM receives.
A genuinely useful chat LLM used to mean a server, an API key, and a per-token bill. Llama 3.2 1B on WebLLM makes conversational AI a client-side primitive: private by construction, free to run, and available offline once the weights are cached.
A clean streaming chat β the fundamental "talk to the model" loop.
Structured extraction: turn messy text into strict JSON, on-device.
Persona role-play β swap the system prompt and become someone else.
RAG: MiniLM retrieves from a pasted doc, Llama answers grounded in it.
WebLLM gives you an OpenAI-shaped chat API backed by a WebGPU engine. You create the engine
(which downloads and compiles the weights), then stream a completion. This page uses the shared
helpers in lib/webllm.js, running inside a Web Worker so the UI stays responsive:
import { webGPUAdapterAvailable, createEngine, streamChat }
from "/lib/webllm.js";
// WebLLM is WebGPU-only β gate before doing anything (headless requestAdapter() β null).
if (!(await webGPUAdapterAvailable())) {
showNeedsWebGPU(); // never a faked reply
} else {
const engine = await createEngine({
model: "Llama-3.2-1B-Instruct-q4f16_1-MLC",
onProgress: (p) => setProgress(p.text, p.progress), // ~880 MB, cached after first load
});
const messages = [
{ role: "system", content: "You are a concise, helpful assistant." },
{ role: "user", content: "Explain WebGPU in one sentence." },
];
const full = await streamChat(
engine,
{ messages, temperature: 0.7, top_p: 0.95, max_tokens: 256 },
(delta) => appendToken(delta), // streams token-by-token on your GPU
);
// engine.interruptGenerate() stops decoding early; engine.runtimeStatsText() reports tok/s.
}
Everything here runs exactly that path in worker.js, and gates on a real WebGPU
adapter first. No adapter β a labelled needs-WebGPU state, never a canned answer.