← govind p lal
AI and ML Bootcamp · Lecture 7 · lecture notes

What Changed Since 2017: Modern Transformer Upgrades

In short — The original transformer is still the base of today's LLMs, but four parts have been upgraded for speed, stability and memory. This lecture recaps the decoder-only block and masked attention, then covers RMSNorm, pre-normalization, SwiGLU, RoPE and Grouped Query Attention. Models like Llama, Gemma and Mistral use these changes.

Decoder-only block and masked attention

builds on Lecture 2: Week 1 - AI and ML | Fast-tracking the course of AI | 18/01/2026, Lecture 5: Week 4 - AI&ML | Transformers: Part 2 | 07/02/2026

Original transformer had an encoder and a decoder (useful for translation, e.g. French -> English). Language models use only the right part. -> Decoder-only models.

Block order: tokens -> token embeddings -> positional information -> repeated transformer blocks (attention, add + normalize, feed-forward) -> linear layer -> softmax -> next token.

Masked multi-head attention

The Problem: the full training text is available, so unmasked attention could read the answer. The model would copy, not learn.

The Solution: in the attention score matrix (tokens x tokens), set every value above the diagonal to negative infinity. Softmax turns them into 0. Works for any sequence length.

!

The mask is negative infinity, not zero, because softmax(-inf) = 0 and the remaining weights still sum to 1.

Four upgrades overview

PartOldModern
NormalizationLayerNorm (post-layer)RMSNorm (pre-layer)
Feed-forward activationReLUSwiGLU
Positional encodingSinusoidal (absolute, fixed)RoPE (rotary, relative)
AttentionMulti-headGrouped Query Attention

Used by Llama, Gemma, Mistral and similar models. The core idea of attention is unchanged. These are memory and compute optimizations.

RMSNorm and pre-normalization

builds on Lecture 4: Week 3 - AI and ML | Transformers- Part 1 | 31/01/2026

Normalization only keeps numbers from getting too big or too small. It is not related to softmax.

LayerNorm does four things: compute mean and centre at zero, compute variance, normalize, then scale and shift. RMSNorm removes the mean subtraction and bias. Experiments showed centering around zero does not matter.

Pre-norm vs post-norm

SwiGLU feed-forward

builds on Lecture 3: Week 2 - AI and ML | Neural Networks from Scratch | 24/01/2026, Lecture 3: Week 2 - AI and ML | Neural Networks from Scratch | 24/01/2026

The Problem: ReLU zeroes every negative value abruptly with a sharp corner. Inputs like -0.3 should be dimmed, not switched off.

The Solution: SiLU. Same as ReLU for large positive values, but near the origin it curves smoothly towards zero.

SwiGLU is not one function. It is a gating design -> Gated Linear Unit with SiLU inside.

InputGate pathlinear + SiLURaw pathlinear onlyMultiplyOutput
SwiGLU: the gate path filters the raw path.

RoPE: rotary positional embeddings

builds on Lecture 4: Week 3 - AI and ML | Transformers- Part 1 | 31/01/2026, Lecture 4: Week 3 - AI and ML | Transformers- Part 1 | 31/01/2026, Lecture 5: Week 4 - AI&ML | Transformers: Part 2 | 07/02/2026

The Problem with sinusoidal encoding

The Solution: RoPE - rotate vectors by position so only the gap matters.

Example

Clock analogy: hands at 12 and 2 are 60 degrees apart. Move them to 7 and 9 and the gap is still 60 degrees. In 'my name is Rishab', 'my' and 'Rishab' are two words apart wherever the phrase appears.

Why only Q and K?

!

Sinusoidal has no trainable parameters in the lecture's framing; RoPE rotates Q and K inside attention instead of adding to embeddings.

Grouped Query Attention (GQA)

adds to earlier · Multi-query and grouped-query variants of attention that shrink the KV cache. · builds on Lecture 5: Week 4 - AI&ML | Transformers: Part 2 | 07/02/2026, Lecture 5: Week 4 - AI&ML | Transformers: Part 2 | 07/02/2026

The Problem: KV cache grows with sequence length. Memory and bandwidth become the bottleneck.

TypeK/V sharingResult
Multi-head (MHA)Q1-K1V1, Q2-K2V2, ... each its ownBest quality, most memory (8 K/V for 8 queries)
Multi-query (MQA)All queries share one K, VToo much compression, quality drops
Grouped query (GQA)Q1,Q2 -> K1V1; Q3,Q4 -> K2V2Almost no loss, 4 K/V for 8 queries
Example

Queries are news reporters; K and V are the camera and production unit. MHA: each reporter has their own. MQA: one crew for all, so reporters on different stories are stuck. GQA: reporters on the same event (a tsunami: financial loss vs physical damage) share a crew.

Glossary

Decoder-only
Architecture using only the transformer decoder; used by all LLMs.
Masked attention
Attention where future tokens are hidden with negative infinity before softmax.
RMSNorm
Normalization that divides by root mean square, with no mean centering.
Pre-norm
Normalizing before attention and FFN rather than after.
SiLU
Smooth ReLU-like activation, x times sigmoid(x).
SwiGLU
Gated FFN: a SiLU gate path multiplied with a raw path.
RoPE
Rotary positional embedding; rotates Q and K by position to encode relative distance.
GQA
Grouped Query Attention; groups of query heads share one key and value.
Epsilon
Tiny constant added to avoid division by zero.