Transformer Block: FFN Often Out-FLOPs Attention

Within a Transformer block, Feed-Forward Networks (FFN) typically consume more FLOPs and parameters (around 66%) than the Multi-Head Self-Attention mechanism (around 33%), especially in larger models with expanded hidden dimensions.

The top 3

  1. FFN vs. Attention FLOPs: The Hidden Cost Ratio: In standard Transformer blocks, the Feed-Forward Network (FFN) typically accounts for 60% to 75% of the total Floating Point Operations (FLOPs), significantly out-costing the Attention mechanism, especially in larger language models where Attention's quadratic terms become less dominant.
  2. FFN's FLOPs Dominance: The Expansion Factor's Role: The primary reason for FFN's higher FLOPs lies in its architectural design, specifically the expansion-then-contraction pattern where the hidden dimension is typically expanded by a factor of 4x (e.g., d_model to 4*d_model and back to d_model), leading to computationally intensive large matrix multiplications compared to Attention.
  3. Top 3 Techniques to Reduce FFN FLOPs: Key strategies to mitigate FFN computational intensity include **sparsity/pruning** (selectively activating fewer neurons, e.g., Spark FFN, Mixture-of-Channels, achieving 2.5x-3.1x FLOPs reduction), **quantization** (reducing numerical precision of weights/activations like int8/int4), and **knowledge distillation** (training smaller models to mimic larger ones).

Sources

Open the full topic