mini-gpt-30m
A 30M-parameter GPT language model built from scratch in plain PyTorch and trained on 2 billion tokens of English. It's model 7 of mini-gpt, a project where the tokenizer, model, data pipeline, training loop and tests are all written from scratch.
It's a base model: it continues text. It is not instruction-tuned and doesn't follow commands.
The water cycle is one of the main advantages of the environment. It helps in the development of a
good water supply for a population. With this, a river is formed for a variety of different forms
of life.
The English is fluent; the facts are not reliable (see Limitations).
Model details
- Developed by: Mohamed Rasheq
- Model type: decoder-only transformer (causal language model), trained from random weights
- Language: English
- License: MIT
- Code: github.com/Mohamedrasheq/mini-gpt (training, data and evaluation scripts)
| Parameters | 29,893,120 |
| Layers / width / heads | 8 / 512 / 8 |
| Context | 512 tokens |
| Design | RoPE positions, SwiGLU feed-forward, RMSNorm, tied input/output embeddings, no biases |
| Tokenizer | byte-level BPE, 8,192 tokens (id 8191 = `< |
| Weights | model.safetensors, float32 |
Uses
Intended uses
- Learning how a small language model is built, trained and evaluated
- A small, fast baseline for research on tokenizers, data mixes, training or evaluation
- A starting point for fine-tuning experiments
Out of scope
- Any use where correct facts matter (answers, advice, education material)
- Chat or instruction following: the model has no instruction or safety tuning
- Production systems
How to use
pip install torch safetensors huggingface_hub
from huggingface_hub import snapshot_download
import sys
folder = snapshot_download("rasheq/mini-gpt-30m")
sys.path.insert(0, folder)
from generate import load, generate
model, tok = load(folder)
print(generate(model, tok, "The water cycle is", n_tokens=100, temperature=0.8, top_k=50))
Or download the files and run python generate.py "The water cycle is". The model is our own
design, so it loads with the included model.py and tokenizer.py, not with transformers.
Training
Data: 2.0B tokens.
- 1.8B from FineWeb-Edu
sample-10BT(files 000-002) - 0.2B from TinyStories V2, about 10% of every batch, to keep simple and fluent story English
Preprocessing: each document is encoded with the 8K tokenizer and ends with <|endoftext|>.
Training sequences are 512-token windows taken at random positions. FineWeb-Edu validation and
test documents come from a file (013) that was never used for training or for the tokenizer.
Hyperparameters
| Steps | 7,630 |
| Tokens per step | 262,144 (64 sequences × 512 tokens × 8 accumulation steps) |
| Optimizer | AdamW, β1 0.9, β2 0.95, weight decay 0.1 (2D weights only) |
| Learning rate | 1.5e-3, 300 warm-up steps, cosine decay to 1.5e-4 |
| Gradient clipping | 1.0 |
| Precision | bf16 mixed precision (fp32 master weights) |
| Hardware | one GPU |
Final validation loss: 3.004 per token on FineWeb-Edu and 1.382 per token on TinyStories. Validation loss fell smoothly for the whole run, with no sign of overfitting.
Evaluation
All tests are zero-shot and use mini-gpt's
evaluate.py. The model writes
nothing: each answer is scored by its log-probability after the question, and the highest wins.
Prompts follow EleutherAI's lm-evaluation-harness. GPT-2 124M is scored by the same script as a
reference.
| Test | Data (size) | Metric | Random | mini-gpt-30m | GPT-2 (124M) |
|---|---|---|---|---|---|
| BLiMP | 67 grammar sets (67,000 sentence pairs) | accuracy | 50% | 76.1% | 82.5% |
| ARC-Easy | test (2,376 questions) | acc_norm | 25% | 39.9% | 40.5% |
| PIQA | validation (1,838) | acc_norm | 50% | 58.2% | 62.5% |
| HellaSwag | validation (10,042) | acc_norm | 25% | 27.9% | 29.9% |
| LAMBADA (OpenAI) | test (5,153 passages) | accuracy | 0% | 22.1% | 33.7% |
| WinoGrande | XL validation (1,267) | accuracy | 50% | 50.7% | 50.4% |
| FineWeb-Edu | 5,000 held-out web pages | loss per character ↓ | - | 0.790 | 0.719 |
| TinyStories | official valid file, second half | loss per character ↓ | - | 0.397 | 0.622 |
- acc_norm divides each answer's log-probability by its length, so long answers aren't penalised. Loss per character compares models with different tokenizers fairly.
- This model is about 4× smaller than GPT-2 and was trained on different data (GPT-2: WebText). It's close on ARC-Easy and HellaSwag, and behind on grammar, PIQA and long-passage LAMBADA. WinoGrande is at chance for both.
- Other evaluation tools can give slightly different numbers because of prompt formatting.
Limitations
- Made-up facts: at this size the model learns how English sounds, not reliable knowledge. Don't use it as a source of information.
- Short memory: it sees at most 512 tokens and loses the thread in long text.
- English only, and it may repeat itself or drift off topic.
- Bias: it learned from web text and can reflect the biases in it. It has no safety tuning.
License
The weights and code are released under the MIT license. Training data: FineWeb-Edu (ODC-By 1.0) and TinyStories (CDLA-Sharing-1.0).
Citation
@misc{mini-gpt-30m,
title = {mini-gpt-30m: a 30M-parameter GPT trained from scratch},
author = {Mohamed Rasheq},
year = {2026},
url = {https://huggingface.co/rasheq/mini-gpt-30m}
}
Contact
Questions and issues: github.com/Mohamedrasheq/mini-gpt/issues
- Downloads last month
- 41
Datasets used to train rasheq/mini-gpt-30m
roneneldan/TinyStories
Evaluation results
- accuracy on BLiMPself-reported76.050
- normalized accuracy on ARC-Easytest set self-reported39.900
- normalized accuracy on PIQAvalidation set self-reported58.220
- normalized accuracy on HellaSwagvalidation set self-reported27.910
- accuracy on LAMBADA (OpenAI)test set self-reported22.100
- accuracy on WinoGrandevalidation set self-reported50.670
