Module 10 · Lesson 8 of 12Pro
The transformer, layer by layer
Level Advanced
Reading time 18 min When you finish this page you can Trace a batch of product IDs through a transformer, naming the shape of the tensor after every layer. Explain why each part of a block exists, position vectors, several heads, the feed-forward layer, the residual adds and layer normalization, and what breaks without it. Count a transformer’s parameters and its work per layer, and find the sequence length where attention starts to dominate. Build a pre-norm block in PyTorch, check it against PyTorch’s own layer, and test that the causal mask stops it reading ahead. Why this matters
Transformers now read sequences of clicks, products, words and image patches across most ML teams. Knowing what each layer does tells you where the parameters and the compute go, and which settings, such as the norm position or a missing mask, quietly break a model that still trains.
Play video · 7 min · Prointernals Pro
Black Friday Sale sale
Flat 50% off everything. Our biggest sale ever.
Sale ends this week
10K+ engineers already learning
One plan. Every course. All live and upcoming courses Every paper guide All 40+ tools 320+ startups with hiring contacts Curated external resources Reversed sessions, identical answers
Kartly is our example online store. Its ML team works on a notebook sample of about 1 million orders from 200,000 customers across 50,000 products. Joseph, who leads the growth team, wants a “Next for you” row: after a customer views a few products, show the products they are most likely to view next.
Our biggest sale ever · Black Friday
Flat 50% Off
Pro
Continue reading Unlock every course, now and later
System Design, live AI Engineering, live Data Engineering, live Machine Learning Engineering, live Inference Engineering, coming soon AI Research, coming soon Performance Engineering, coming soon Agent & Harness Engineering, coming soon LLM Fine-tuning, coming soon LLM Pre-training & Post-training, coming soon Reinforcement Learning, coming soon AI Infrastructure & Platform Engineering, coming soon AI Evaluation & Safety, coming soon Forward Deployed Engineering, coming soon Cloud Computing, coming soon DevOps, coming soon System Design AI Engineering Inference EngineeringSoon AI ResearchSoon Performance EngineeringSoon Agent & Harness EngineeringSoon System Design AI Engineering Inference EngineeringSoon AI ResearchSoon Performance EngineeringSoon Agent & Harness EngineeringSoon
Data Engineering LLM Fine-tuningSoon LLM Pre-training & Post-trainingSoon Reinforcement LearningSoon AI Infrastructure & Platform EngineeringSoon Data Engineering LLM Fine-tuningSoon LLM Pre-training & Post-trainingSoon Reinforcement LearningSoon AI Infrastructure & Platform EngineeringSoon
Machine Learning Engineering AI Evaluation & SafetySoon Forward Deployed EngineeringSoon Cloud ComputingSoon DevOpsSoon Machine Learning Engineering AI Evaluation & SafetySoon Forward Deployed EngineeringSoon Cloud ComputingSoon DevOpsSoon
50% off · Annual and Lifetime
BLACKFRIDAY50 Applied at checkout
View all plans → · Already Pro? Sign in
Previous
Attention: the maths of focusing on what matters
Next lesson
Training a small transformer from scratch
On this page 1 / 11
Reversed sessions, identical answers The whole model on one page Order has to be added to the input One block, two sub-layers Why the adds and the norms Seeing the next product would be cheating Where the parameters and the work go Serving the model Common mistakes Check your understanding Summary
↑ ↓ to move Enter to open Esc to close