References: The transformer block: where it comes together
Source material
Section titled “Source material”Source material:• Stanford CME 295: Transformers & Large Language Models, Autumn 2025, Lecture 1 Instructor: Afshine Amidi & Shervine Amidi, Stanford University YouTube: https://www.youtube.com/watch?v=Ub3GoFaUcds Course site: https://cme295.stanford.edu/syllabus/2025/ Cheatsheet: https://cme295.stanford.edu/cheatsheet/ License (lecture video): as published on Stanford's public YouTube channel License (Amidi cheatsheets): MITClawdemy provides original notes, summaries, and quizzes derived from this materialfor educational purposes. All rights to the original lecture remain with Stanford andthe instructors.Going deeper
Section titled “Going deeper”A short list, chosen for durability. Each link is a specific next step, not a generic "learn more."
-
The Illustrated Transformer by Jay Alammar. A visual treatment of the full transformer block. Where this lesson kept the math minimal, Alammar draws every matrix shape and walks the residual paths in color. Read this if you want to see every box drawn out with full color and shape annotations.
-
The Annotated Transformer from Harvard NLP. Reproduces the original Vaswani paper's architecture in PyTorch alongside the paper's text. A direct path from this lesson to runnable code. Especially useful for the Add+Norm and FFN sub-layers, where reading the implementation makes the order-of-operations obvious.
-
3Blue1Brown's transformer series. Grant Sanderson covers the full block as part of his neural-networks playlist; the transformer-architecture episode and the multi-head attention episode are both worth watching after this lesson. Episode numbering in the playlist has shifted over time; sort by date or scan the titles to find the transformer entries.
-
Stanford CME 295 cheatsheet by the Amidi twins. MIT-licensed. A compact reference for the full block; useful as a single-sheet recall aid during the practice section.
-
A Survey of Transformers by Lin et al., 2021. A taxonomy of transformer variants up through 2021, organized by which sub-layer is varied. Useful for the structural map even though specific variants have moved on; read it after this lesson for a tour of how researchers have substituted on each of the boxes covered here.
Adjacent topics
Section titled “Adjacent topics”Topics that build on or sit beside this one.
-
What is NOT in a vanilla transformer block. Modern open-source models add several pieces this lesson does not cover: KV caching for inference, sliding-window or sparse attention for long contexts, FlashAttention for memory efficiency, and mixture-of-experts (MoE) feed-forward variants. Each is its own optimization on top of the basic block; understanding this lesson is the prerequisite for understanding any of them.
-
Training, prompting, RLHF. This lesson covers the architecture; turning a trained transformer into a useful assistant involves separate machinery (instruction tuning, reinforcement learning from human feedback, prompt design, system prompts). Later lessons in this track cover them, starting with Pretraining: predicting the next word.
-
Encoder versus decoder versus encoder-decoder. The original transformer paper had both an encoder and a decoder; modern decoder-only models (GPT-style) drop the encoder. The block-level mechanics this lesson covers are the same; the difference is in how blocks are stacked and which attention masks are applied. The encoder-decoder and T5 lesson in this track picks that up.
-
Where to go next. You now have the architecture in your head. Earlier in this track, How models know word order covered how position gets into the model. The next lessons take the block's pieces one at a time: How models inject position into attention: RoPE, Why transformers normalize: LayerNorm to RMSNorm, and Attention efficiency: sliding windows, KV cache.
Original sources
Section titled “Original sources”The primary sources for the architecture this lesson covers.
-
"Attention Is All You Need", Vaswani et al., NeurIPS 2017. The transformer paper. Section 3 lays out the full block (multi-head attention, feed-forward, residuals, LayerNorm, sinusoidal position encoding); Figure 1 is the architecture diagram this lesson's practice section asked you to annotate. Read it after this lesson and almost every diagram will be familiar.
-
"Attention is Not All You Need: Pure Attention Loses Rank Doubly Exponentially with Depth", Dong, Cordonnier, and Loukas, 2021. The rank-collapse result this lesson cites for why a pointwise feed-forward step is needed.
-
"On Layer Normalization in the Transformer Architecture", Xiong et al., 2020. The formal analysis of why Pre-LN trains more stably than Post-LN.
-
"Layer Normalization", Ba, Kiros, Hinton, 2016. The LayerNorm paper. Predates the transformer by a year and was originally proposed for recurrent networks; the transformer adopted it because it works for variable-length sequences. Read for the comparison with BatchNorm.
-
"Deep Residual Learning for Image Recognition", He et al., 2016. The ResNet paper. Introduced residual connections for very deep image networks; the transformer borrowed the idea wholesale. A key "make deep networks trainable" idea of the deep learning era.
-
"Root Mean Square Layer Normalization", Zhang and Sennrich, 2019. The RMSNorm paper. Argues that the mean-centering step in LayerNorm is unnecessary for transformer performance; RMSNorm is now standard in many large open-source models because it is computationally cheaper.
-
"RoFormer: Enhanced Transformer with Rotary Position Embedding", Su et al., 2021. The RoPE paper. Proposes rotary position embeddings as a replacement for sinusoidal position encoding; widely adopted by recent open-source transformers because it generalizes better to sequence lengths beyond what was seen during training.
Community discussion
Section titled “Community discussion”None selected for this lesson. The public discussion of the full transformer block has consolidated into the Alammar visual post, the Annotated Transformer, and the academic papers above. If a canonical thread surfaces, it will be added at the next quarterly review.