Skip to content
imaged

Text generation (chat)

SmolLM2 360M Instruct

A small chat model that answers questions, writes and explains in English, entirely on the device: Hugging Face's SmolLM2 with 360 million parameters. Apache-2.0.

Apache-2.0language modelllmchattext generationsmollm2hugging faceofflineapache-2.0
Choose a variant

About this model

SmolLM2 360M Instruct is a chat model: give it a conversation and it writes the next answer, as text that streams while it is written. It answers everyday questions, explains, drafts short messages and writes simple code, in English, with no network connection.

It is Hugging Face's SmolLM2 with 360 million parameters, trained on 4 trillion tokens of web, code and math data and then tuned to follow instructions. The pack holds the model and its tokenizer; Slab applies the model's chat template (ChatML, with its default system message) to the app's messages.

Slab reads the prompt 64 tokens at a time and writes the answer one token at a time, with the key/value cache kept in the engine and shared by both. A follow-up question reuses the cached tokens of the conversation so far, and the answer can be sampled (temperature, top-k, top-p, min-p, repeat penalty, seed) or greedy.

What you can build

  • Answer questions and explain things inside an app, offline
  • Draft short messages, titles and summaries
  • Turn short instructions into simple code snippets
  • A private assistant whose conversations never leave the device

Explain simply

f16
Input
Explain why the sky is blue to a ten-year-old.
Output
The sky is blue because of a thing called sunlight. Sunlight is a big ball of light that comes from the sun. When sunlight hits the Earth, it scatters in different directions. Blue light is the light that scatters the most because it is smaller and has less energy. This is why the sky looks blue to us.

(Greedy decoding on Metal, 67 tokens.)

Write

f16
Input
Write a short, friendly message reminding my team about Friday's 10 am meeting.
Output
Hi Team,

I hope you're all doing well! I wanted to remind you about our Friday 10 am meeting. It's a great opportunity to discuss any ongoing projects, share updates, and align everyone on our goals for the day.

If you have any questions or need to discuss anything, please don't hesitate to reach out. We'll be meeting in the conference room at 10 am.

See you on Friday!

Best,
SmolLM

(Greedy decoding on Metal, 101 tokens.)

Code

f16
Input
Write a Python function that checks whether a word is a palindrome.
Output
Here's a Python function that checks whether a word is a palindrome:

```python
def is_palindrome(word):
    word = word.lower()
    return word == word[::-1]
```

This function works by first converting the word to lowercase to ensure the comparison is case-insensitive. It then checks if the word is equal to its reverse (`word[::-1]`). If they are equal, the function returns `True`, indicating that the word is a palindrome. Otherwise, it returns `False`.

You can use this function like this:

```python
print(is_palindrome("radar"))  # True
print(is_palindrome("hello"))  # False
```

(Greedy decoding on Metal, 160 tokens.)

A follow-up

f16
Input
user: Suggest a name for a small bakery by the sea.
assistant: 1. The Sea's Sweet Bite: A small bakery by the sea, where the sea air and the sea salt are the perfect ingredients for a sweet and salty treat.
2. The Coastal Cravings: A bakery by the sea, where the sea air and the sea salt are the perfect ingredients for a sweet and salty treat.
3. The Sea's Sweet Delight: A small
user: Make it shorter, two words at most.
Output
1. The Sea's Sweet Bite
2. The Coastal Cravings
3. The Sea's Sweet Delight

(Greedy decoding on Metal, 24 tokens. The 121 tokens of the earlier turns were reused from the cache.)

Variants & downloads

Choose the build for your app

Model files are hosted on Google Drive. Large files may open a confirmation page before downloading.

Standard

Slab

Weights stored in FP16, decoded to FP32 when loading. The same answers as the upstream model in our checks (see Accuracy).

Platforms: macos · android

smollm2-360m-instruct-f16.slab

698 MB · Hosted download

Download
SHA-256 checksum
ca99e0c7478e43237075e3814ddd548a65e321390b25dadd7dbd614a6e60b64a

LICENSE-Apache-2.0.txt

11 KB

