text-generation ยท text ยท WebAssembly ยท ~676 MB (q4)
MobileLLM-R1 is Meta's 2025 on-device reasoning family โ sub-billion-parameter
models post-trained on math, code, and science to reason step by step on a
phone. This page runs the 360M checkpoint entirely in your browser via
Transformers.js on the universal WebAssembly/CPU path โ no GPU
required. Give it a problem and watch it think inside <think> tags, then answer
โ all streamed on your device. No API key, no server, nothing uploaded.
A different family from the other small LLMs here (Qwen, Llama, Gemma, SmolLM, Phi, ERNIE):
MobileLLM-R1 uses Meta's compact llama4_text architecture (deep-and-thin
with grouped-query attention). It is a reasoning model for math/code, not a general
chatbot โ steer it with problems, not trivia. At 360M in 4-bit it is small, so expect small-model
reasoning: often right, sometimes confidently wrong.
| Model | onnx-community/MobileLLM-R1-360M-ONNX (ONNX build of facebook/MobileLLM-R1-360M) |
|---|---|
| Task | text-generation (causal LM, reasoning post-trained) |
| Architecture | Meta MobileLLM-R1 โ a compact decoder-only transformer (model_type: llama4_text), 15 layers, 1024 hidden, GQA (16/4 heads), 128k Llama-4 vocab, ~360M params |
| Params / dtype | ~360M ยท q4 (4-bit) on WASM (onnx/model_q4.onnx) |
| Backend | WebAssembly (CPU) โ no WebGPU required. This is the verified path; expect a few tokens/sec on a laptop CPU. |
| Runtime | Transformers.js 3.7.5 (shared pin โ the llama4_text class is already registered; no version-pin needed) |
| Download | ~676 MB (q4, WASM), cached after first load |
| Specialty | Math, code, and science reasoning โ emits a <think> reasoning trace, then the final answer (often in \boxed{โฆ}) |
| License | FAIR Non-Commercial Research License โ research / educational use only |
| Web APIs | WebAssembly, Web Workers, ES module imports |
Heads up: the first load transfers ~676 MB (4-bit weights), then it's cached. This is a reasoning model โ it will "think out loud" before answering, so give it enough max-tokens to finish. On a CPU it streams at a few tokens per second.
An LLM never "picks a word" โ every step it produces a probability over all 128,256 tokens in its vocabulary, and the sampler chooses one. Below is the exact templated prompt the model receives (Llama-4 chat markup), and โ from one real forward pass over the current conversation โ the actual top candidates for the very next token, with their probabilities. This is the real distribution, computed on your device, not a mock-up.
Load the model and click "Show next-token distribution".
MobileLLM-R1 is a bet that reasoning โ not just fluent chat โ can fit in a sub-billion model that runs on the device in your pocket. Because it is small and CPU-friendly, it makes step-by-step problem solving a local primitive: no GPU, no API bill, no data leaving the machine, and it works offline once cached.
<think> trace is visible, so you can see how it got there and catch mistakes.Give it a problem and watch it reason step by step, streaming on your device.
A step-by-step math & unit helper that shows its working and boxes the answer.
Watch it think: the reasoning trace and answer split into two panes as it streams.
Grounded reasoning: an embedding model retrieves facts, MobileLLM-R1 reasons over them.
It's the standard Transformers.js text-generation pipeline โ pass a messages array
(the pipeline applies MobileLLM-R1's Llama-4 chat template), a TextStreamer for
token-by-token output, and your sampling settings:
import { pipeline, TextStreamer } from "@huggingface/transformers"; // v3.7.5
// Universal WASM/CPU path โ no WebGPU needed. 4-bit weights (~676 MB, cached once).
const generator = await pipeline(
"text-generation", "onnx-community/MobileLLM-R1-360M-ONNX",
{ device: "wasm", dtype: "q4" },
);
const messages = [
{ role: "system", content: "Think step by step, then give the final answer." },
{ role: "user", content: "What is 17 * 24? Work it out step by step." },
];
const streamer = new TextStreamer(generator.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await generator(messages, {
max_new_tokens: 320, do_sample: true, temperature: 0.6, top_p: 0.9, streamer,
});
// โ "<think> 17 * 24 = 17 * 20 + 17 * 4 = 340 + 68 = 408 </think> The answer is \boxed{408}."
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.