TinyStories GPT-124M
A Compact Language Model Built from Scratch in PyTorch
2 min readupdated
This model is a GPT-style decoder with 124.4 million parameters, trained entirely from scratch on the TinyStories dataset (a collection of short children's stories). All components—from the attention mechanism and perceptron layers to the training loop and tokenization—are implemented as clear PyTorch code without relying on heavy external frameworks. The result is coherent fairytale-style text, making the model ideal for learning the inner workings of transformers from the inside out.
Key features
- GPT architecture: 12 layers, hidden state dimension of 768, 12 attention heads, and a 1024-token context window.
- Training from scratch: Trained on a single RTX 5085 graphics card for 50,000 steps on 3.28 billion tokens.
- Quality: The final validation loss metric reached 1.133, while perplexity stays around 3.09.
- Easy launch: A custom implementation of the
GPTclass allows weights to be loaded directly viasafetensors.
What you can do
- Run generation: Use the script to create your own short stories from an arbitrary text prompt.
- Study the code: Explore the model architecture, written from scratch in pure PyTorch, for educational purposes.
- Reproduce training: Kick off the full model training process on the TinyStories dataset using configuration files.
Example
Prompt: Once upon a time
Result: Once upon a time, there was a little girl named Lily. She loved to play outside and pick flowers. One day, she found a big squash in her garden...
Read more
Details• Dataset: TinyStories (English language, simple children's stories)
• Hardware requirements: Trained on 1× NVIDIA RTX 5080 (16 GB)
• Limitations: English language only, no instruction tuning or RLHF (the model is not a chatbot)










Comments