File size: 3,161 Bytes
d6132b9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | ---
license: mit
library_name: tiny-dlms
pipeline_tag: reinforcement-learning
tags:
- tiny-dlms
- decision-model
- from-scratch
- pytorch
- imitation-learning
- vision-transformer
- maze
---
# tiny-dlms-melon-maze: Mēlon 8x128 (maze)
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](https://github.com/benisalla/tiny-dlms) · [project page](https://benisalla.github.io/tiny-dlms/).
A learning project, not a production model.
## Usage
```bash
pip install "tiny-dlm[hub] @ git+https://github.com/benisalla/tiny-dlms"
```
```python
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()])
```
## Model
| | |
|---|---|
| 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 |
## Training
Imitation: mazes generated on the fly, the target is the shortest path, with detours so it learns to recover.
## Results
| 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 |
## The tiny-dlms models
| Model | |
|---|---|
| [tiny-dlms-rhoa](https://huggingface.co/liamsi/tiny-dlms-rhoa) | the best Rhoa: pre-trained on 2 GB of web text, then fine-tuned |
| [tiny-dlms-rhoa-small](https://huggingface.co/liamsi/tiny-dlms-rhoa-small) | the small Rhoa, pre-trained on 2 GB of web text, then fine-tuned |
| [tiny-dlms-rhoa-gpt2](https://huggingface.co/liamsi/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](https://huggingface.co/liamsi/tiny-dlms-rhoa-base) | the pre-trained Rhoa before fine-tuning: masked-token prediction on 2 GB of web text |
| [tiny-dlms-melon-car](https://huggingface.co/liamsi/tiny-dlms-melon-car) | Mēlon driving CarRacing from pixels |
| [tiny-dlms-melon-car-small](https://huggingface.co/liamsi/tiny-dlms-melon-car-small) | the small Mēlon driving CarRacing from pixels |
| [tiny-dlms-melon-maze](https://huggingface.co/liamsi/tiny-dlms-melon-maze) | Mēlon solving mazes from pixels |
|