← All models

text-generation Β· chat LLM Β· WebLLM (MLC) Β· WebGPU Β· ~2.2 GB

Phi-4-mini β€” Microsoft's newest small model, on your GPU

Phi-4-mini-instruct is the newest model in Microsoft's Phi line: 3.8B parameters, a rebuilt 200k-token vocabulary, grouped-query attention for faster decode, and markedly stronger instruction-following and function calling than Phi-3.5. It runs entirely in your browser, compiled to WebGPU by MLC's WebLLM engine β€” streaming tokens, sampling controls, a system prompt, and full conversation history, with nothing uploaded and no API bill. WebGPU only: a 3.8B model decoding token-by-token needs a real GPU and enough VRAM (~3.4 GB), and a ~2.2 GB one-time download.

At a glance

Modelmicrosoft/Phi-4-mini-instruct
MLC buildPhi-4-mini-instruct-q4f16_1-MLC
RuntimeWebLLM / MLC β€” not Transformers.js. Weights are precompiled to WebGPU shaders.
Tasktext-generation (instruction-tuned chat)
Params / dtype3.8B Β· q4f16_1 (4-bit weights, fp16 compute)
What's new vs Phi-3.5200k-token vocabulary, grouped-query attention, stronger function-calling & instruction following
BackendWebGPU only β€” no WASM fallback. Gated on a real GPU adapter (~3.4 GB VRAM).
Download~2.2 GB, cached after first load
Context window4096 tokens (MLC prebuilt config; base model supports 128k)
LicenseMIT
Web APIsWebGPU, Web Workers, ES module imports

How it differs from the other chat pages: this is the Phi-4 generation β€” a newer, retrained successor to the built Phi-3.5-mini page (same 3.8B size, but a new tokenizer and a function-calling focus). It's a distinct architecture family from Gemma (Gemma 3), Qwen (Qwen3) and Llama. Both Phi pages stay available so you can compare the generations.

Run it β€” chat

Heads up: loading transfers ~2.2 GB the first time (then it's cached). Best on a GPU with β‰₯4 GB of memory.

The conversation will appear here. Load the model, then say hello.
History is kept in-tab only β€” reloading forgets it.

See inside

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-4's 4096-token window you're using.

decode speed
–
time to first token
–
decode time
–
generated
–
context used (est.)
–
total time
–

Exact chat messages sent to the model (last turn)

Send a message to see the messages array that WebLLM receives.

Why it matters

Phi-4-mini is small enough to run in a tab but rebuilt to be a better instruction-follower and tool-caller than its predecessor. 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.

Use cases

Basics

A clean streaming chat β€” the fundamental "talk to the model" loop.

Practical

Tool routing: Phi-4-mini picks a function and emits a JSON call for it.

Wild

Watch it reason: personas and visible step-by-step thinking.

Multi-model

RAG: MiniLM retrieves from a pasted doc, Phi-4 answers grounded in it.

How the API works

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-4-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.

References