← All models

text-generation Β· text Β· WebAssembly / WebGPU Β· ~140 MB (q8)

SmolLM2-135M β€” the smallest useful chat LLM, in your browser

SmolLM2-135M-Instruct is the smallest member of Hugging Face's SmolLM2 instruct family β€” only ~135M parameters. That's the interesting bet: how capable can a chat model be when it's tiny enough to download in seconds and run on any device? This page runs it entirely in your browser via Transformers.js, streaming a real chat completion on the universal WebAssembly/CPU path (no GPU required). Nothing is uploaded; there is no API key and no server.

A distinct model from the 360M sibling already in this showcase (SmolLM2-360M) β€” this is the extreme-low-end checkpoint. Its ONNX build exports as the standard llama decoder architecture, so it loads through the ordinary text-generation pipeline. Being this small, it's fast but simple: great for quick replies, rewriting, and structured little tasks β€” not deep reasoning.

At a glance

ModelHuggingFaceTB/SmolLM2-135M-Instruct
Tasktext-generation (causal LM, ChatML chat)
ArchitectureDecoder-only transformer (model_type: llama) β€” hidden size 576, 30 layers, ~135M params
Params / dtype~135M Β· q8 on WASM (onnx/model_quantized.onnx)
BackendWebAssembly (CPU) β€” no WebGPU required; WebGPU used as an optional accelerator with a WASM fallback
Download~140 MB (q8), cached after first load
Best atShort answers, rewriting/summarising, simple structured tasks β€” it's tiny, so keep prompts focused
LicenseApache-2.0 (Hugging Face)
Web APIsWebAssembly, Web Workers, ES module imports (WebGPU optional)

Run it

Heads up: the first load transfers the weights (~140 MB), then it's cached. Because it's only 135M parameters, it loads fast and tokens stream quickly even on the WASM/CPU path β€” the trade-off is that a model this small keeps things simple and can get facts wrong. Keep prompts short and concrete.

assistantThe model auto-loads when it's already cached; otherwise click Download once. Ask me something β€” I stream my answer token by token, entirely on your device.
Sampling controls

See inside β€” the next-token distribution

An LLM never "picks a word" β€” every step it produces a probability over its whole vocabulary, and the sampler chooses one. Below is the exact templated prompt the model receives (ChatML), and β€” from one real forward pass over the current conversation β€” the actual top candidates for the very next token, with their probabilities. Raise the temperature and the tail fattens; drop it and the top token dominates. This is the real distribution, computed on your device, not a mock-up.

Constructed chat template

Load the model and click "Show next-token distribution".

Top candidates for the next token

The bars appear here.

Why it matters

A 135M-parameter chat model that fits in ~140 MB and runs on plain CPU makes an on-device assistant reachable on almost any device β€” an old phone, a locked-down laptop, a kiosk β€” with no GPU, no key, and nothing sent to a server. It won't out-argue a frontier model, but for fast, private, "good enough" text tasks it's a genuinely useful primitive.

Use cases

Basics

Ask a question and watch the answer stream token by token β€” the core chat loop.

Practical

A one-shot rewriter: paste text, pick a tone, get a cleaned-up version on-device.

Wild

Temperature playground: run the same prompt greedy vs hot and compare how wild it gets.

Multi-model

On-device RAG: MiniLM retrieves the relevant snippet, SmolLM2 answers from it.

How the API works

It's the standard Transformers.js text-generation pipeline β€” pass a messages array (the pipeline applies SmolLM2's ChatML template), a TextStreamer for token-by-token output, and your sampling settings:

import { pipeline, TextStreamer } from "@huggingface/transformers";

// q8 runs on the universal WASM/CPU path (WebGPU as an optional accelerator).
const generator = await pipeline(
  "text-generation", "HuggingFaceTB/SmolLM2-135M-Instruct", { device: "wasm", dtype: "q8" },
);

const messages = [
  { role: "system", content: "You are a helpful, concise assistant." },
  { role: "user", content: "Give three tips for staying focused." },
];

const streamer = new TextStreamer(generator.tokenizer,
  { skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });

await generator(messages, {
  max_new_tokens: 200, do_sample: true, temperature: 0.7, top_p: 0.9, streamer,
});

The "see inside" panel runs one raw forward pass β€” generator.model(generator.tokenizer(prompt)) β€” reads the last position's logits, softmaxes them, and shows the real top-k. Everything runs in a Web Worker so generation never blocks the page; the loader auto-inits an already-cached copy and never silently re-downloads.

References