Efficient Model Architectures
Designing models for efficiency: MobileNet depthwise separable convolutions, EfficientNet scaling, mixture of experts, early exit, dynamic computation, and the Pareto frontier of accuracy vs FLOPs.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- Depthwise Separable Convolutions
- Compound Scaling (EfficientNet)
- Mixture of Experts (MoE)
- Early Exit / Dynamic Depth
- Efficient Attention Variants
- The Accuracy-Efficiency Pareto Frontier
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive the FLOP reduction from depthwise separable convolutions.
- Explain compound scaling and the relationship between depth, width, and resolution.
- Describe MoE as conditional computation for scaling parameters cheaply.
- Explain early exit and when dynamic depth is beneficial.
- Navigate the accuracy-FLOPs Pareto frontier for model selection.
Notation
- — input/output channels
- — kernel size
- — compound scaling coefficient
- — number of experts, — top-k routing
Core Intuition
Standard architectures (ResNet, Transformer) are designed for accuracy with little regard for compute. Efficient architectures achieve the same accuracy with 5-10x fewer FLOPs by exploiting: factored operations (depthwise separable), conditional computation (MoE), and adaptive depth (early exit). The goal: push the Pareto frontier of accuracy vs efficiency.
Efficient Architectures
Depthwise Separable Convolutions
Standard convolution: multiplications per spatial position.
Depthwise separable: Factor into two steps:
- Depthwise: convolution independently per channel. Cost: .
- Pointwise: convolution to mix channels. Cost: .
FLOP reduction:
For : reduction = . 8.7x fewer FLOPs.
Compound Scaling (EfficientNet)
Observation: Scaling only depth, only width, or only resolution gives diminishing returns. Scaling all three together is optimal.
Compound scaling:
subject to (FLOP constraint).
Grid search finds . Then increase to scale the model uniformly.
Result: EfficientNet-B7 achieves higher ImageNet accuracy than ResNet-152 with 8x fewer FLOPs.
Mixture of Experts (MoE)
Conditional computation: Only activate a subset of parameters per input:
Properties:
- Total parameters: dense equivalent.
- Active parameters per token: only fraction.
- Training compute: same as a model with experts active.
For LLMs (Mixtral 8x7B):
- 8 expert FFNs, top-2 routing.
- 47B total parameters, 13B active per token.
- Performance of a 13B dense model with cost of a 13B model.
Early Exit / Dynamic Depth
Idea: Add classification heads at intermediate layers. If the model is already confident, exit early without computing remaining layers.
Average depth: Easy examples exit early (2-3 layers); hard examples use full depth. Average compute is reduced.
For serving: Useful when latency varies by request. Easy queries answered fast; hard queries take longer.
Efficient Attention Variants
- Multi-Query Attention (MQA): Share K, V across heads → less KV-cache.
- Grouped-Query (GQA): groups of shared K, V → balanced tradeoff.
- Sliding Window: instead of .
- Linear Attention: via kernel decomposition.
- Multi-Scale: Different heads attend at different resolutions.
The Accuracy-Efficiency Pareto Frontier
Definition: A model is Pareto-optimal if no other model achieves both higher accuracy AND lower compute.
Navigating the frontier:
- Low compute ( GFLOP): MobileNet, EfficientNet-B0.
- Medium (- GFLOP): EfficientNet-B3, DeiT-Small.
- High ( GFLOP): Large transformers dominate.
Key insight: The Pareto frontier shifts with new architectural innovations. MoE pushed it significantly for LLMs.
Common Pitfalls
Pitfall 1. Comparing models only on FLOPs. Actual latency depends on memory access patterns, parallelism, and hardware. A model with fewer FLOPs can be slower in practice.
Pitfall 2. Using MoE without load balancing. Without auxiliary loss, some experts get all tokens (collapse) while others are unused.
Pitfall 3. Early exit with poorly calibrated confidence. If the model is overconfident at early layers, it exits too soon with wrong answers.
Summary
- Depthwise separable: 8-9x fewer FLOPs by factoring convolutions.
- Compound scaling: Scale depth, width, resolution together optimally.
- MoE: Scale parameters cheaply with conditional computation.
- Early exit: Adaptive depth — easy inputs skip expensive later layers.
- Pareto frontier: Choose architecture based on accuracy-compute budget.
Exercises
Exercise 1. Compute the FLOPs for standard vs depthwise separable convolution with .
Exercise 2. For a Mixtral-style MoE with : compute active vs total parameters.
Exercise 3. Design an early-exit strategy for a 32-layer transformer: where to place exit heads and what confidence threshold to use.
Exercise 4. Derive the compound scaling coefficients that double FLOPs (constraint: ).
Exercise 5. Compare the Pareto efficiency of a 7B dense model vs a 47B MoE (8x7B, top-2) model.