A Hands-On Introduction to Modern Decoder-Only Transformers
Abstract
We follow one message through a modern decoder-only Transformer, from byte-level subword tokenization to autoregressive generation and next-token training. Equations and tensor shapes connect learned embeddings, causal self-attention with pre-normalization and rotary position embeddings (RoPE), SwiGLU feed-forward networks, and a tied vocabulary head to a single-file PyTorch implementation. The 370,848-parameter model can be trained on a CPU. Tests check individual operations, and a small synthetic corpus exercises the full training-to-generation path. We compare the miniature model with documented architectures and explain how caching, batching, and attention kernels affect computation and memory.
Create a lesson
Metadata
- Categories
- cs.CL, cs.LG
- Comments
- 34 pages, 11 figures, 4 tables
Related papers
Prompt-Based Speculative Decoding for Grammatical Error Correction
Shared title terminologycs.CLRyszard Staruch, Filip Graliński
What Makes Decoder-Based Sentence Embeddings Strong? Rethinking Encoder and Decoder Architectures for Sentence Embeddings
Shared title terminologycs.CLTatsuki Okada, Toru Sugimoto, Yusuke Sakai et al.
What Survives a Loop? A Shared Decision Model for Encoders and Decoders
Shared title terminologycs.CLYixin Peng, Stefan Decker