← All models

text-generation · text · WebGPU + WASM · ~360 MB

SmolLM2 360M — a chat model that runs even without a GPU

A 360-million-parameter instruct LLM from Hugging Face, small enough to stream tokens on your own device — on the GPU via WebGPU when there is one, and genuinely on the CPU via WebAssembly when there isn't. Chat with it, steer it with a system prompt and sampling controls, then open the hood and watch the real probability distribution it samples each next token from. No server, no API key, nothing uploaded.

At a glance

ModelHuggingFaceTB/SmolLM2-360M-Instruct
Tasktext-generation (causal LM, chat-tuned)
ArchitectureLlama-style decoder-only transformer, 360M params, 49k-token vocab
Params / dtype360M · q4f16 on WebGPU · q8 on WebAssembly
BackendWebGPU when a real adapter exists, else WebAssembly (CPU) — auto-picked
Download~360 MB, cached after first load
LicenseApache-2.0
Web APIsWebGPU (optional), WebAssembly, Web Workers

Unlike the WebGPU-only chat models in this catalogue, SmolLM2-360M is small enough that its WebAssembly path is genuinely usable — slower than the GPU, but real. That's why this page auto-initialises everywhere, no "needs a GPU" wall.

Run it — chat

assistantLoad the model, then say hello. I stream my reply token by token, right here on your device.
Sampling controls

See inside — the next-token distribution

An LLM never "chooses a word" — every step it produces a probability over all 49,152 tokens in its vocabulary, and the sampler picks one. Below is the exact templated prompt the model receives, 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-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 chat model that runs even without a GPU turns language into a client-side primitive you can ship to everyone, not just visitors with modern graphics hardware: private, offline-capable, and free to run at any scale. No inference bill, no data leaving the device.

Use cases

Basics

Ask a question, watch the answer stream — the core chat loop.

Practical

On-device text tools: rewrite, classify, and extract from any text.

Wild

A tiny agent that plays a choose-your-own-adventure with you.

Multi-model

RAG: MiniLM retrieves from a pasted doc, SmolLM2 answers grounded in it.

How the API works

SmolLM2 uses the standard text-generation pipeline. Pass a messages array (the pipeline applies the chat template for you), a TextStreamer for token-by-token output, and your sampling settings. The only twist is the device pick — WebGPU with q4f16 if a real adapter is present, WebAssembly with q8 if not:

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

const gpu = "gpu" in navigator && await navigator.gpu.requestAdapter();
const generator = await pipeline(
  "text-generation",
  "HuggingFaceTB/SmolLM2-360M-Instruct",
  gpu ? { dtype: "q4f16", device: "webgpu" }   // fast path
      : { dtype: "q8",    device: "wasm"   },   // real CPU fallback
);

const messages = [
  { role: "system", content: "You are a helpful, concise assistant." },
  { role: "user", content: "Explain WebAssembly in one sentence." },
];

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

await generator(messages, {
  max_new_tokens: 256, 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 the UI never blocks.

References