Adaptive Computation Modules: Granular Conditional Computation For Efficient Inference

Bartosz Wójcik, Alessio Devoto, Karol Pustelnik, Pasquale Minervini, Simone ScardapanearXiv 2023

TL;DR

Transformer models are notoriously compute-heavy because they treat every input token—whether it's a complex object or a blurry background patch—with the same amount of processing power. This paper introduces Adaptive Computation Modules (ACMs), which allow models to dynamically adjust their "width" (computational effort) on a per-token basis. By replacing standard layers with a sequence of parallelizable "learners" and a smart gating mechanism, the authors achieve significant inference speedups with negligible impact on accuracy.

What Problem Does This Paper Address?

State-of-the-art neural networks, particularly Transformers, have ballooned in size, leading to high latency and energy consumption. The authors observe a fundamental inefficiency: the full representational capacity of a layer is often only needed for a small subset of "hard" tokens. For example, in an image of a bird, the patches containing the bird require deep processing, while the clear blue sky patches are computationally "easy."

Existing conditional computation methods have drawbacks. Early Exiting usually stops processing for the entire input at once, lacking granularity. Token Dropping removes information entirely, which can be risky. Mixture-of-Experts (MoE) often allocates a fixed amount of compute per token regardless of difficulty. ACMs aim for a "Goldilocks" solution: granular, per-token width adaptation that is both flexible and hardware-efficient.

Figure 1: ACMs adapt their computational load for each in- put on a per-token basis by selecting the number of learners to execute via a trainable gate. In the example on the top, a background token (green) is allocated fewer learners than a content-rich token (orange). This results in a spatially vary- ing computational load, as shown on the bottom.

Methods

The core of the proposal is the Adaptive Computation Module (ACM). Instead of one large static layer (like an MLP), an ACM consists of $N$ smaller, homogeneous "learners."

  1. Architecture: A small gating network $g$ looks at an input token $z$ and predicts $k$, the number of learners needed to process it. The final output is the sum of the first $k$ learners. Crucially, once $k$ is determined, these learners can be executed in parallel.
  2. Smart Initialization: To avoid training from scratch, the authors "ACMize" pre-trained models. They use a three-phase approach:
  3. Module-wise Distillation: Learners are trained to reconstruct the output of the original static layer.
  4. Gating Pre-training: The gate is trained using artificial labels derived from the reconstruction error of the learners.
  5. End-to-End Fine-tuning: The entire model is refined using a combination of task loss and auxiliary losses that encourage computational diversity and adherence to a target FLOP budget.
Figure 2: Architecture of an ACM block: the output is the sum of k learners, where k is determined on a per-token basis by a small gating network g. The learners are executed in parallel. In the example, only the first two learners are executed, and the computation of the third (greyed out) is skipped.

Datasets

The authors evaluated their method across two distinct domains:

  • Computer Vision: ImageNet-1k for standard classification and ImageNet-C for testing robustness to distribution shifts (like blur or noise). They used a Vision Transformer (ViT-B) as the base.
  • Speech-to-Text: The CommonVoice-es dataset using a pre-trained XLS-R-300M (Wav2Vec2) model.

Key Insights and Ideas

  • Width vs. Depth: While many adaptive methods focus on skipping layers (depth), ACM focuses on adjusting the "effective width" of each layer. The authors argue this is a more granular way to handle token-level difficulty.
  • Learner Redundancy: The paper demonstrates that for a majority of tokens, the same transformation can be achieved by just two or three learners instead of the full module, justifying the adaptive approach.
  • Hardware Efficiency: Unlike unstructured sparsity, which is hard to accelerate on GPUs, ACMs are designed for efficiency. By sorting tokens by their predicted $k$ value, the model can use standard, highly-optimized matrix multiplication kernels.
  • Emergent Specialization: Through auxiliary losses, the model naturally learns to allocate more compute to semantically meaningful regions (like objects in images or actual speech in audio) without being explicitly told to do so.

Key Results

  • Pareto Dominance: In vision tasks, ACM-based ViT-B models consistently outperformed baselines like A-ViT and MoEfication, especially at lower computational budgets (below 12.5 GFLOPs).
  • Speech Performance: For speech recognition, ACMs achieved a lower Word Error Rate (WER) across all evaluated FLOP budgets compared to MoEfication.
  • Real-world Speedup: Using custom Triton kernels, the authors showed that ACMs have negligible overhead. The wall-clock inference time decreases linearly with the average number of executed learners, proving that the theoretical FLOP savings translate to actual hardware speedups.
Figure 4: Performance-efficiency trade-offs of different conditional computation methods as measured on the CommonVoice-es dataset. The model’s performance is re- ported in terms of Word Error Rate (WER). ACMs achieve lower WER for every evaluated computational budget.

Limitations and Future Work

  • Scope of Adaptation: Currently, ACMs replace MLP blocks and linear projections. The self-attention mechanism itself remains static, which could be a target for future adaptive modules.
  • Pruning Synergy: The authors suggest that the relationship between ACMs and weight pruning remains an open question—combining the two could lead to even leaner models.
  • Quantization: The training procedure replaces individual modules, suggesting that one could potentially use quantized learners (e.g., 8-bit or 4-bit) to further drive down the inference cost.

Summary updated

BibTeX
@misc{wojcik2023adaptive,
  author = {Bartosz Wójcik and Alessio Devoto and Karol Pustelnik and Pasquale Minervini and Simone Scardapane},
  title = {{Adaptive Computation Modules: Granular Conditional Computation For Efficient Inference}},
  year = {2023},
  eprint = {2312.10193},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.10193},
}
Figure