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 the small Mēlon driving CarRacing 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" "gymnasium[box2d]"
import torch
from tiny_dlm.car import OPTION_ACTIONS, make_env, preprocess
from tiny_dlm.hub import from_pretrained
from tiny_dlm.vision import encode_options
model, tokenizer, config = from_pretrained("liamsi/tiny-dlms-melon-car-small")
idx = encode_options(config["option_texts"], tokenizer)[None] # the 15 driving options
mask = torch.ones(1, idx.size(1), dtype=torch.bool)
env = make_env() # CarRacing-v3
obs, _ = env.reset(seed=0)
for _ in range(1000):
choice, probs = model.decide(preprocess(obs)[None], idx, mask) # 96x96 frame -> 48x48 -> one option
obs, reward, done, truncated, _ = env.step(OPTION_ACTIONS[choice.item()])
if done or truncated:
break
Or with the repo: python scripts/car_drive.py --ckpt <checkpoint> records a video.
| Layers x width | 2 x 64 (4 heads) + 1 layer where the options look at each other |
| Input | 48x48 colour image, 36 patches of 8x8 |
| Blocks | RMSNorm, RoPE, SwiGLU |
| Weights | 0.21 M |
| Training steps | 3,500 |
| Options | steer full left and accelerate · steer full left and coast · steer medium left and accelerate · steer medium left and coast · steer slight left and accelerate · steer slight left and coast · go straight and accelerate · go straight and coast · steer slight right and accelerate · steer slight right and coast · steer medium right and accelerate · steer medium right and coast · steer full right and accelerate · steer full right and coast · brake |
Imitation: it copies a pure-pursuit teacher that drove 45 tracks (frames recorded with scripts/car_record.py).
| Driver (5 unseen tracks, CarRacing-v3) | Mean score |
|---|---|
| this model | 913 |
| the teacher (pure pursuit) | 913 |
| always straight | -26 |
| random | -40 |
| 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 |