text-generation · reasoning model · WebLLM (MLC) · WebGPU · ~4.5 GB
DeepSeek-R1-Distill-Llama-8B is a reasoning model: distilled from DeepSeek-R1, it's
trained to think out loud — emitting a full chain of thought wrapped in <think>…</think>
before it commits to a final answer. It runs entirely in your browser, compiled to WebGPU by MLC's
WebLLM engine. This page does the thing that makes an R1 model special: it
separates the reasoning trace from the answer — the thinking goes in a collapsible
panel, the answer stands on its own — and counts reasoning tokens vs answer tokens live. Nothing is
uploaded. WebLLM is WebGPU-only, so it needs a real GPU with enough VRAM.
| Model | deepseek-ai/DeepSeek-R1-Distill-Llama-8B |
|---|---|
| MLC build | DeepSeek-R1-Distill-Llama-8B-q4f16_1-MLC (verified present in WebLLM's prebuiltAppConfig) |
| Runtime | WebLLM / MLC — not Transformers.js. Weights are precompiled to WebGPU shaders. |
| Task | text-generation (reasoning / chain-of-thought) |
| Params / dtype | 8B · q4f16_1 (4-bit weights, fp16 compute) |
| Backend | WebGPU only — no WASM fallback. Gated on a real GPU adapter (~5 GB VRAM). |
| Download | ~4.5 GB, cached after first load |
| Reasoning format | Emits <think>…</think> then the answer (the chat template opens the block) |
| Context window | 4096 tokens (MLC prebuilt config) |
| License | MIT (base: Llama-3.1 community license) |
| Web APIs | WebGPU, Web Workers, ES module imports, <details> |
A reasoning model spends most of its tokens thinking, then a few on the answer — and that
split is the whole story. The reasoning trace is parsed out of the raw stream by finding the
</think> boundary: everything before it (minus a leading <think>)
is reasoning; everything after is the answer. The counters below are measured live, so you can see
how much compute the model spent reasoning versus answering, and how long it took before the
answer (not just the first token) started.
Ask something to see the messages array that WebLLM receives.
Reasoning models trade tokens for reliability: by working a hard problem out in the open before answering, they get maths, logic, and multi-step tasks right far more often than a model that blurts a single guess. Running one on WebLLM makes that a private, client-side primitive — and because the reasoning is visible, you can audit how the model reached its answer, not just take the answer on faith.
A maths / logic puzzle, with the model's working shown separately from the answer.
Step-by-step problem solving and debugging-reasoning over a snippet or scenario.
Watch it reason through a lateral-thinking riddle or plan a multi-step task.
R1 plans the approach → Qwen2.5-Coder writes the code that implements it.
WebLLM gives you an OpenAI-shaped chat API backed by a WebGPU engine. The reasoning is not a special
API feature — it's in the text the model generates. You stream the completion as normal,
then split the stream on the </think> boundary to separate reasoning from answer.
This page uses the shared helpers in lib/webllm.js plus a small splitThink()
parser, all inside a Web Worker so the UI stays responsive:
import { webGPUAdapterAvailable, createEngine, streamChat }
from "/lib/webllm.js";
import { splitThink } from "./webllm-chat.js";
if (!(await webGPUAdapterAvailable())) {
showNeedsWebGPU(); // never a faked reasoning trace
} else {
const engine = await createEngine({
model: "DeepSeek-R1-Distill-Llama-8B-q4f16_1-MLC",
onProgress: (p) => setProgress(p.text, p.progress), // ~4.5 GB, cached after first load
});
// R1-distill: keep the system prompt minimal; the model reasons on its own.
const messages = [{ role: "user", content: "How many times do a clock's hands overlap in 24 hours?" }];
let acc = "";
await streamChat(engine, { messages, temperature: 0.6, max_tokens: 1024 }, (delta) => {
acc += delta;
const { reasoning, answer, thinking } = splitThink(acc);
renderReasoning(reasoning, thinking); // collapsible panel
renderAnswer(answer); // shown distinctly once arrives
});
}
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 reasoning trace.