FlashFFN: Multi-Head Decomposition Enables I/O-Aware Feed-Forward Network
Abstract
The Feed-Forward Network (FFN) dominates the activation memory of modern Transformers because the wide intermediate tensor is materialized in off-chip HBM between the two matmul stages. FlashAttention-style I/O-aware tiling avoids the analogous cost in attention, but the same one-pass fusion does not fit a monolithic FFN. We identify the reason as a hardware-geometry constraint: under one-pass tiled accumulation a fused FFN kernel must keep an output accumulator spanning the full hidden dimension in on-chip SRAM, which is infeasible for hidden dimensions of 2048 or more on currently shipping NVIDIA datacenter GPUs (A100/H100/B200) under one-pass tiled execution with sequence tiles of 128 or more tokens. We formalize this as an SRAM-feasibility proposition and prove a corollary: multi-head decomposition is the simplest architectural transform that brings FFN inside this SRAM-feasible regime, because it makes the per-head accumulator width (the hidden dimension divided by the number of FFN heads) a free parameter that can be driven below the GPU's SRAM cutoff. Naïve multi-head FFN, however, blows up the per-head expansion ratio as the hidden dimension grows, drifting away from the well-validated SwiGLU 8/3 optimum and degrading quality at scale; we resolve this with a dense MoE-like sub-network correction that restores the optimal ratio while preserving SRAM-feasibility. The resulting architecture, FlashFFN, is an SRAM-feasible FFN block that replaces SwiGLU under matched parameter and FLOPs budgets and derives directly from the SRAM constraint. Across 128M–1.3B parameter models trained on 60–100B tokens of The Pile, FlashFFN achieves a Pareto improvement over SwiGLU at fixed compute: up to 2.7× lower peak activation memory at long sequences, inference latency that matches or improves over SwiGLU (up to 1.18× faster end-to-end prefill and 1.19× faster decode on H100), and consistent quality gains (up to -0.84 in evaluation perplexity (PPL) and +1.60 average accuracy points across six downstream benchmarks at 1.3B). Code: https://github.com/alexzms/FlashMHF