Add model card: 54.8M from-scratch TinyStories GPT, verified params + held-out PPL 5.24
Browse files
README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
language: en
|
| 5 |
+
tags:
|
| 6 |
+
- tiny
|
| 7 |
+
- tiny-lm
|
| 8 |
+
- tiny-model
|
| 9 |
+
- slm
|
| 10 |
+
- small-language-model
|
| 11 |
+
- from-scratch
|
| 12 |
+
- tinystories
|
| 13 |
+
- gpt
|
| 14 |
+
- bpe
|
| 15 |
+
datasets:
|
| 16 |
+
- ronendagan/TinyStories
|
| 17 |
+
metrics:
|
| 18 |
+
- perplexity
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# tinystories-50m
|
| 22 |
+
|
| 23 |
+
A **54,804,992-parameter** transformer language model trained **from scratch** on
|
| 24 |
+
[TinyStories](https://huggingface.co/datasets/ronendagan/TinyStories), a corpus of
|
| 25 |
+
simple, repetitive children's stories. It is the 50M scale-up in the
|
| 26 |
+
`tinystories-24m` → `tinystories-50m` lineage (the 24M sibling was coherent at
|
| 27 |
+
18.2 tok/param; this one trains at 8.17 tok/param on the same narrow domain).
|
| 28 |
+
|
| 29 |
+
It writes fluent, on-domain children's stories. It is **not** a general
|
| 30 |
+
language model — out-of-domain generation degrades, and it should not be used
|
| 31 |
+
for anything beyond the story domain it was trained on.
|
| 32 |
+
|
| 33 |
+
## Architecture
|
| 34 |
+
|
| 35 |
+
| Field | Value |
|
| 36 |
+
|---|---|
|
| 37 |
+
| Parameters | **54,804,992** (exact; verified against the safetensors header) |
|
| 38 |
+
| Layers (L) | 16 |
|
| 39 |
+
| d_model (D) | 512 |
|
| 40 |
+
| Heads (H) | 8 (head dim 64) |
|
| 41 |
+
| FFN dim | 2048 (4× D) |
|
| 42 |
+
| Vocab | 8192 (BPE) |
|
| 43 |
+
| Max seq len | 512 |
|
| 44 |
+
| Embeddings | **weight-tied** (lm_head = tok) |
|
| 45 |
+
| Norm | RMSNorm (pre-norm, 2 per block + final) |
|
| 46 |
+
| Activation | GELU |
|
| 47 |
+
| Attention | causal, no bias in linear layers |
|
| 48 |
+
| Dtype | float32 |
|
| 49 |
+
|
| 50 |
+
Parameter breakdown (sums exactly to 54,804,992):
|
| 51 |
+
|
| 52 |
+
- token embedding: 8192 × 512 = 4,194,304
|
| 53 |
+
- position embedding: 512 × 512 = 262,144
|
| 54 |
+
- 16 blocks × 3,146,752 = 50,348,032
|
| 55 |
+
- 2 × RMSNorm (512) + qkv (512×1536) + proj (512×512) + fc1 (512×2048) + fc2 (2048×512)
|
| 56 |
+
- final RMSNorm: 512
|
| 57 |
+
|
| 58 |
+
## Training
|
| 59 |
+
|
| 60 |
+
- **Data:** TinyStories (ronendagan/TinyStories), ~447.86M tokens after BPE-8192
|
| 61 |
+
re-tokenization, 8.17 tokens/param.
|
| 62 |
+
- **Optimizer:** AdamW, cosine LR decay with warmup (peak 6e-4).
|
| 63 |
+
- **Batch:** 64, seq 512 → 32,768 tokens/step.
|
| 64 |
+
- **Steps:** 13,668 (one full epoch). Best checkpoint at step 13,250.
|
| 65 |
+
- **Hardware:** single NVIDIA RTX 5090 (32 GB), peak ~15 GB.
|
| 66 |
+
- **Final val loss:** 1.6371 (best ckpt 1.6566 @ step 13,250).
|
| 67 |
+
|
| 68 |
+
## Evaluated numbers
|
| 69 |
+
|
| 70 |
+
- **Held-out perplexity (TinyStories val split):** **5.24** (best ckpt,
|
| 71 |
+
val cross-entropy 1.6566 → exp = 5.2412). This is the honest metric for a
|
| 72 |
+
narrow-domain model; standard general benchmarks (BLiMP/ARC/PIQA) are not
|
| 73 |
+
meaningful here and are deliberately not reported.
|
| 74 |
+
- **Coherence:** 9/9 seeded generations (3 story-start prompts × 3 seeds) are
|
| 75 |
+
fluent, on-domain, with consistent characters and correct punctuation. Minor
|
| 76 |
+
artifacts expected at this scale (occasional garbled quote char, a couple of
|
| 77 |
+
logical slips).
|
| 78 |
+
|
| 79 |
+
## Files
|
| 80 |
+
|
| 81 |
+
| File | What |
|
| 82 |
+
|---|---|
|
| 83 |
+
| `model.safetensors` | weights (210 MB, 99 tensors, float32) |
|
| 84 |
+
| `tokenizer.json` | BPE-8192 tokenizer (`tokenizers` format) |
|
| 85 |
+
| `config.json` | architecture config |
|
| 86 |
+
| `load_model.py` | self-contained loader + `TinyStoriesGPT` class |
|
| 87 |
+
|
| 88 |
+
## Usage
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
from load_model import load
|
| 92 |
+
model, tok = load()
|
| 93 |
+
ids = tok.encode("Once upon a time,")
|
| 94 |
+
out = model.generate(torch.tensor([ids]).cuda(), 100, temp=0.8, top_k=40)
|
| 95 |
+
print(tok.decode(out[0].tolist(), skip_special_tokens=True))
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## What it is and is not
|
| 99 |
+
|
| 100 |
+
- **Is:** a small, from-scratch, on-domain story generator. Good for studying
|
| 101 |
+
how a ~55M transformer learns a narrow, repetitive domain.
|
| 102 |
+
- **Is not:** a general-purpose LM. Do not expect coherent output on code,
|
| 103 |
+
math, or open-domain text. The low perplexity is domain-specific.
|