activation sparsity
**Activation Sparsity in Neural Networks** is the **phenomenon and optimization technique where a large fraction of neuron activations are zero or near-zero during inference** — enabling significant computational savings by skipping computations involving zero activations, reducing effective FLOPS by 50-90% without accuracy loss, and forming the basis of conditional computation strategies where different inputs activate different subsets of parameters.
**Types of Sparsity**
| Type | What Is Sparse | When Applied | Benefit |
|------|---------------|-------------|--------|
| Weight sparsity | Network parameters (weights = 0) | After training (pruning) | Model size reduction |
| Activation sparsity | Hidden layer outputs (activations = 0) | During inference | Compute reduction |
| Attention sparsity | Attention matrix entries | During inference | Memory + compute |
| Gradient sparsity | Gradients during training | During training | Communication reduction |
**ReLU Creates Natural Sparsity**
```
ReLU(x) = max(0, x)
In a typical ReLU network:
~50-90% of activations are exactly 0 after ReLU
→ If output is 0, no need to compute downstream multiplications
Problem: Modern models use GELU/SiLU/Swish instead of ReLU
GELU(x) ≈ x × Φ(x) → NEVER exactly zero
→ Lost natural sparsity in GPT/LLaMA/etc.
```
**ReLU's Advantage for Efficiency**
| Activation | Sparsity | Quality | Efficiency |
|-----------|---------|---------|------------|
| ReLU | ~70% zeros | Slightly lower | Very efficient |
| GELU | ~0% zeros | Baseline | No sparsity benefit |
| SiLU/Swish | ~0% zeros | Good | No sparsity benefit |
| ReLU² (squared ReLU) | ~90% zeros | Comparable | Most efficient |
**Exploiting Activation Sparsity for LLM Inference**
```
Standard FFN compute:
hidden = GELU(x @ W_up) @ W_down # Dense computation
FLOPS: 2 × d × 4d = 8d²
Sparse FFN with ReLU:
hidden = ReLU(x @ W_up) @ W_down # ~70% of hidden is zero
Effective FLOPS: 8d² × 0.3 = 2.4d² # 3.3× speedup!
Implementation:
1. Compute hidden = ReLU(x @ W_up)
2. Find nonzero indices: idx = (hidden != 0)
3. Only multiply: hidden[idx] @ W_down[idx, :]
```
**Activation Sparsity in Practice**
| Model | Approach | Sparsity | Speedup | Quality |
|-------|---------|---------|---------|--------|
| ReluLLaMA (2023) | Replace GELU→ReLU + continued pretraining | 70% | 2× | < 1% loss |
| Deja Vu (2023) | Predict which neurons activate | 75% | 2× | Lossless |
| PowerInfer (2024) | Hot/cold neuron split CPU+GPU | 90% (cold) | 10× on CPU | Lossless |
| Mixtral (MoE) | Expert gating → structural sparsity | 87.5% (6 of 8 experts inactive) | ~3× | Lossless |
**Predictive Activation Sparsity**
- Observation: Given input, can predict which neurons will activate without computing all.
- Method: Small predictor network → predicts active neurons → only compute those.
- Deja Vu approach: Use previous layer's output to predict current layer's sparse pattern.
- Result: Skip computation for 75% of neurons with >99% prediction accuracy.
**Hardware Considerations**
- Dense GPU: Poor at exploiting unstructured sparsity (irregular memory access).
- Structured sparsity (NVIDIA N:M): 2:4 pattern → native GPU support (2× speedup).
- CPU inference: Sparse operations map well to CPU (PowerInfer approach).
- Custom hardware: Cerebras, SambaNova natively support sparse computation.
Activation sparsity is **the hidden efficiency lever that can dramatically reduce the cost of neural network inference** — by recognizing that most neurons produce zero or near-zero outputs for any given input, and by using activation functions and prediction mechanisms that exploit this sparsity, it's possible to achieve 2-10× inference speedups that are critical for deploying large language models on resource-constrained hardware.