Transformer Block Assembly › Key Parameters

Michael BrenndoerferUpdated June 13, 20252 min read
Language AI HandbookAll chapters
Part 15 of 67Transformer Blocks
Chapter 110Transformer Block Assembly › Key Parameters
Reading section 15 of 16 · Key Parameters · 2 minSection 15 of 16 · 2 min

Book contents

Section 15 of 16 · 2 min read

Transformer Block Assembly › Key ParametersOne section · Sections in this chapter15 / 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

When implementing transformer blocks, these parameters control capacity and efficiency:

  • dmodeld_{\text{model}} (model dimension): The embedding dimension that flows through the entire block. Typical values range from 256 (small models) to 12288 (GPT-3 scale). This dimension must be divisible by nheadsn_{\text{heads}} since each head operates on dhead=dmodel/nheadsd_{\text{head}} = d_{\text{model}} / n_{\text{heads}} dimensions.

  • nheadsn_{\text{heads}} (attention heads): Number of parallel attention mechanisms. More heads enable attending to different types of relationships simultaneously. Common choices are 8, 12, 16, or 32 heads.

  • dffd_{\text{ff}} (FFN hidden dimension): The intermediate dimension of the feed-forward network. For standard FFNs, typically dff=4×dmodeld_{\text{ff}} = 4 \times d_{\text{model}}. For SwiGLU, typically dff=83×dmodeld_{\text{ff}} = \frac{8}{3} \times d_{\text{model}} (approximately 2.7×) to maintain similar parameter count. The gating mechanism effectively doubles the width, so a smaller explicit expansion compensates.

  • norm_type: Choice between RMSNorm (faster, used in LLaMA/Mistral) and LayerNorm (original, used in GPT-2/BERT). RMSNorm is preferred for new architectures.

  • norm_placement: Pre-norm (normalize before sublayers) or post-norm (normalize after). Pre-norm is standard for modern deep models due to better gradient flow.

  • ffn_type: Standard (two linear layers with activation) or gated (SwiGLU, GeGLU). Gated variants improve expressiveness at similar parameter cost.

  • causal: Whether to apply causal masking in attention. Required for autoregressive language models, disabled for bidirectional encoders like BERT.

  • ϵ\epsilon (normalization epsilon): Small constant (typically 10−610^{-6} to 10−510^{-5}) added to prevent division by zero in normalization. The RMSNorm formula divides by mean(x2)+ϵ\sqrt{\text{mean}(x^2) + \epsilon}. Without ϵ\epsilon, a vector of all zeros would cause a division by zero. May need adjustment (e.g., 10−510^{-5} instead of 10−610^{-6}) for mixed-precision training where numerical precision is lower.