tiny-dlms
Tiny Decision Models That Score Instead of Generate
Two tiny models that look at a situation, score every option and pick one: Rhoa for text, Mēlon for images.
- bAbI 100% · Banking77 85.3%
- CarRacing 913, equal to its teacher
- 97% of unseen mazes solved
Built withPyTorch
ONNX
JavaScriptGymnasiumMatplotlib

Overview
tiny-dlms is two decision models built from scratch in PyTorch. Instead of generating an answer, they read a situation and its options, give every option a score and pick the highest. Every piece is hand-written: tokenizers, Transformer, pre-training, fine-tuning, image model, benchmark and browser demo, with no Hugging Face transformers.
Rhoa reads text. One model, fine-tuned on four datasets at once, answers bAbI stories, finds the intent among 151 CLINC150 or 77 Banking77 options, and tries CommonsenseQA. Mēlon is the same judge on image patches: it learns to drive in CarRacing from a pure-pursuit teacher, and to solve mazes.
I benchmarked 16 Rhoa versions and 4 Mēlon versions on the same held-out test data, next to simple baselines, and compared a word tokenizer with a byte-level BPE. To try it: pip install -e ".[test,car,web]", then QUICK=1 bash scripts/train_all.sh checks the whole pipeline, and scripts/ask.py asks a trained model.
The question
Can a model with a few million weights make good decisions by scoring every option, instead of generating an answer?
Key features
- Two tokenizers from scratch: words and byte-level BPE (GPT-2 style)
- Transformer encoder with RMSNorm, RoPE and SwiGLU, GPT-2 blocks as an option
- Masked-token pre-training on 2 GB of web text, streamed from disk
- One model fine-tuned on bAbI, CLINC150, Banking77 and CommonsenseQA at once
- Health checks before every long run: 15 for Rhoa, 11 for the car, 8 for the maze
- In-browser demo with ONNX Runtime Web, demo videos and a Colab notebook
How it works
One sequence per option
Each option is paired with the context as <cls> context <sep> option. Mēlon does the same with image patches instead of words.
Score every option
An encoder reads each pair, a candidate layer lets the options look at each other, and a score head gives one number per option. A softmax picks the decision.
Pre-train, then fine-tune
Rhoa first learns to guess 15% hidden tokens in web text, then learns to pick the right option. Mēlon learns from a teacher that drives, or from mazes generated on the fly.
Examples

Tech stack
Tokenizers, Transformer, pre-training, fine-tuning and the image model
Export of the best Rhoa for the browser demo
The tokenizer rewritten for the browser, with ONNX Runtime Web
The CarRacing environment where Mēlon learns to drive
Benchmark, pre-training and tokenizer plots
What I learned
- What you pre-train on matters: 4.6 MB of our own task text cost 9 points on bAbI, while 2 GB of web text gained 12.
- My first BPE lost to whole words by up to 12 points. The cause was a missing leading space on the first word of each answer; with a prefix space, the fixed BPE powers the best model.
- Depth plans: on the maze, going from 4 to 8 layers took the solve rate from 50% to 97%.
Limitations
- CommonsenseQA stays at random guessing for every model: a few million weights cannot hold world knowledge.
- More web text gives little: 2 GB instead of 1.5 GB moved the tasks by about ±1 point. At 2.4M weights, size is the limit.
Related projects

Tiny BERT — A Small Encoder and Its BPE Tokenizer, From Scratch
Code is in a private repository for now.
A 9M-parameter BERT-style encoder and its byte-level BPE tokenizer, written and pre-trained from scratch in PyTorch, with no Hugging Face transformers. It is the encoder the rest of my tiny family starts from.
Built with:
PyTorch
Hugging Face Datasets
NumPy
scikit-learnMatplotlib
pytest

tiny-reranker — Text, Image and Audio Rerankers from Scratch
Code is in a private repository for now.
Three small cross-encoders that reorder the top results of a first search stage. One reads a query with a passage, one a caption with a picture, one a caption with a sound. All three are built from scratch in PyTorch on top of tiny-bert.
Built with:
PyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript

Tiny LLM — A Small LLM Built From Scratch
A small LLM written layer by layer in PyTorch. The same code trains from zero or loads GPT-2, Llama (SmolLM2), Qwen2.5 and Pythia with outputs identical to Hugging Face, fine-tunes them with LoRA, and chats in a Streamlit app.
Built with:
PyTorch
Hugging Face TransformersLoRA
Streamlit
Kaggle