Evidence at a Glance
Three transformer layers, six attention heads, 384-wide embeddings, and a tied 50,257-token vocabulary.
The final checkpoint preserves the complete training and validation-loss history.
Measured from the checkpoint's held-out TinyStories validation batches.
Overview
TinyStories GPT is a decoder-only language model implemented and trained directly in PyTorch. The published checkpoint contains 44,019,840 parameters across three transformer blocks, six attention heads, 384-wide embeddings, a 256-token context window, and tied input/output embeddings over the GPT-2 BPE vocabulary.
The training pipeline owns more than the network definition. It streams source text in bounded chunks, caches token IDs to a raw binary file, memory-maps the result, creates a 90/10 train-validation split, and supports automatic model sizing, warm-up plus cosine learning-rate decay, gradient clipping, validation sampling, resumable checkpoints, and loss history.
The model was trained on the TinyStories corpus for 45,001 optimizer steps. A CLI and local threaded web demo both load the real checkpoint on CPU and expose prompt, temperature, length, and top-k sampling controls. No hosted model is substituted behind the interface.
The Challenge
The TinyStories corpus is large enough that naïvely reading all text and token IDs into Python objects creates avoidable memory pressure. Training also needs to survive long runs without losing optimizer state or the evidence needed to judge generalisation.
The GPT-2 vocabulary makes the embedding table a large part of a compact model's parameter budget, so architecture size, context, data volume, and tokenizer choice have to be considered together rather than quoting a small layer count as the whole model size.
Key Engineering Decisions
Implement the Transformer Directly
Causal self-attention, MLP blocks, residual paths, normalization, weight tying, loss, and autoregressive sampling remain inspectable instead of hiding behind a pretrained-model API.
Stream and Memory-Map Tokens
One-megabyte text chunks feed a cached int32 token file, and NumPy memmap pages training slices on demand instead of holding the corpus twice in memory.
Train for Recovery and Comparison
Checkpoints retain architecture, weights, optimizer state, step, tokenizer, and loss history; validation runs every 100 steps and resumable snapshots are written every 1,000.
Run the Actual Checkpoint in the Demo
The local server loads the trained model on CPU and bounds temperature and output length, keeping the showcase honest and predictable.
What I Owned
Results
Valuable Lessons
For a compact language model, tokenizer vocabulary can dominate the parameter budget; parameter count needs architectural context to mean anything.
A model demo is credible when it loads the real checkpoint and publishes measured training facts, not when it only presents a curated text sample.
