LookupFFN: Making Transformers Compute-lite for CPU inference

Zhanpeng Zeng, Michael Davies, Pranav Pulijala, Karthikeyan Sankaralingam, Vikas Singh

While GPUs remain the gold standard for training large deep learning models, CPUs are frequently preferred for production inference due to their lower costs, wider availability, and seamless integration into existing data-center workflows. However, modern Transformer architectures rely heavily on General Matrix Multiplications (GEMM) in their Feed-Forward Network (FFN) layers, creating a significant compute bottleneck for CPU deployments.

LookupFFN reimagines the FFN—traditionally a compute-heavy operation—as a series of efficient, learnable memory lookups. By shifting the workload from raw computation to memory access, it achieves a 6.8x reduction in FLOPs and a 2.51x speedup for CPU inference with negligible loss in accuracy.

The Compute vs. Memory Dilemma

CPUs are generally "compute-poor" compared to GPUs but "memory-rich," often featuring massive L3 caches (128MB or more). Standard GEMM-based FFNs fail to play to these strengths, bottlenecking on limited arithmetic units rather than utilizing available high-bandwidth cache.

Previous attempts to optimize FFNs for CPUs used Locality Sensitive Hashing (LSH) to make the networks "sparse." However, these methods suffered from three critical flaws:

  1. Rehashing Overhead: Hash tables had to be constantly rebuilt as weights changed during training.
  2. Bucket Skewness: Hash buckets often ended up unevenly distributed, leading to inefficient, unbalanced workloads.
  3. High Query Costs: Achieving accurate results required a massive, computationally expensive number of hash functions.

Enter LookupFFN: Learnable Memory Lookups

To resolve these issues, the authors propose LookupFFN, which replaces the standard FFN with a differentiable, learnable lookup mechanism. Instead of using a fixed hashing algorithm to find existing weights, LookupFFN treats the hash tables themselves as learnable parameters.

Conceptual comparison of LookupFFN against prior LSH-based methods.

This architecture introduces several key innovations:

  • Differentiable Hashing: By using a "soft" softmax-based relaxation, the lookup operation becomes differentiable. This allows the model to learn exactly what values should be in the tables and how to index them via standard backpropagation.
  • BH4 (Block-diagonal Hadamard) Projection: To keep the initial routing step cheap, LookupFFN uses a structured projection combining block-diagonal matrices with Fast Hadamard Transforms. This reduces complexity from $O(d^2)$ to $O(d \log d)$ while remaining expressive enough to map inputs to the correct table indices.
  • Decoupled Architecture: By decoupling the lookup tables from the original weight matrices, the model completely eliminates the need for "rehashing" and solves the "bucket skewness" problem. Every lookup now has a deterministic, constant cost.

Hardware-Algorithm Co-design

The core insight of LookupFFN is realizing that CPUs have underutilized SRAM. By recasting matrix multiplication as memory lookups, the authors move the bottleneck from the CPU's arithmetic logic units (ALUs) to its cache hierarchy.

Interestingly, the authors discovered a "scaling sweet spot": reducing the number of hash tables while increasing the table size keeps the total memory footprint stable. This simultaneously reduces FLOPs (due to fewer lookups) while improving accuracy (due to more expressive tables).

Performance and Results

The researchers evaluated LookupFFN on RoBERTa pretraining (English Wikipedia) and the GLUE Benchmark (MNLI). The results demonstrate massive efficiency gains without sacrificing model quality:

  • Massive Efficiency Gains: On a RoBERTa-base model, LookupFFN achieved a 6.8x reduction in FLOPs compared to a vanilla FFN.
  • Real-World Speedup: When tested on a modern AMD EPYC (Zen 2) server, an optimized implementation of LookupFFN was 2.51x faster than the standard PyTorch FFN.
  • Cache Efficiency: Hardware profiling showed an 80% L1 cache hit rate, confirming that the algorithm successfully leverages the CPU's memory architecture.
  • Competitive Accuracy: The model maintained nearly identical performance. For RoBERTa-base, the log perplexity was 1.41 for LookupFFN versus 1.37 for the vanilla version.

Limitations and Future Work

While highly efficient in terms of compute, LookupFFN requires more memory to store its learnable tables (e.g., 16MB+). While this easily fits in modern CPU caches, it may pose constraints for memory-limited edge devices. Additionally, achieving the reported 2.5x speedup required custom C++ kernels using OpenMP and AVX2, as standard frameworks like PyTorch are heavily optimized for GEMM rather than the "weighted gather" operations LookupFFN relies on.

Looking ahead, as 3D-stacked cache technology (like AMD's V-Cache) becomes standard, the benefits of memory-lookup-based architectures like LookupFFN are poised to grow even further, potentially making CPU inference a highly competitive alternative for large-scale deployments.

Summary updated

BibTeX
@inproceedings{zeng2023lookupffn,
  author = {Zhanpeng Zeng and Michael Davies and Pranav Pulijala and Karthikeyan Sankaralingam and Vikas Singh},
  title = {{LookupFFN: Making Transformers Compute-lite for CPU inference}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=7smyQzYk9J},
}
Figure