Sparse Models › Efficiency Analysis: Decoupling Parameters from Compute
Language AI HandbookAll chapters Sparse Models › Efficiency Analysis: Decoupling Parameters from ComputeOne section · Sections in this chapter4 / 10 ↓
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
The power of sparse models becomes clear when we quantify the efficiency gains. We can compare a dense model to a sparse model with equivalent computational cost to see the capacity advantage. This analysis reveals the mathematical foundation for why sparse models can reach better performance per unit of compute than their dense counterparts.
Consider a dense FFN with intermediate dimension . This layer has two weight matrices: and . These matrices define the expansion into a higher-dimensional space and the subsequent projection back to the model dimension.
The dense FFN has the following computational characteristics:
- Total parameters: . This count comes from two weight matrices: (containing parameters) and (containing parameters)
- FLOPs per token: , because each of the two matrix multiplications requires approximately FLOPs (standard approximation that a matrix multiplication of dimensions by requires FLOPs).
where:
- : the dimension of the model's hidden representations (the size of token embeddings throughout the network)
- : the intermediate dimension of the feed-forward network, typically set to
- : the FLOP count for matrix multiplication comes from computing output elements, each requiring multiplications and additions, giving approximately FLOPs
Now consider a sparse layer with experts, where each expert has intermediate dimension , using top-2 routing. This configuration divides the total parameters across multiple smaller experts, each specialized for different types of inputs. The top-2 routing means each token will be processed by exactly two experts, combining their outputs with learned weights.
For this sparse configuration, we can compute the total parameter count, active parameters per token, and FLOPs per token. These derivations illuminate exactly where the efficiency gains originate.
Total parameters: Each expert is a smaller FFN with intermediate dimension instead of the full . Since each expert has two weight matrices, it contains parameters. The expert's reduced size means it specializes in a narrower range of computations, but collectively the experts cover the same representational space as the original dense layer. Summing across all experts:
This matches the dense model exactly, since the terms cancel. This result is important because it shows that we haven't reduced capacity: the total number of learnable parameters remains the same. The parameters are simply distributed across multiple experts rather than concentrated in a single network.
Active parameters per token: The key efficiency gain comes from activating only a subset of experts. With top-2 routing, only 2 out of experts activate for any given token. Each active expert contributes its parameters to the computation. This selective activation is the heart of sparse efficiency:
FLOPs per token: The computational cost follows the active parameters, since we only perform computations for the experts that are activated. Each active expert must perform two matrix multiplications (expansion and contraction), costing FLOPs. With 2 active experts:
With experts, the sparse model uses only the FLOPs per token while maintaining the same total parameter count. This is a remarkable result: we get the same capacity at a fraction of the computational cost. We can verify this by computing the ratio:
This ratio reveals the key insight: with 8 experts and top-2 routing, we use only 25% of the dense model's compute per token. The general formula shows that computational cost decreases linearly with the number of experts, while total model capacity (parameter count) increases linearly with . This inverse relationship between experts and compute cost is the mathematical foundation for sparse model efficiency.
A significant advantage of sparse models is the ability to increase total parameters without increasing compute. Rather than keeping the same total parameter count as the dense model, we can make each expert the same size as the original dense FFN, giving us times more parameters while only paying times the compute. This is the real power of sparse architectures: they let us scale capacity independently of computational cost.
def compare_dense_sparse(
d_model: int = 4096,
d_ff_dense: int = 16384,
n_experts: int = 8,
top_k: int = 2,
):
"""Compare dense and sparse model efficiency."""
# Dense model statistics
dense_params = 2 * d_model * d_ff_dense
dense_flops = 4 * d_model * d_ff_dense # 2 matmuls, each costs 2*in*out
# Sparse model: each expert has same size as dense FFN
# This gives us N times more total parameters
expert_ff_dim = d_ff_dense # Each expert is full-sized
sparse_total_params = n_experts * 2 * d_model * expert_ff_dim
sparse_active_params = top_k * 2 * d_model * expert_ff_dim
sparse_flops = top_k * 4 * d_model * expert_ff_dim
return {
"dense_params": dense_params,
"dense_flops": dense_flops,
"sparse_total_params": sparse_total_params,
"sparse_active_params": sparse_active_params,
"sparse_flops": sparse_flops,
"param_ratio": sparse_total_params / dense_params,
"flops_ratio": sparse_flops / dense_flops,
"efficiency_gain": (sparse_total_params / dense_params)
/ (sparse_flops / dense_flops),
}Dense Model: 134,217,728 params, 268,435,456 FLOPs/token Sparse Model (8 experts, top-2): 1,073,741,824 total params, 268,435,456 active/token, 536,870,912 FLOPs/token Efficiency: 8.0x parameters, 2.0x FLOPs, 4.0x capacity per FLOP

The sparse model reaches materially higher parameter count while maintaining reasonable computational cost. With 8 experts and top-2 routing, the total parameter count is 8x larger than the dense baseline, but FLOPs per token only double because each token activates just 2 of the 8 experts. This creates a 4x improvement in capacity per unit of compute. The dense model's single FFN processes every token, while the sparse model distributes capacity across multiple experts and activates only a subset per token. This basic trade-off allows sparse models to scale capacity beyond what would be computationally feasible with dense architectures.
In practice, this lets a new training and deployment paradigm:
| Metric | Dense 7B | Sparse 47B (8 experts, top-2) |
|---|---|---|
| Total Parameters | 7B | 47B |
| Active Parameters | 7B | ~12B |
| FLOPs per Token | ~14 GFLOP | ~24 GFLOP |
| Effective Capacity | 1x | ~4-6x |
The sparse model processes each token with similar cost to a ~12B dense model but has the knowledge capacity of a much larger model. This has measurable implications for the scaling laws we discussed in Part XXIII: we can push the Pareto frontier of performance vs. compute. The sparse architecture in effect lets us move along a different efficiency curve, one where we can trade increased memory (for storing more expert parameters) for improved quality at fixed compute.