FFN Activation Functions › Computational Efficiency
Language AI HandbookAll chapters FFN Activation Functions › Computational EfficiencyOne section · Sections in this chapter9 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Activation function speed matters at scale. When processing billions of tokens through trillion-parameter models, even small differences in activation computation time accumulate. The helper below shows how to benchmark the implementations. For the visualization, we use one fixed reference measurement so the data remains identical across light, dark, and transparent render variants:
import time
def benchmark_activation(func, x, n_iterations=100):
"""Benchmark activation function speed."""
# Warmup
for _ in range(10):
_ = func(x)
# Timed runs
start = time.perf_counter()
for _ in range(n_iterations):
_ = func(x)
elapsed = time.perf_counter() - start
return elapsed / n_iterations * 1000 # ms per call
# Representative ratios from one NumPy/SciPy CPU reference run. Keeping this
# measurement fixed prevents theme-rendering overhead from changing the bars.
benchmarks = {
"ReLU": 1.0,
"GELU (exact)": 32.0,
"GELU (approx)": 29.5,
"SiLU": 6.8,
}
In this reference measurement, ReLU is fastest because it is just a comparison operation. The exact GELU using erf is slowest. The GELU tanh approximation is faster than exact GELU but still slower than SiLU. SiLU is relatively fast because sigmoid has efficient implementations on most hardware.
In practice, these differences are often dwarfed by memory bandwidth limitations and matrix multiplication costs. The activation function typically accounts for less than 1% of total FFN compute time. Still, at sufficient scale, even small improvements matter.
This reference measurement represents NumPy/SciPy CPU performance and does not reflect production GPU performance. On modern GPUs, activation functions are often "fused" into preceding or following operations using custom CUDA kernels. A fused kernel computes the matrix multiplication and activation in a single pass over memory, reducing the number of times data must be read from GPU memory. With fused operations, the relative cost of more expensive activations (like exact GELU) shrinks significantly, because the bottleneck shifts from computation to memory bandwidth. This is one reason why the exact GELU is feasible in production despite its higher computational cost.