Transformer Block Assembly › Parameter Breakdown by Component
Language AI HandbookAll chapters Transformer Block Assembly › Parameter Breakdown by ComponentOne section · Sections in this chapter9 / 16 ↓
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
Understanding where parameters live helps with model analysis and optimization. Let's break down a complete model:
def analyze_model_parameters(n_layers, d_model, n_heads, d_ff, vocab_size):
"""
Analyze parameter distribution in a transformer language model.
Returns dict with parameter counts for each component.
"""
analysis = {}
# Embedding (input and output tied)
analysis["embedding"] = vocab_size * d_model
# Per-layer components
per_layer = {}
# RMSNorm: 2 per layer (attention + FFN) with d_model params each
per_layer["norm"] = 2 * d_model
# Attention: Q, K, V, O projections
per_layer["attention"] = 4 * d_model * d_model
# SwiGLU FFN: gate, up, down projections
per_layer["ffn"] = 3 * d_model * d_ff
per_layer["total"] = sum(per_layer.values())
# Total for all layers
analysis["per_layer"] = per_layer
analysis["all_layers"] = n_layers * per_layer["total"]
# Final norm
analysis["final_norm"] = d_model
# LM head (often tied with embedding)
analysis["lm_head"] = 0 # Tied with embedding
# Total
analysis["total"] = (
analysis["embedding"] + analysis["all_layers"] + analysis["final_norm"]
)
return analysis
# Analyze a GPT-2 Small-like configuration
analysis = analyze_model_parameters(
n_layers=12,
d_model=768,
n_heads=12,
d_ff=2048, # ~2.7x with SwiGLU
vocab_size=50257,
)Parameter Analysis (GPT-2 Small-like configuration) ======================================================= Configuration: Layers: 12, d_model: 768, n_heads: 12, d_ff: 2048 Vocabulary: 50,257 tokens Per-layer breakdown: Norm : 1,536 ( 0.0%) Attention : 2,359,296 ( 33.3%) Ffn : 4,718,592 ( 66.7%) ────────────────────────────── Total : 7,079,424 Model totals: Embedding: 38,597,376 All layers: 84,953,088 Final norm: 768 ────────────────────────────── Total: 123,551,232 (~124M parameters)


The analysis reveals that FFN parameters dominate within each transformer block. Let's quantify this for SwiGLU:
- Attention parameters: (for QKV and O projections)
- SwiGLU FFN parameters: (for gate and up projections plus the down projection)
With typical SwiGLU expansion (), the FFN has about parameters versus attention's . This is roughly a 2:1 ratio, meaning FFN accounts for about 67% of each block's parameters. At the model level, the embedding layer is also significant: with vocabulary size , the embedding matrix has parameters, which can exceed a single layer's parameters for large vocabularies.