On-device
Light enough to run on its own, without a network connection, on smartphones, wearables and IoT equipment.
Public definition · since October 2026
XSLM / noun
A language model with millions to a few hundred million parameters — one step smaller than LLMs and SLMs. It runs on small devices, costs almost nothing to run, and is built to do one job well.
A term coined by SONUB (sonub.com).
Model size is the number of learned numbers (parameters). Each step down is about ten to a thousand times smaller.
| Model | Size (log scale) | Parameters | Where it runs |
|---|---|---|---|
| LLMLarge Language Model | tens to hundreds of billions | GPU servers in data centers | |
| SLMSmall Language Model | around a few billion | a powerful computer or a single GPU | |
| XSLMExtra Small Language Model | millions to a few hundred million | smartphones, wearables, IoT devices | |
| Referencethe learning model in this repository | 1,248 | Python 3, no GPU |
Light enough to run on its own, without a network connection, on smartphones, wearables and IoT equipment.
An SLM needs several GB of VRAM just to load. An XSLM runs in a few hundred MB of memory or less, so deploying and running it costs almost nothing.
Not an encyclopedia like an LLM, but one task done very well: summarizing, classifying text, function calling, or routing for an AI agent.
An XSLM is a chain of small programs. Each one reads the file made by the previous one and makes the next file. Change an earlier file, and rebuild everything after it.
prepare.pydata/raw.txt → train.txt, val.txt. Q/A lines, split into training and validation text. The data format decides what the model becomes good at.
tokenizer.pyCharacter-level BPE. Learns merge rules and turns text into token IDs and back — decode(encode(text)) == text.
engine.py model.pyAutograd (Value, backward) and a GPT: token + position embedding, causal attention, MLP, residuals, output head.
train.pyNext-token prediction with cross-entropy loss and gradient descent. Saves a resumable checkpoint after every step.
generate.pyPredict the next token, pick one, append, repeat — with temperature, top-k and seed.
runner.pyLoads the weights once and serves an HTTP API: GET /health, POST /generate.
xchat.pyA simple chatbot for testing the XSLM you built, in your web browser. It is only a test tool. What it is for
export.pyWrites model.safetensors, config.json and tokenizer.json for Hugging Face.
XChat is just for testing. It is a simple chatbot that shows whether the XSLM you built can answer. It is not the final product. Once the test goes well, the model moves on:
Chat with your model in the web browser and check its answers.
Upload the model so anyone can download it.
Download the model and test it the way people test any other model. These tools only load the formats and architectures they support, usually GGUF, which export.py does not produce.
Convert the model and run it inside your own app.
pairs = Counter(zip(ids, ids[1:]))
pair, frequency = pairs.most_common(1)[0]
new_id = len(vocab)
vocab.append(vocab[pair[0]] + vocab[pair[1]])
ids = merge(ids, pair, new_id)
q = linear(h, w['query'])
keys.append(linear(h, w['key']))
values.append(linear(h, w['value']))
scores = [dot(q, k) / width ** 0.5 for k in keys]
attention = softmax(scores) # only past positions
loss = model.loss(window[:-1], window[1:])
loss.backward()
for p in model.parameters:
p.data -= learning_rate * p.grad * scale
logits = model.forward(ids[-context:])[-1]
candidates = ranked[:top_k]
weights = [exp((logits[i] - peak) / temperature)
for i in candidates]
token = rng.choices(candidates, weights=weights)[0]
The reference/ folder is the complete course code. Pure Python 3, standard library only — no pip, no GPU, no API key, no pretrained weights.
git clone https://github.com/thruthesky/xslm
cd xslm/reference
python3 prepare.py
python3 tokenizer.py
python3 engine.py
python3 train.py
python3 generate.py
python3 runner.py &
python3 xchat.py
train 12
val 3
vocab: 40 merges: 12
roundtrip: OK [29, 13, 14, 1, 30]
y = 15.0 dy/dx = 8.0
parameters: 1248 resume: 0
validation: 3.7568
step: 1 loss: 3.6875
...
saved: checkpoints/model.json
XSLM Runner: ('127.0.0.1', 8765)
You> hi
| Weights | Shape | Count |
|---|---|---|
| Token embedding | 40 × 8 | 320 |
| Position embedding | 12 × 8 | 96 |
| Query, key, value, project | 4 × (8 × 8) | 256 |
| MLP expand, contract | 16 × 8 + 8 × 16 | 256 |
| Output head | 40 × 8 | 320 |
| Total — vocabulary 40, width 8, context 12, 1 block, 1 head | 1,248 | |
After 20 training steps the answers are still mostly random — that is expected. The model is shrunk to the smallest size so you can read every calculation, but the parts are the same. Grow the same structure and train it on data for one job, and it becomes a practical XSLM.
The full course types and trains an XSLM inside a Linux terminal that runs in the web browser. Nothing to install.
The term XSLM (Extra Small Language Model) was coined by SONUB (sonub.com) in October 2026, as the name of its course for learning to build an AI from scratch. This page is the public definition of the term.
XSLM (Extra Small Language Model). SONUB, 2026. https://thruthesky.github.io/xslm/