Download
SHA-256 checksum
a331c76d2a6b4095a0bfc208582f4f458fee8f92fd7f9be149f6b9bc83f42d62
Conversion details
command
hf download HuggingFaceTB/SmolLM2-360M-Instruct --revision a10cc1512eabd3dde888204e902eca88bddb4951 --local-dir SmolLM2-360M-Instruct --include "*.json" --include model.safetensors python - <<'EOF' # An N-token decoder step (N dynamic: 1 to write the answer, 64 to read the # prompt in chunks): the tokens, their positions, the key/value cache of the # tokens so far (keys transposed), its additive mask and the mask within the # chunk in; the tokens' next-token logits and their keys and values out. No # node depends on N (no Expand, the softmax written out), so the two sizes # share their weights. The output layer reads the tied token embedding. import json, torch from transformers import AutoModelForCausalLM torch.set_grad_enabled(False) d = "SmolLM2-360M-Instruct"; T = 2048 m = AutoModelForCausalLM.from_pretrained(d, dtype=torch.float32).eval() c = m.config; L = c.num_hidden_layers; H = c.num_attention_heads; Hk = c.num_key_value_heads; Dh = c.hidden_size // H; G = H // Hk theta = json.load(open(f"{d}/config.json"))["rope_theta"] inv = 1.0 / (theta ** (torch.arange(0, Dh, 2).float() / Dh)); ang = torch.arange(T).float()[:, None] * inv[None]; ang = torch.cat([ang, ang], -1) class Chunk(torch.nn.Module): def __init__(self, m): super().__init__(); self.m = m self.register_buffer("cos_t", ang.cos()); self.register_buffer("sin_t", ang.sin()) def forward(self, input_ids, position_ids, self_k, self_v, mask, chunk_mask): mm = self.m.model; N = input_ids.shape[1] x = mm.embed_tokens(input_ids)[0] cos = self.cos_t[position_ids[0]][:, None, :]; sin = self.sin_t[position_ids[0]][:, None, :] rope = lambda t: t * cos + torch.cat([-t[..., Dh // 2:], t[..., : Dh // 2]], -1) * sin cm = chunk_mask.view(1, N, 1, N) nk, nv = [], [] for i, l in enumerate(mm.layers): a = l.self_attn; y = l.input_layernorm(x) q = (rope(a.q_proj(y).view(N, H, Dh)) * (Dh ** -0.5)).view(N, Hk, G, Dh).permute(1, 0, 2, 3).reshape(Hk, N * G, Dh) kt = rope(a.k_proj(y).view(N, Hk, Dh)).permute(1, 2, 0) v = a.v_proj(y).view(N, Hk, Dh).permute(1, 0, 2) nk.append(kt); nv.append(v) sc = q @ self_k[i] + mask sn = ((q @ kt).view(Hk, N, G, N) + cm).reshape(Hk, N * G, N) mx = torch.maximum(sc.amax(-1, keepdim=True), sn.amax(-1, keepdim=True)) ec = torch.exp(sc - mx); en = torch.exp(sn - mx) o = (ec @ self_v[i] + en @ v) / (ec.sum(-1, keepdim=True) + en.sum(-1, keepdim=True)) x = x + a.o_proj(o.view(Hk, N, G, Dh).permute(1, 0, 2, 3).reshape(N, H * Dh)) f = l.mlp; y = l.post_attention_layernorm(x) x = x + f.down_proj(f.act_fn(f.gate_proj(y)) * f.up_proj(y)) x = mm.norm(x) return mm.embed_tokens.weight @ x.t(), torch.stack(nk), torch.stack(nv) z = torch.zeros; n = 4 torch.onnx.export(Chunk(m), (z(1, n, dtype=torch.long), z(1, n, dtype=torch.long), z(L, Hk, Dh, T), z(L, Hk, T, Dh), z(1, T), z(1, n, n)), "step.onnx", input_names=["input_ids", "position_ids", "self_k", "self_v", "mask", "chunk_mask"], output_names=["logits", "new_k", "new_v"], opset_version=17, dynamo=False, dynamic_axes={"input_ids": {1: "n"}, "position_ids": {1: "n"}, "chunk_mask": {1: "n", 2: "n"}, "logits": {1: "n"}, "new_k": {3: "n"}, "new_v": {2: "n"}}) EOF slab-load convert step.onnx step1.slab --input input_ids=1x1 --input position_ids=1x1 --input self_k=32x5x64x2048 --input self_v=32x5x2048x64 --input mask=1x2048 --input chunk_mask=1x1x1 slab-load convert step.onnx step64.slab --input input_ids=1x64 --input position_ids=1x64 --input self_k=32x5x64x2048 --input self_v=32x5x2048x64 --input mask=1x2048 --input chunk_mask=1x64x64 slab-load quantize step1.slab smollm2-360m-instruct-f16.slab --f16 slab-load quantize step64.slab step64-f16.slab --f16 slab-load buckets smollm2-360m-instruct-f16.slab step64-f16.slab slab-load tokenizer smollm2-360m-instruct-f16.slab SmolLM2-360M-Instruct/tokenizer.json --pad "<|im_end|>" slab-load chat smollm2-360m-instruct-f16.slab SmolLM2-360M-Instruct slab-load meta set smollm2-360m-instruct-f16.slab default_backend.macos=gpu

