No history yet

Modern Transformer Block

The Modern Transformer Block

The original 2017 Transformer architecture was a monumental achievement, but the models we use today have evolved significantly. Think of it like the difference between a Model T and a modern car. They share the same core principles, but years of refinement have led to vastly improved stability, efficiency, and performance. The modern Transformer block isn't a single invention, but a collection of key upgrades that have become the de-facto standard in models like Llama 3.1 and Gemma 3.

Stabilizing the Stack with Pre-Normalization

One of the first major shifts was in how the model normalizes data between layers. The original design used Post-Layer Normalization (Post-LN), where the normalization step happens after the main computation (like self-attention) and the residual connection.

This worked fine for the original model's depth, but as researchers built deeper and deeper networks, they hit a wall. Post-LN made training unstable, causing the dreaded vanishing or exploding gradients problem. The solution was simple but profound: move the normalization step to the beginning of the block. This is called Pre-Layer Normalization (Pre-LN).

By normalizing the input before the computation, the gradients flowing backward during training remain well-behaved, allowing for much deeper and more stable models. While Pre-LN was the key insight, the specific normalization method also evolved. Today, most top models use , a simpler and more efficient variant of the original Layer Normalization.

Pre-Normalization stabilizes training for deep networks and improves the flow of gradients, making it a standard feature in most modern LLMs.

Encoding Position with Rotation

Transformers don't have a built-in sense of sequence order like Recurrent Neural Networks do. They need to be explicitly told where each token is. The original paper used static sinusoidal functions to create positional embeddings. This method worked, but it struggled with sequences longer than what it was trained on and wasn't ideal for capturing the relative positions of tokens.

Enter Rotary Positional Embeddings (RoPE). Instead of adding a positional value to the token embedding, RoPE rotates the embedding vector. The angle of rotation depends on the token's position. This clever approach encodes absolute position while making it trivial for the model to determine the relative position between any two tokens, simply by looking at the rotational difference between their vectors.

This rotational method gives RoPE superior generalization to longer sequences and has become the standard for high-performance models.

Smarter Activations and Leaner Layers

Two other trends have defined the modern Transformer block: better activation functions and a move towards simplicity.

The original Transformer used the standard ReLU (Rectified Linear Unit) activation function in its feed-forward network. While effective, it's a very simple function. Modern architectures have adopted more sophisticated gated activation functions, most notably SwiGLU (Swish-Gated Linear Unit). GLUs use a gating mechanism to control the flow of information through the network, allowing the model to learn more complex relationships in the data. This switch has consistently yielded better performance.

Lesson image

Finally, there's a trend toward removing unnecessary parameters. Many modern architectures, including Llama 3.1, have removed all bias parameters from their linear layers. A bias is a constant value added to the output of a layer, and the thinking is that normalization layers like RMSNorm already handle the task of shifting the data, making separate bias parameters redundant. This makes the model slightly smaller and more efficient without sacrificing performance.

These refinements—Pre-RMSNorm, RoPE, SwiGLU, and bias-free layers—are the core components of the modern Transformer block. They represent a convergence of ideas that have pushed the boundaries of what's possible with language models.

Let's test your understanding of these architectural upgrades.

Quiz Questions 1/5

What was the primary motivation for switching from Post-Layer Normalization (Post-LN) to Pre-Layer Normalization (Pre-LN) in deep Transformer architectures?

Quiz Questions 2/5

How do Rotary Positional Embeddings (RoPE) primarily differ from the original sinusoidal embeddings used in Transformers?

These core architectural shifts have been crucial in building the powerful and stable large language models we have today.