Papers
Topics
Authors
Recent
Search
2000 character limit reached

Spark FFN: Sparse Transformer Efficiency

Updated 13 February 2026
  • Spark FFN is a variant of feed-forward networks that employs top-k masking, statistical thresholding, and parameter-efficient gating to enforce activation sparsity in Transformers.
  • The design systematically reduces per-token FLOPs and wall-time by leveraging the lazy neuron phenomenon without compromising model quality or standard training dynamics.
  • It integrates a linear-time differentiable top-k approximation and predictor-value split to achieve hardware-friendly sparse computations in both training and inference.

Spark FFN is a feed-forward network (FFN) variant for Transformers that explicitly exploits activation sparsity by means of top-kk masking, statistical thresholding, and parameter-efficient gating. Developed in the context of the Spark Transformer architecture, Spark FFN systematically reduces computational cost in both training and inference, achieving significant FLOPs and wall-time reductions while preserving model quality and training dynamics. The core innovation lies in scalable, hardware-friendly sparsification of FFN activations and a low-cost, differentiable predictor for selecting active neurons, thereby reactivating “lazy neuron” sparsity in modern Transformer models (You et al., 7 Jun 2025).

1. Background: Standard Transformer FFN and the Lazy Neuron Phenomenon

In the canonical Transformer layer, the FFN processes each token embedding xRdmodelx\in\mathbb{R}^{d_{\text{model}}} using a two-layer MLP:

y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_2

with W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}, W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}, and a nonlinearity σ()\sigma(\cdot) such as GELU or ReLU. This requires approximately 4dmodeldff4 d_{\text{model}} d_{\text{ff}} FLOPs per token.

Li et al. (2022) identified the “lazy neuron” phenomenon: when σ=\sigma = ReLU, only a small subset of the dffd_{\text{ff}} hidden units have nonzero activations per token. This intrinsic sparsity allows, in principle, for skipping W2W_2 multiplications on inactive neurons, reducing some computation but not the initial xRdmodelx\in\mathbb{R}^{d_{\text{model}}}0 product. The challenge is to efficiently and explicitly harness this per-token sparsity without degrading model quality or increasing parameter count (You et al., 7 Jun 2025).

2. Explicit Sparsification via Top-xRdmodelx\in\mathbb{R}^{d_{\text{model}}}1 Masking

Spark FFN enforces sparsity by selecting the top-xRdmodelx\in\mathbb{R}^{d_{\text{model}}}2 activations from the pre-nonlinearity score vector xRdmodelx\in\mathbb{R}^{d_{\text{model}}}3. The masking process is:

  • Compute xRdmodelx\in\mathbb{R}^{d_{\text{model}}}4 where xRdmodelx\in\mathbb{R}^{d_{\text{model}}}5,
  • Compute xRdmodelx\in\mathbb{R}^{d_{\text{model}}}6,
  • Propagate via xRdmodelx\in\mathbb{R}^{d_{\text{model}}}7.

Here, xRdmodelx\in\mathbb{R}^{d_{\text{model}}}8 retains only the xRdmodelx\in\mathbb{R}^{d_{\text{model}}}9 largest elements (per token), annihilating the rest. If y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_20, the final multiplication y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_21 is reduced to y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_22 FLOPs from y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_23. However, y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_24 selection by sorting is y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_25 and is non-differentiable, necessitating an efficient relaxation (You et al., 7 Jun 2025).

3. Statistical Top-y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_26: Linear-Time Differentiable Masking

To overcome the inefficiency of exact Top-y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_27, Spark FFN introduces the “statistical Top-y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_28” operator, which approximates Top-y=(xW1) σ W2y = \left(x W_1\right)~\sigma~ W_29 selection in linear time and is differentiable almost everywhere. For a vector W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}0 and target W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}1:

  • Compute W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}2, where W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}3 is the standard Gaussian quantile function,
  • Apply soft-thresholding: W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}4.

This procedure sets elements below the threshold to zero and for others subtracts W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}5. Since mean and standard deviation are W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}6 and soft-thresholding is elementwise, the total computation is W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}7. Empirically, the approach ensures W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}8 surviving entries under a Gaussian fit assumption, which is supported for FFN pre-activations in practice (You et al., 7 Jun 2025).