Integration examples

Python

python

import slab

cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
llm = slab.Session(cfg, "smollm2-360m-instruct-f16.slab")

chat = slab.Input()
chat.add_message("user", "Explain why the sky is blue to a ten-year-old.")
chat.max_tokens = 200
chat.temperature = 0.7      # 0 (the default): always the most likely word

for piece in llm.generate(chat):   # text as it is written
    print(piece, end="", flush=True)

Device & backend compatibility

Pack default: macos / GPU. About 4 times faster than the CPU: 79 tokens/s against 20, and the first words after 35 ms against 427 ms for a short chat prompt.

Available execution backends for SmolLM2 360M Instruct
PlatformEngineStatusPrecision
apple

CPU

CPU

Supported

Measured on macOS.

f32
apple

Metal

GPU

Supported

Measured on macOS. The default.

f32
apple

Apple Neural Engine

NPU

Not supported

Tried on M1 Max: the model's 32 layers and output (token embeddings in, vocabulary split in three) compile for the Neural Engine, all but a few small operations placed on it. A one-token step took 48-61 ms against 8.9 ms on the GPU and 64 tokens 64 ms against 21 ms; compiling took about a minute at every open, and in FP16 the most likely next token changed at 6% of positions. Slab runs this pack on the GPU or CPU.

—
android

CPU

CPU

Not supported

Not offered on phones: a language model on a phone's CPU is too slow to use.

—
android

Vulkan

GPU

Supported

Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17.

f32

Performance

Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.

Mac with Apple M1 Max

Slab · GPU

macOS 26.6.2

12.7 ms

Measured time · scope below

f16Session open (ms): 565 Platform: macos Runs: 5 Input: a chat prompt of 43 tokens, 128 new tokens Measured: 2026-10-31

Milliseconds per generated token while streaming (79 tokens/s), median of 5 answers with the cache cleared. The first piece of text after 35 ms (the prompt included); a prompt of 452 tokens read in 263 ms. Opening takes 4.9 s the first time on a device, while Slab compiles the GPU program and keeps it in the cache folder, then 565 ms. Peak memory after opening and one answer: 1834 MB.

Mac with Apple M1 Max

Slab · CPU

macOS 26.6.2

49.3 ms

Measured time · scope below

f16Session open (ms): 607 Platform: macos Runs: 5 Input: a chat prompt of 43 tokens, 128 new tokens Measured: 2026-10-31

Milliseconds per generated token while streaming (20 tokens/s), median of 5 answers with the cache cleared. The first piece of text after 427 ms (the prompt included); a prompt of 452 tokens read in 3633 ms. Peak memory after opening and one answer: 1872 MB.

Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)

Slab · GPU

Android 17

144.1 ms

Measured time · scope below

f16Session open (ms): 2390 Platform: android Runs: 5 Input: a chat prompt of 44 tokens, 128 new tokens Measured: 2026-11-06

Milliseconds per generated token while streaming (7 tokens/s), median of 5 answers with the cache cleared, greedy. The first piece of text after 758 ms (a prompt of 44 tokens included). Each token is about 3,700 small GPU dispatches on Vulkan; recording them on the CPU takes most of the time. open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 1824 MB.

Accuracy checks

macos · GPU · f16

transformers 5.21 with the upstream model in FP32, greedy decoding of up to 100 tokens, on 30 everyday prompts (facts, how-to, writing, code, arithmetic) with SmolLM2's chat template

The same answer, token for token, for 30 of 30 prompts.

macos · CPU · f16

transformers 5.21 with the upstream model in FP32, greedy decoding of up to 100 tokens, on 30 everyday prompts (facts, how-to, writing, code, arithmetic) with SmolLM2's chat template

The same answer, token for token, for 30 of 30 prompts.

Before you choose this model

  • Small: it makes factual mistakes and follows detailed instructions loosely (asked for two words, it gave three in our example). Check its answers where they matter.
  • English: other languages work poorly.
  • The conversation fits in 2048 tokens (about 1,500 words), the cache this pack was built with.
  • The first open on a device takes about 5 s on the GPU while Slab compiles the model; later opens take 0.6 s if the app keeps the cache folder.
  • No images and no JSON-schema constraints with this pack.
  • Runs on the GPU or CPU, not the Neural Engine: in our trial the Neural Engine was 3 to 7 times slower than the GPU and less exact (see Backends).