text-generation Β· hybrid-reasoning chat LLM Β· Transformers.js (ONNX) Β· WebGPU Β· ~2.1 GB
SmolLM3 is Hugging Face's fully-open 3B model, and it can think out loud on demand:
flip thinking on and it emits a <think>β¦</think> chain of
reasoning before answering β you watch the trace stream live β or flip it off for a
fast, direct reply. One model, two behaviours, toggled with SmolLM3's /think and
/no_think modes (its chat template's enable_thinking switch). Unlike the
WebLLM chat pages, this one runs on Transformers.js (the ONNX build), so you also
see the exact templated prompt. WebGPU only β a ~2.1 GB download, cached after first load.
| Model | HuggingFaceTB/SmolLM3-3B |
|---|---|
| ONNX build | HuggingFaceTB/SmolLM3-3B-ONNX (onnx/model_q4f16) |
| Runtime | Transformers.js (ONNX Runtime Web) β not WebLLM. The smollm3 model class ships in @huggingface/transformers 3.7.5. |
| Task | text-generation (instruction-tuned, hybrid reasoning) |
| Params / dtype | 3B Β· q4f16 (4-bit weights, fp16 compute) |
| Thinking control | enable_thinking in the chat template β the /think Β· /no_think modes. One model, two behaviours. |
| Chat template | ChatML with a real system role, plus a <think> reasoning segment in thinking mode |
| Backend | WebGPU only here β a 3B model is impractical on WASM. Gated on a real GPU adapter (~3 GB memory). |
| Download | ~2.1 GB, cached after first load |
| License | Apache 2.0 |
| Web APIs | WebGPU, Web Workers, ES module imports |
How it differs from the other chat pages: SmolLM3 is a hybrid reasoning model like Qwen3, but it runs on Transformers.js/ONNX rather than WebLLM β a different runtime and a distinct, fully-open SmolLM3 architecture from Hugging Face. It's a much bigger, reasoning-capable successor to the built SmolLM2 360M page.
Heads up: loading transfers ~2.1 GB the first time (then it's cached). Best on a GPU with β₯3 GB of memory.
<think> trace before answering (/think).
A reasoning model spends tokens in two places: the <think> trace (private
reasoning you'd normally never see) and the answer. The split below is measured
live. Turn thinking off and the reasoning count drops to zero and the reply comes faster β thinking
trades latency and tokens for better answers on hard prompts. Time-to-first-token is the prefill
cost; everything after is decode. Because this runs on Transformers.js, the exact templated prompt
(including the /think vs /no_think generation prompt) is shown below.
Send a message to see the exact prompt string the model receives.
SmolLM3 is a fully-open 3B model β open weights, open data recipe β with a genuinely useful hybrid reasoner. Running it on Transformers.js puts that on the client: for easy prompts you turn thinking off and get a fast reply; for hard ones β multi-step maths, planning, careful extraction β you turn it on and the model works through the problem in a visible trace before committing. All private by construction, free to run, and available offline once cached.
A clean streaming chat with the thinking toggle β the fundamental loop.
Reasoned extraction: strict JSON and step-by-step problem solving with the trace on.
Thinking on vs off β the SAME hard prompt run both ways, side by side.
RAG: MiniLM retrieves from a pasted doc, SmolLM3 reasons over the passages.
Transformers.js runs the ONNX build through the standard pipeline("text-generation", β¦)
path on the WebGPU backend. SmolLM3's hybrid mode is selected by the chat template's
enable_thinking switch, so this page applies the template itself with that flag, then
streams the continuation with a TextStreamer, splitting the <think>
reasoning from the answer in worker.js:
import { hasWebGPU } from "/lib/webai.js";
import { pipeline, TextStreamer } from "@huggingface/transformers"; // 3.7.5
// A 3B model needs a GPU β gate on a real adapter (headless requestAdapter() β null).
if (!(await hasWebGPU())) { showNeedsWebGPU(); } // never a faked reply
else {
const gen = await pipeline("text-generation", "HuggingFaceTB/SmolLM3-3B-ONNX",
{ device: "webgpu", dtype: "q4f16", progress_callback: setProgress });
const messages = [
{ role: "system", content: "You are a concise assistant." },
{ role: "user", content: "Is 97 prime?" },
];
// enable_thinking picks /think vs /no_think β we template it ourselves so it's inspectable.
const prompt = gen.tokenizer.apply_chat_template(messages,
{ add_generation_prompt: true, tokenize: false, enable_thinking: true });
const streamer = new TextStreamer(gen.tokenizer, { skip_prompt: true, callback_function: onPiece });
await gen(prompt, { max_new_tokens: 512, do_sample: true, temperature: 0.6, top_p: 0.95, streamer });
// worker.js splits the streamed β¦ trace from the answer.
}
Everything here runs exactly that path in worker.js, off the main thread, and gates on
a real WebGPU adapter first. No adapter β a labelled needs-WebGPU state, never a canned answer.