Spark Transformer: Reactivating Sparsity in Transformer FFN and Attention

Lin Chen (Google) · Chong You (Google) · Srinadh Bhojanapalli (Google Research) · Sanjiv Kumar (Google DeepMind) · Felix Yu (Google Research) · Kan Wu (SystemsResearch@Google) · Zhipeng Jia (Google) · Jiaxian Guo (The University of Tokyo, The University of Tokyo) · Utku Evci (Google) · Jan Wassenberg (Google) · Praneeth Netrapalli (Google DeepMind) · Jeremiah Willcock (Google) · Suvinay Subramanian (Google) · Felix Chern (Google Inc) · Alek Andreev (Google DeepMind) · Shreya Pathak (Google DeepMind) · Prateek Jain (Google Research) · David Culler (Google) · Henry Levy (University of Washington, University of Washington)
activation sparsityattention mechanismfeedforward networksflopshardware-accelerator-friendlylazy neuron phenomenonlinear-time approximate algorithmparameter countrelu activation functionspark transformersparse attentionstatistical top-ktop-k maskingtransformerswall-time benefit

The discovery of the *lazy neuron phenomenon* (Li et al., 2022), where fewer than 10% of the feedforward networks (FFN) parameters in trained Transformers are activated per token, has spurred significant interests in *activation sparsity* for enhancing large model efficiency. While notable progress has been made in translating such sparsity to wall-time benefits across CPUs, GPUs, and TPUs, modern Transformers have moved away from the ReLU activation function crucial to this phenomenon. Existing efforts on re-introducing activation sparsity, e.g., by reverting to ReLU or applying top-k masking, often degrade model quality, increase parameter count, or complicate training. Sparse attention, the application of sparse activation to the attention mechanism, often face similar challenges. This paper introduces the Spark Transformer, a novel architecture that achieves high activation sparsity in both FFN and the attention mechanism while maintaining model quality, parameter count, and standard training procedures. Our method realizes sparsity via top-$k$ masking for explicit control over sparsity level. Crucially, we introduce *statistical top-k*, a hardware-accelerator-friendly, linear-time approximate algorithm that avoids costly sorting and mitigates significant training slowdown from standard top-k operators. Furthermore, Spark Transformer reallocates existing FFN parameters and attention key embeddings to form a low-cost predictor for identifying activated entries. This design not only mitigates quality loss from enforced sparsity, but also enhances wall-time benefit. Pretrained with the Gemma-2 recipe, Spark Transformer demonstrates competitive performance on standard benchmarks while exhibiting significant sparsity: only 8\% of FFN neurons are activated, and each token attends to a maximum of 256 tokens. This translates to a 2.5x reduction in FLOPs, leading to decoding wall-time speedups of up to 1.79x on CPU and 1.40xon GPU.