Writing a Decoder-Only Transformer for LLM from Scratch in Python
The author of a series of articles describes in detail the implementation of a transformer block for a small decoder-only LLM using the PyTorch framework. Components covered include: Multi-Head Attention with masking, Feed Forward Network with GELU, normalization layer, and residual connections. The article explains the difference from the original architecture: pre-normalization (Pre-LN) is used instead of post-normalization for training stability.
Google/DeepMind
OpenAI
Meta

