tiny-dlms-melon-car: weights and card
Browse files- README.md +83 -0
- config.json +52 -0
- model.safetensors +3 -0
- tokenizer.json +1 -0
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: tiny-dlms
|
| 4 |
+
pipeline_tag: reinforcement-learning
|
| 5 |
+
tags:
|
| 6 |
+
- tiny-dlms
|
| 7 |
+
- decision-model
|
| 8 |
+
- from-scratch
|
| 9 |
+
- pytorch
|
| 10 |
+
- imitation-learning
|
| 11 |
+
- vision-transformer
|
| 12 |
+
- CarRacing-v3
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# tiny-dlms-melon-car: Mēlon 4x128 (car)
|
| 16 |
+
|
| 17 |
+
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 driving CarRacing from pixels. The options are scored all at once and a softmax gives one probability each; nothing is generated.
|
| 18 |
+
|
| 19 |
+
Written and trained from scratch in PyTorch (no Hugging Face `transformers`): tokenizer, Transformer, training.
|
| 20 |
+
Code, all the other checkpoints and the full benchmark: [GitHub](https://github.com/benisalla/tiny-dlms) · [project page](https://benisalla.github.io/tiny-dlms/).
|
| 21 |
+
A learning project, not a production model.
|
| 22 |
+
|
| 23 |
+
## Usage
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
pip install "tiny-dlm[hub] @ git+https://github.com/benisalla/tiny-dlms" "gymnasium[box2d]"
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
import torch
|
| 31 |
+
from tiny_dlm.car import OPTION_ACTIONS, make_env, preprocess
|
| 32 |
+
from tiny_dlm.hub import from_pretrained
|
| 33 |
+
from tiny_dlm.vision import encode_options
|
| 34 |
+
|
| 35 |
+
model, tokenizer, config = from_pretrained("liamsi/tiny-dlms-melon-car")
|
| 36 |
+
idx = encode_options(config["option_texts"], tokenizer)[None] # the 15 driving options
|
| 37 |
+
mask = torch.ones(1, idx.size(1), dtype=torch.bool)
|
| 38 |
+
env = make_env() # CarRacing-v3
|
| 39 |
+
obs, _ = env.reset(seed=0)
|
| 40 |
+
for _ in range(1000):
|
| 41 |
+
choice, probs = model.decide(preprocess(obs)[None], idx, mask) # 96x96 frame -> 48x48 -> one option
|
| 42 |
+
obs, reward, done, truncated, _ = env.step(OPTION_ACTIONS[choice.item()])
|
| 43 |
+
if done or truncated:
|
| 44 |
+
break
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Or with the repo: `python scripts/car_drive.py --ckpt <checkpoint>` records a video.
|
| 48 |
+
|
| 49 |
+
## Model
|
| 50 |
+
|
| 51 |
+
| | |
|
| 52 |
+
|---|---|
|
| 53 |
+
| Layers x width | 4 x 128 (4 heads) + 1 layer where the options look at each other |
|
| 54 |
+
| Input | 48x48 colour image, 36 patches of 8x8 |
|
| 55 |
+
| Blocks | RMSNorm, RoPE, SwiGLU |
|
| 56 |
+
| Weights | 1.34 M |
|
| 57 |
+
| Training steps | 4,000 |
|
| 58 |
+
| 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 |
|
| 59 |
+
|
| 60 |
+
## Training
|
| 61 |
+
|
| 62 |
+
Imitation: it copies a pure-pursuit teacher that drove 45 tracks (frames recorded with `scripts/car_record.py`).
|
| 63 |
+
|
| 64 |
+
## Results
|
| 65 |
+
|
| 66 |
+
| Driver (5 unseen tracks, CarRacing-v3) | Mean score |
|
| 67 |
+
|---|---|
|
| 68 |
+
| **this model** | **913** |
|
| 69 |
+
| the teacher (pure pursuit) | 913 |
|
| 70 |
+
| always straight | -26 |
|
| 71 |
+
| random | -40 |
|
| 72 |
+
|
| 73 |
+
## The tiny-dlms models
|
| 74 |
+
|
| 75 |
+
| Model | |
|
| 76 |
+
|---|---|
|
| 77 |
+
| [tiny-dlms-rhoa](https://huggingface.co/liamsi/tiny-dlms-rhoa) | the best Rhoa: pre-trained on 2 GB of web text, then fine-tuned |
|
| 78 |
+
| [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 |
|
| 79 |
+
| [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 |
|
| 80 |
+
| [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 |
|
| 81 |
+
| [tiny-dlms-melon-car](https://huggingface.co/liamsi/tiny-dlms-melon-car) | Mēlon driving CarRacing from pixels |
|
| 82 |
+
| [tiny-dlms-melon-car-small](https://huggingface.co/liamsi/tiny-dlms-melon-car-small) | the small Mēlon driving CarRacing from pixels |
|
| 83 |
+
| [tiny-dlms-melon-maze](https://huggingface.co/liamsi/tiny-dlms-melon-maze) | Mēlon solving mazes from pixels |
|
config.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library": "tiny-dlms",
|
| 3 |
+
"kind": "melon",
|
| 4 |
+
"model_args": {
|
| 5 |
+
"block_size": 48,
|
| 6 |
+
"vocab_size": 17,
|
| 7 |
+
"n_layer": 4,
|
| 8 |
+
"n_cand_layer": 1,
|
| 9 |
+
"n_head": 4,
|
| 10 |
+
"n_embd": 128,
|
| 11 |
+
"drop_rate": 0.1,
|
| 12 |
+
"bias": false,
|
| 13 |
+
"pad_id": 0,
|
| 14 |
+
"sep_id": 3,
|
| 15 |
+
"pool": "candidate",
|
| 16 |
+
"n_kv_head": 0,
|
| 17 |
+
"head_dim": 0,
|
| 18 |
+
"norm_type": "rmsnorm",
|
| 19 |
+
"norm_eps": 1e-06,
|
| 20 |
+
"pos_encoding": "rope",
|
| 21 |
+
"rope_base": 10000.0,
|
| 22 |
+
"activation": "silu",
|
| 23 |
+
"gated_mlp": true,
|
| 24 |
+
"intermediate_size": 0
|
| 25 |
+
},
|
| 26 |
+
"stage": "car",
|
| 27 |
+
"training_steps": 4000,
|
| 28 |
+
"image_args": {
|
| 29 |
+
"image_size": 48,
|
| 30 |
+
"patch_size": 8,
|
| 31 |
+
"channels": 3
|
| 32 |
+
},
|
| 33 |
+
"option_texts": [
|
| 34 |
+
"steer full left and accelerate",
|
| 35 |
+
"steer full left and coast",
|
| 36 |
+
"steer medium left and accelerate",
|
| 37 |
+
"steer medium left and coast",
|
| 38 |
+
"steer slight left and accelerate",
|
| 39 |
+
"steer slight left and coast",
|
| 40 |
+
"go straight and accelerate",
|
| 41 |
+
"go straight and coast",
|
| 42 |
+
"steer slight right and accelerate",
|
| 43 |
+
"steer slight right and coast",
|
| 44 |
+
"steer medium right and accelerate",
|
| 45 |
+
"steer medium right and coast",
|
| 46 |
+
"steer full right and accelerate",
|
| 47 |
+
"steer full right and coast",
|
| 48 |
+
"brake"
|
| 49 |
+
],
|
| 50 |
+
"params": 1343872,
|
| 51 |
+
"repo": "liamsi/tiny-dlms-melon-car"
|
| 52 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63407b022f17ffe402c5693eacae1490e4fd65889450f73f1df09797fd02d1d2
|
| 3 |
+
size 5379640
|
tokenizer.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"itos": ["<pad>", "<unk>", "<cls>", "<sep>", "<mask>", "accelerate", "and", "brake", "coast", "full", "go", "left", "medium", "right", "slight", "steer", "straight"]}
|