GPT-3 › Architectural Details
Language AI HandbookAll chapters GPT-3 › Architectural DetailsOne section · Sections in this chapter4 / 25 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
GPT-3 uses the same fundamental decoder-only transformer architecture as GPT-2. The core design remains unchanged: a stack of transformer decoder blocks with masked self-attention, each followed by a feed-forward network. This continuity was a deliberate choice. The GPT-3 authors wanted to isolate the effect of scale, not architecture innovation. By keeping the design consistent with GPT-2, any capability differences observed between the models can be attributed to size rather than architectural changes.
The key architectural differences from GPT-2 include:
- Alternating dense and sparse attention: In some layers, GPT-3 uses sparse attention patterns that attend to every other token, reducing computational cost for long sequences
- Learned position embeddings: Like GPT-2, positions are represented by learned embeddings rather than sinusoidal functions
- Pre-layer normalization: Layer normalization is applied before each sublayer (attention and FFN) rather than after, following the Pre-LN configuration that stabilizes training for deep networks
Pre-layer normalization (Pre-LN) deserves particular attention. In the original transformer design, layer normalization was applied after the residual connection, a pattern called Post-LN. For shallow networks, this works fine. But for very deep networks like GPT-3 with 96 layers, Post-LN creates gradient flow problems: the gradients must pass through each normalization operation during backpropagation, and at great depths this can cause gradients to vanish or explode. Pre-LN addresses this by normalizing before the sublayer operation. This keeps the residual connections carry gradients cleanly from output back to input regardless of depth. This seemingly minor change was essential for training stability at 96 layers.
Parameter Count Calculation
When we say GPT-3 has 175 billion parameters, what exactly are we counting? Understanding where these parameters live reveals the model's structure and helps explain why scale matters so much for capability.
A transformer model stores its learned knowledge in weight matrices. Each weight is a single floating-point number that the model adjusts during training. The total count of these numbers determines the model's capacity to represent patterns in language. To understand GPT-3's scale, we need to trace through each component and count its parameters systematically.
The Building Blocks
A GPT-style model consists of several distinct components, each contributing parameters:
- Token embeddings: A lookup table that converts each vocabulary token into a dense vector
- Position embeddings: A separate lookup table that encodes where each token appears in the sequence
- Transformer layers: The repeated blocks that process and transform token representations
- Final layer normalization: A normalization layer before the output projection
- Output projection: A matrix that converts hidden states back to vocabulary probabilities
Let's formalize this. For a model with vocabulary size , maximum sequence length , model dimension , number of layers , and feed-forward dimension , the total parameter count is:
where:
- : token embedding parameters. Each of the vocabulary tokens gets its own -dimensional vector, requiring parameters total.
- : position embedding parameters. Each of the possible positions gets a -dimensional vector.
- : parameters per transformer layer, which we'll derive below.
- : final layer normalization has a learnable scale and bias vector, each of dimension .
- : the output projection maps from hidden dimension back to vocabulary size . This is often weight-tied with the token embeddings (sharing the same matrix), but GPT-3 uses separate weights.
The formula captures the intuition that larger vocabularies, longer sequences, and higher dimensions all increase parameter count. But the dominant term is : the transformer layers, repeated times.
Inside a Transformer Layer
Each transformer layer consists of two sublayers, each followed by layer normalization:
- Multi-head self-attention: Allows tokens to gather information from other positions
- Feed-forward network (FFN): Applies the same transformation to each position independently
The attention sublayer requires four projection matrices: Query (), Key (), Value (), and Output (). Each matrix has shape , contributing parameters. With four matrices, attention adds parameters.
The feed-forward network consists of two linear transformations. The first expands from dimension to (typically ), and the second contracts back from to . This requires parameters.
Each layer also has two layer normalizations (one before attention, one before FFN in the Pre-LN configuration), each with scale and bias vectors of dimension . This adds parameters per layer.
Putting it together:
where:
- : the four attention projection matrices (, , , )
- : the two feed-forward linear layers. With , this becomes .
- : scale and bias for two layer normalizations
Notice that the per-layer count scales with . This quadratic dependence explains why increasing the hidden dimension has such a dramatic effect on model size: doubling quadruples the parameters in each layer. It also explains why GPT-3's hidden dimension of 12,288 is so consequential: compared to GPT-2's 1,600, this is roughly an 8x increase in , which translates to a 64x increase in parameters per layer from the quadratic terms alone.
A Worked Example: GPT-3 175B
Let's apply these formulas to GPT-3's actual configuration:
- Vocabulary size: tokens (the GPT-2 tokenizer vocabulary)
- Maximum sequence length: tokens
- Model dimension:
- Number of layers:
- Feed-forward dimension:
First, we calculate the per-layer parameters:
Each layer contributes about 1.81 billion parameters. With 96 layers, the transformer stack alone accounts for approximately 174 billion parameters. The remaining 1+ billion come from embeddings and the output projection.
This breakdown reveals an important pattern: the transformer layers dominate the parameter count. Increasing the number of layers or the hidden dimension has a much larger effect than expanding the vocabulary or context length. If you doubled the vocabulary to 100,514 tokens, the additional parameters would be less than 1.5 billion, barely 1% of the total. But if you doubled the hidden dimension to 24,576, you would quadruple the per-layer parameters and nearly quadruple the entire model. In practice, this means that the "knowledge" of a GPT-3-scale model lives overwhelmingly in its attention and FFN matrices, not in the embedding lookup tables.
Implementation
Let's implement this calculation to verify our formulas and explore how parameters distribute across components:
def compute_gpt3_parameters(
vocab_size=50257,
n_layers=96,
d_model=12288,
n_heads=96,
d_ff=None,
max_seq_len=2048,
):
"""
Calculate parameter count for a GPT-3 style model.
The feed-forward dimension is 4x the model dimension by default.
"""
if d_ff is None:
d_ff = 4 * d_model
# Token embeddings
token_embedding_params = vocab_size * d_model
# Position embeddings
position_embedding_params = max_seq_len * d_model
# Per-layer parameters
# Attention: Q, K, V, O projections
attention_params_per_layer = 4 * d_model * d_model
# FFN: two linear layers
ffn_params_per_layer = 2 * d_model * d_ff
# Layer norms (2 per layer, each has scale and bias)
layernorm_params_per_layer = 4 * d_model
params_per_layer = (
attention_params_per_layer
+ ffn_params_per_layer
+ layernorm_params_per_layer
)
total_layer_params = n_layers * params_per_layer
# Final layer norm
final_norm_params = 2 * d_model
# Output projection (weight-tied with embedding or separate)
# GPT-3 uses separate output weights
output_params = d_model * vocab_size
total = (
token_embedding_params
+ position_embedding_params
+ total_layer_params
+ final_norm_params
+ output_params
)
return {
"token_embedding": token_embedding_params,
"position_embedding": position_embedding_params,
"layers": total_layer_params,
"final_norm": final_norm_params,
"output": output_params,
"total": total,
}GPT-3 175B Parameter Breakdown ============================================= Token embeddings: 0.62B Position embeddings: 0.03B Transformer layers: 173.95B Final layer norm: 0.02M Output projection: 0.62B --------------------------------------------- Total: 175.21B
The output confirms our manual calculation. The vast majority of parameters, over 173 billion, reside in the 96 transformer layers. This makes sense: each layer contributes about 1.8 billion parameters through its attention projections and feed-forward network, and with 96 layers, these add up quickly.
The embedding layers tell an interesting story. Despite handling a vocabulary of 50,257 tokens, the token embeddings account for only about 0.62 billion parameters, less than 1% of the total. The position embeddings are even smaller at 0.025 billion (25 million) parameters. The output projection mirrors the token embedding in size but is kept separate in GPT-3 rather than being weight-tied.
This distribution has practical implications. If you want a larger model, adding layers or increasing the hidden dimension is far more effective than expanding the vocabulary or context length. Conversely, if you want a smaller model, the layers are where you need to cut.
The visualization below makes this distribution strikingly clear:

The pie chart reveals just how lopsided the distribution is: the transformer layers are so dominant that the embeddings and output projection are barely visible. This concentration of parameters in the processing layers, rather than the input/output interfaces, reflects where the model's computational "thinking" happens. The embeddings convert tokens to vectors and back, but the layers are where the model transforms and reasons about those representations. The pattern also has an important implication for interpretability: if you want to understand what a model knows or how it reasons, you need to study the attention and FFN matrices in the processing layers, not the embedding tables.