tiny-dlms
Collection
Tiny decision models from scratch in PyTorch: Rhoa reads text, Mēlon reads images. • 7 items • Updated
Mēlon (μῆλον, the golden apple) is a tiny decision model that looks at an image and picks one option written in words. This is Mēlon solving mazes from pixels. The options are scored all at once and a softmax gives one probability each; nothing is generated.
Written and trained from scratch in PyTorch (no Hugging Face transformers): tokenizer, Transformer, training.
Code, all the other checkpoints and the full benchmark: GitHub · project page.
A learning project, not a production model.
pip install "tiny-dlm[hub] @ git+https://github.com/benisalla/tiny-dlms"
import random, torch
from tiny_dlm import maze
from tiny_dlm.hub import from_pretrained
from tiny_dlm.vision import encode_options
model, tokenizer, config = from_pretrained("liamsi/tiny-dlms-melon-maze")
idx = encode_options(config["option_texts"], tokenizer)[None] # go up / down / left / right
mask = torch.ones(1, idx.size(1), dtype=torch.bool)
walls, player, goal = maze.new_maze(random.Random(0))
choice, probs = model.decide(maze.render(walls, player, goal)[None], idx, mask)
print(config["option_texts"][choice.item()])
| Layers x width | 8 x 128 (4 heads) + 1 layer where the options look at each other |
| Input | 48x48 colour image, 64 patches of 6x6 |
| Blocks | RMSNorm, RoPE, SwiGLU |
| Weights | 2.39 M |
| Training steps | 28,000 |
| Options | go up · go down · go left · go right |
Imitation: mazes generated on the fly, the target is the shortest path, with detours so it learns to recover.
| Player (200 unseen mazes) | Solved | Steps / shortest path |
|---|---|---|
| this model | 97.0% | 1.00 |
| the teacher (shortest path) | 100.0% | 1.00 |
| greedy | 74.0% | 1.47 |
| random | 8.5% | 4.36 |
| Model | |
|---|---|
| tiny-dlms-rhoa | the best Rhoa: pre-trained on 2 GB of web text, then fine-tuned |
| tiny-dlms-rhoa-small | the small Rhoa, pre-trained on 2 GB of web text, then fine-tuned |
| tiny-dlms-rhoa-gpt2 | Rhoa with GPT-2 blocks (LayerNorm, learned positions, GELU), pre-trained on 2 GB of web text |
| tiny-dlms-rhoa-base | the pre-trained Rhoa before fine-tuning: masked-token prediction on 2 GB of web text |
| tiny-dlms-melon-car | Mēlon driving CarRacing from pixels |
| tiny-dlms-melon-car-small | the small Mēlon driving CarRacing from pixels |
| tiny-dlms-melon-maze | Mēlon solving mazes from pixels |