Gated Linear Units › Parameter Efficiency Analysis
Language AI HandbookAll chapters Gated Linear Units › Parameter Efficiency AnalysisOne section · Sections in this chapter7 / 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
One consideration when adopting GLU variants is the parameter cost. The standard FFN has two weight matrices, while GLU-based FFNs have three. Let's analyze this trade-off carefully.
For a standard FFN with hidden dimension , the parameter count (ignoring biases) is:
This comes from two weight matrices:
- : parameters
- : parameters
For a GLU-based FFN with the same hidden dimension , the parameter count is:
This comes from three weight matrices:
- : parameters (value/Swish projection)
- : parameters (gate/linear projection)
- : parameters (output projection)
The GLU variant has 50% more parameters for the same hidden dimension. To maintain the same parameter count as a standard FFN, we can solve for the reduced hidden dimension :
Solving for :
This means we need to reduce by a factor of to match the parameter count of a standard FFN.
def count_ffn_params(d_model, d_ff, variant="standard"):
"""Count FFN parameters for different variants."""
if variant == "standard":
# W1 and W2
return 2 * d_model * d_ff
elif variant in ["glu", "swiglu", "geglu"]:
# W, V, and W2
return 3 * d_model * d_ff
else:
raise ValueError(f"Unknown variant: {variant}")
def equivalent_glu_hidden_dim(d_model, d_ff_standard):
"""Compute d_ff for GLU to match standard FFN parameter count."""
standard_params = count_ffn_params(d_model, d_ff_standard, "standard")
# 3 * d_model * d_ff_glu = 2 * d_model * d_ff_standard
# d_ff_glu = (2/3) * d_ff_standard
return int((2 / 3) * d_ff_standard)
# Example: GPT-2 small configuration
d_model_gpt = 768
d_ff_standard = 3072 # Standard 4x expansion
d_ff_glu = equivalent_glu_hidden_dim(d_model_gpt, d_ff_standard)
params_standard = count_ffn_params(d_model_gpt, d_ff_standard, "standard")
params_glu_full = count_ffn_params(d_model_gpt, d_ff_standard, "glu")
params_glu_reduced = count_ffn_params(d_model_gpt, d_ff_glu, "glu")Parameter count comparison (GPT-2 Small scale): d_model: 768 Standard FFN d_ff: 3072 Standard FFN params: 4,718,592 GLU FFN (same d_ff) params: 7,077,888 (+50%) GLU FFN (reduced d_ff=2048) params: 4,718,592 (matched)
The comparison shows that keeping the same hidden dimension increases parameters by 50%, while reducing to 2048 brings the parameter count close to the standard FFN. This demonstrates the practical trade-off: you can either accept more parameters for the same hidden capacity, or reduce hidden capacity to match parameters while gaining the expressiveness of gating.
LLaMA and other modern models typically use the reduced hidden dimension approach. For example, LLaMA-7B uses with , which is approximately rather than the standard . This gives roughly the same parameter count as a standard FFN with expansion while gaining the benefits of gated activation.