4. Predictor-Value Decomposition and Efficient Sparse Computation

Spark FFN partitions the input and first FFN layer for further efficiency. The weight matrix W1Rdmodel×dffW_1\in\mathbb{R}^{d_{\text{model}}\times d_{\text{ff}}}9 and input W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}0 are split:

  • Predictor block: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}1, operating on W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}2,
  • Value block: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}3, operating on W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}4.

The mechanism is:

  • Compute predictor scores: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}5,
  • Build mask: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}6,
  • Compute values: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}7,
  • Select and activate: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}8,
  • Output: W2Rdff×dmodelW_2\in\mathbb{R}^{d_{\text{ff}}\times d_{\text{model}}}9.

Because σ()\sigma(\cdot)0 is σ()\sigma(\cdot)1-sparse, the expensive projections and matrix multiplications can be performed efficiently as sparse vector-matrix products. The predictor block’s cost is σ()\sigma(\cdot)2; value block and output cost σ()\sigma(\cdot)3 and σ()\sigma(\cdot)4, respectively. Optimal empirical performance occurs at σ()\sigma(\cdot)5 (You et al., 7 Jun 2025).

5. Measured Efficiency, Sparsity, and Model Quality

On a 2B-parameter Transformer pretrained according to the Gemma-2 recipe, Spark FFN achieves:

  • Activation sparsity: σ()\sigma(\cdot)6 (e.g., σ()\sigma(\cdot)7 with σ()\sigma(\cdot)8),
  • End-to-end per-token FLOPs reduction: σ()\sigma(\cdot)9 (72% in FFN, 75% in attention dot-products),
  • Decoding speedup: up to 4dmodeldff4 d_{\text{model}} d_{\text{ff}}0 on 4-core CPU (prefill 4dmodeldff4 d_{\text{model}} d_{\text{ff}}1, decode 4dmodeldff4 d_{\text{model}} d_{\text{ff}}2), up to 4dmodeldff4 d_{\text{model}} d_{\text{ff}}3 on NVIDIA T4 GPU,
  • No change to the optimizer, learning rate schedule, or pretraining curriculum.

Empirically, this procedure yields near-zero impact on pretraining loss or downstream quality, and enables hardware-efficient implementations using specialized sparse kernels (You et al., 7 Jun 2025).

6. Architectures, Hyper-Parameters, and Implementation

Key configurable aspects include:

  • 4dmodeldff4 d_{\text{model}} d_{\text{ff}}4: Active neurons per token (4dmodeldff4 d_{\text{model}} d_{\text{ff}}5 of 4dmodeldff4 d_{\text{model}} d_{\text{ff}}6 in Gemma-2 models),
  • 4dmodeldff4 d_{\text{model}} d_{\text{ff}}7: Predictor width, optimal at 4dmodeldff4 d_{\text{model}} d_{\text{ff}}8 (multiple of 4dmodeldff4 d_{\text{model}} d_{\text{ff}}9 per Gemma-2 constraint),
  • Thresholding: Statistical Top-σ=\sigma =0 is parameter-free, almost everywhere differentiable, and σ=\sigma =1,
  • Training: No modifications to standard Transformer training pipeline.

In attention, a similar predictor-value split is employed, with σ=\sigma =2 halved (σ=\sigma =3), and per-token attention restricted to the top σ=\sigma =4 keys.

7. Pseudocode and Integration in Transformer Layers

The Spark FFN forward pass for a single token σ=\sigma =5 involves:

dffd_{\text{ff}}0

Gradients flow through the statistical Top-σ=\sigma =6 everywhere except at zero crossings. Inference reuses the same forward pass, with per-token computation dropping from σ=\sigma =7 FLOPs to σ=\sigma =8. Practical implementations employ specialized SIMD/tiling/CUDA kernels for memory and compute efficiency (You et al., 7 Jun 2025).


Spark FFN reactivates latent activation sparsity in Transformer FFNs by combining explicit top-σ=\sigma =9 masking, scalable thresholding, and efficient parameter reuse, resulting in substantial computational savings and wall-time improvements without compromising model quality or standard training dynamics.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Spark FFN.