Flash Multi-Head Feed-Forward Network

Minshen Zhang, Xiang Hu, Jianguo Li, Wei Wu, Kewei Tu

TL;DR

Flash Multi-Head Feed-Forward Network (FlashMHF) introduces a multi-head architecture for the FFN layer in Transformers, structurally mirroring multi-head attention. By combining scale-balanced parallel sub-networks with an I/O-aware fused kernel, FlashMHF outperforms standard SwiGLU FFNs in perplexity and downstream tasks while slashing peak memory usage by 3–5x and accelerating inference by up to 1.08x.

What Problem Does This Paper Address?

In a standard Transformer block, the multi-head mechanism is exclusive to the self-attention layer, allowing the model to look at multiple representational subspaces simultaneously. However, recent research highlights a deep structural symmetry between attention and the Feed-Forward Network (FFN): an FFN can be reinterpreted as a single-head attention mechanism operating over key-value parameter matrices rather than token sequences.

Figure 1: Structural Symmetry.

If multi-head designs work so well for attention, why not apply them to FFNs? A naive implementation of a Multi-Head FFN (MH-FFN) runs into two major roadblocks:

  1. Memory Pressure: Storing intermediate activations for $H$ independent heads causes memory consumption to scale linearly with the head count, quickly leading to Out-Of-Memory (OOM) errors during training or inference.
  2. Scaling Imbalance: As models grow, the total intermediate dimension ($d_{ff}$) expands, but the per-head dimension ($d_h$) typically remains fixed. This distorts the optimal $d_{ff}/d_h$ ratio, causing a drop in parameter efficiency and a failure to scale effectively beyond ~128M parameters.
Figure 2: Memory limitation of MH-FFN.

Methods

The authors propose FlashMHF to overcome these bottlenecks through two core innovations:

1. Parallel FFN Sub-Networks (Scale Balancing)

To fix the scaling imbalance, FlashMHF restructures each head to contain multiple parallel FFN pathways ($E$) combined via a learned gating mechanism (resembling a dense Mixture-of-Experts layer without top-$k$ routing). This keeps the internal dimension of each sub-network tightly coupled to the head dimension ($d_e \approx \frac{8}{3}d_h$), preserving architectural balance even as the model scales up.

2. I/O-Aware Flash Algorithm

To solve the memory crisis, the authors took inspiration from FlashAttention. Instead of materializing the massive intermediate SwiGLU activation tensor in the slow High-Bandwidth Memory (HBM), FlashMHF uses a blockwise computation strategy. The parameter matrices are partitioned into smaller blocks that fit entirely within fast on-chip SRAM. The SwiGLU activations are computed online, multiplied by the weight matrices, and accumulated chunk-by-chunk inside a single fused kernel.

Datasets

The models were pre-trained from scratch on THE PILE.

  • The 128M and 370M parameter models were trained on 60B tokens.
  • The 1.3B parameter model was trained on 100B tokens.

Evaluation Benchmarks: * Perplexity/Validation Loss: Evaluated on the PG19 validation split. * Downstream Tasks: A suite of commonsense reasoning and reading comprehension datasets including HellaSwag, SIQA, PIQA, OBQA, WinoGrande, and RACE.

Key Insights and Ideas

  • FFN as "Implicit Thinking": The authors conceptualize a standard FFN as executing a single sequential path of reasoning. Introducing multiple heads allows the model to perform something akin to a beam search over this implicit thinking process, exploring multiple cognitive paths in parallel to build richer representations.
  • The Softmax Bottleneck: In an ablation study called Parametric KV (PKV)—which replaces the FFN with standard multi-head attention using learnable parameters—performance degraded significantly. The row-wise softmax in attention creates an aggressive information bottleneck. In contrast, the element-wise activation function of SwiGLU allows channels to learn features more freely and independently.
  • A Rare "Free Lunch": In deep learning architecture design, gaining expressivity usually costs speed or memory. FlashMHF breaks this trade-off, acting as a drop-in replacement for SwiGLU FFNs that simultaneously improves model quality, reduces memory footprint, and increases hardware throughput.

Key Results

  • Memory Reduction: FlashMHF achieved a massive 3–5x reduction in peak GPU memory usage compared to standard SwiGLU FFNs, and completely avoided the OOM errors suffered by naive MH-FFNs at long sequence lengths.
  • Inference Speedup: Benchmarked on an Nvidia H100 GPU, FlashMHF delivered up to a 1.08x peak inference speedup (averaging ~1.05x) by eliminating the I/O bottleneck of reading/writing intermediate tensors to HBM.
  • Better Scaling and Perplexity: Across all scales (128M to 1.3B), FlashMHF consistently achieved lower validation loss than the baseline. At the 1.3B scale, it showed an improvement of 0.85 in perplexity.
  • Downstream Superiority: FlashMHF variants achieved the highest scores on every single downstream benchmark evaluated. At the 1.3B scale, FlashMHF with a 128-head dimension scored an average of 43.35 across tasks, compared to the baseline's 41.75.
Evaluation Loss across different head dimensions

Limitations and Future Work

  • Hardware-Specific Optimization: While the Triton implementation runs efficiently on consumer-grade GPUs like the RTX 3090, it does not automatically maximize the throughput of newer architectures like NVIDIA Hopper (H100). The authors had to write specialized CUDA/ThunderKittens code to leverage asynchronous data movement and warp-group specialization on Hopper.
  • Modest Training Scale: The models were trained on 60B–100B tokens due to compute constraints. Fully validating FlashMHF's capabilities will require scaling it up to multi-trillion token regimes typical of commercial LLMs.

Summary updated

BibTeX
@misc{zhang2025flash,
  author = {Minshen Zhang and Xiang Hu and Jianguo Li and Wei Wu and Kewei Tu},
  title = {{Flash Multi-Head Feed-Forward Network}},
  year = {2025},
  eprint = {2512.06989},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.06989},
}
Figure