Micro-LLM
A Llama-style language model written from scratch in PyTorch, small enough to pre-train on a laptop, then fine-tuned with reinforcement learning.
Why
To understand how large language models work by building every part of one, instead of calling an API.
What is in it
- Model. A Llama-style decoder-only Transformer written in PyTorch, with RMSNorm and SwiGLU feed-forward layers.
- Data. The TinyStories dataset, tokenised with tiktoken’s byte-pair encoding.
- Pre-training. A training loop with checkpointing and evaluation, sized so the test configuration pre-trains in about 30 minutes on a laptop GTX 1050.
- Alignment. A PPO stage that fine-tunes the pre-trained model towards a target sentiment: the RLHF recipe used for large models, at small scale. It builds directly on the reinforcement learning work from my MSc.



