Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLMs for Engineers

Free · sign in to start and track progress

1 · Inside the transformer

  • 1Tokens and embeddings
  • 2Attention, step by step
  • 3The transformer block

    Exercise answers

    • Answer: Build a block and verify parameter counts against real models
    • Answer: Prove RoPE is relative, numerically

2 · How models are trained

  • 4Pretraining and scaling laws
  • 5Post-training an assistant

3 · Running models in production

  • 6Sampling and hallucination
  • 7Context windows, KV cache and caching
  • 8Reasoning models and extended thinking
  • 9Choosing and comparing models
CapstoneChoose a model for document extractionReference implementation

Module 1 · Inside the transformer · Lesson 3

The transformer block

The parts of the block that are not attention, namely the MLP, residual connections, normalisation and rotary position embeddings, and how they add up to a model whose parameters you can count from its config.

70 min 2 videos 3 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvRun Hugging Face models on CPU

By the end of this lesson you can

  • Write the equations of a modern pre-norm block (RMSNorm, attention, SwiGLU MLP, residual adds) and explain each design choice
  • Explain the MLP as a key-value memory and why most of a dense model's parameters live there
  • Show with a worked example why rotary position embeddings make attention scores depend only on relative position
  • Count the parameters of GPT-2 small and Llama 3 8B from their hyperparameters
  • Distinguish total from active parameters in a mixture-of-experts model

On this page

  • The block, as two equations
  • The MLP: where most parameters live
  • A key-value memory
  • Mixture of experts: big but sparse
  • Residual connections
  • Normalisation
  • Rotary position embeddings
  • A worked example
  • Putting it together in code
  • Worked example: counting parameters
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01The block, as two equations
  2. 02The MLP: where most parameters live
  3. 03Residual connections
  4. 04Normalisation
  5. 05Rotary position embeddings
  6. 06Putting it together in code
  7. 07Worked example: counting parameters
  8. 08Connections
  9. 09Summary

Sources & further reading

  • Attention Is All You NeedPaper · Vaswani et al. · Google · 2017Section 3 defines the original block (post-norm, ReLU MLP, sinusoidal positions). Read it to see what modern models changed.
  • RoFormer: Enhanced Transformer with Rotary Position EmbeddingPaper · Su, Lu, Pan, Murtadha, Wen, Liu · 2021The RoPE paper. Section 3.2 derives the 2D rotation case used in this lesson, then generalises it to d dimensions.
  • Transformer Feed-Forward Layers Are Key-Value MemoriesPaper · Geva, Schuster, Berant, Levy · 2020The key-value reading of the MLP. Sections 3 and 4 show what individual keys detect and what their values promote.
  • The Llama 3 Herd of ModelsPaper · Llama Team, Meta · Meta · 2024Table 3 gives the hyperparameters used in this lesson's parameter count. A good example of a modern dense recipe (RMSNorm, SwiGLU, RoPE, GQA).
  • On Layer Normalization in the Transformer ArchitecturePaper · Xiong et al. · 2020Why pre-norm trains stably without a long learning-rate warm-up. The introduction and Figure 1 are enough.
  • GLU Variants Improve TransformerPaper · Noam Shazeer · Google · 2020Two pages that introduce SwiGLU, the gated MLP used by most open-weight models.
  • Mixtral of ExpertsPaper · Jiang et al. · Mistral AI · 2024A clear, short description of a sparse mixture-of-experts MLP with top-2 routing.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 9 more sections
  • 3 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks