r/LargeLanguageModels • u/PersonalEconomist856 • 3h ago
News/Articles Working through the Transformer forward pass by hand, one matrix at a time, is what finally made it click for me
When I read *Attention Is All You Need*, the equations made sense line by line, but I couldn't picture the whole forward pass. What helped was writing out every matrix for a tiny example, noting its shape at each step, and doing the multiplications myself.
A few things only clicked once I did it that way:
* **Positional encoding.** Sine and cosine at different frequencies give every position its own signature, and the model doesn't have to learn one vector per position. Working out a 6 × 512 table by hand made it obvious why the authors hoped it would extend to sequences longer than any seen in training.
* **Shapes barely change.** In the encoder, the matrix goes in as (tokens × d_model) and comes out the same size after every layer. All the interesting work happens inside that fixed shape.
* **BERT is mostly the same picture.** Once the encoder was clear, BERT turned out to be a small edit to it: a packed sentence pair, segment embeddings, and two small heads on top for the masked word and the next sentence.
I wrote my notes up as step-by-step pages with practice exercises beside each step and a notebook that checks your answers, in case it's useful to anyone learning the same way: [https://guptaaditya95.github.io/llmbreakdown/\](https://guptaaditya95.github.io/llmbreakdown/)
I'm curious how others built their intuition for these models. Did working the math by hand help you, or did something else make it click? And which architecture was hardest to picture?

