text-generation Β· chat LLM Β· WebLLM (MLC) Β· WebGPU Β· ~2.2 GB
Microsoft's Phi-3.5-mini is a 3.8-billion-parameter instruct model punching well above its size on reasoning, maths, and structured output β and it runs entirely in your browser, 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 bigger, more capable step up from the 1B models: no WASM fallback, so it needs a real GPU and enough VRAM.
| Model | microsoft/Phi-3.5-mini-instruct |
|---|---|
| MLC build | Phi-3.5-mini-instruct-q4f16_1-MLC |
| Runtime | WebLLM / MLC β not Transformers.js. Weights are precompiled to WebGPU shaders. |
| Task | text-generation (instruction-tuned chat) |
| Params / dtype | 3.8B Β· q4f16_1 (4-bit weights, fp16 compute) |
| Backend | WebGPU only β no WASM fallback. Gated on a real GPU adapter (~3.7 GB VRAM). |
| Download | ~2.2 GB, cached after first load |
| Context window | 4096 tokens (MLC prebuilt config; base model supports 128k) |
| License | MIT |
| 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, and the context meter shows how much of Phi's 4096-token window you're using.
Send a message to see the messages array that WebLLM receives.
Phi-3.5-mini is small enough to run in a tab but strong enough to reason: it's competitive with much larger models on maths, code, and structured tasks. Running it on WebLLM makes that capability a client-side primitive β private by construction, free to run, and available offline once the weights are cached.
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: "Phi-3.5-mini-instruct-q4f16_1-MLC",
onProgress: (p) => setProgress(p.text, p.progress), // ~2.2 GB, cached after first load
});
const messages = [
{ role: "system", content: "You are a careful, concise assistant." },
{ role: "user", content: "If a train travels 60 km in 45 minutes, what is its speed in km/h?" },
];
const full = await streamChat(
engine,
{ messages, temperature: 0.7, top_p: 0.95, max_tokens: 384 },
(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.