LookupFFN: Making Transformers Compute-lite for CPU inference

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

Abstract

While GPU clusters are the de facto choice for training large deep neural network (DNN) models today, several reasons including ease of workflow, security, and cost have led to efforts investigating whether CPUs may be viable for inference in routine use in many sectors of the industry. However, the imbalance between the compute capabilities of GPUs and CPUs is significant. Motivated by these considerations, we study a module which is a workhorse within modern DNN architectures, GEMM-based Feed Forward Networks (FFNs), and assess the extent to which it can be made compute- (or FLOP-) lite. Specifically, we propose an alternative formulation, LookupFFN, inspired by recent studies using Locality Sensitive Hashing (LSH) to approximate FFNs. Our formulation recasts essential operations as memory lookups, leveraging the trade-off between compute and memory on platforms where memory is abundant, such as CPUs. For RoBERTa language model pretraining, our formulation achieves similar performance compared to GEMM-based FFNs while dramatically reducing the required FLOPs.

Introduction

In modern Transformer architectures, the Feed-Forward Network (FFN) is a primary computational bottleneck. These layers typically rely on General Matrix Multiply (GEMM) operations, which are highly optimized for the massive parallel throughput of GPUs but can be inefficient on CPUs. While previous research has explored Locality Sensitive Hashing (LSH) to introduce sparsity and reduce computation, these methods often suffer from high rehashing overheads and "bucket skewness," where uneven data distribution across hash buckets prevents efficient parallelization.

LookupFFN addresses these challenges by shifting the paradigm from static hashing to learnable memory lookups. By utilizing the large, high-speed caches (L1 and LLC) available on modern CPUs, LookupFFN trades raw computational intensity for memory bandwidth, a resource that is often underutilized in standard inference pipelines.

Methodology

Differentiable Lookup and BH4 Projection

LookupFFN treats the FFN as a learnable memory lookup problem. Instead of using fixed, non-differentiable hash functions, the model uses a differentiable formulation where the lookup tables themselves are model parameters. This eliminates the need for periodic rehashing as weights evolve during training.

To generate hash codes efficiently, we introduce the BH4 (Block-diagonal Hadamard) Projection. This structured linear layer uses a sequence of parameterized block-diagonal matrices interleaved with fast Hadamard transforms. This approach provides the expressive power needed to mimic complex transformations at a fraction of the cost of standard dense layers.

The LookupFFN architecture consists of a Hash stage (input projection) followed by a Gather stage (weighted lookup from learnable tables).

Learnable Coarse Representations

Unlike traditional LSH-based methods like SLIDE or MONGOOSE, which use random partitions to search for weights, LookupFFN learns a direct mapping from input projections to optimized "coarse representations." This decoupling allows the model to learn the most efficient way to partition the feature space for a given task.

Comparison of LookupFFN (Ours) against existing LSH methods. LookupFFN uses learnable parameterized coarse representations rather than random partitions.

Experimental Results

We evaluated LookupFFN using RoBERTa-base and RoBERTa-small models on English Wikipedia pretraining and the GLUE benchmark (MNLI).

  • Computational Efficiency: LookupFFN achieved a 6.8x reduction in FLOPs for RoBERTa-base compared to a standard FFN.
  • Hardware Speedup: On an AMD EPYC 7452 server, the optimized implementation delivered a 2.51x real-world speedup.
  • Accuracy Parity: In RoBERTa-small tests, LookupFFN achieved a log perplexity of 1.74, slightly outperforming the vanilla FFN (1.78) while using significantly less compute.
  • Cache Utilization: Hardware profiling showed an 80% L1 cache hit rate, confirming that the algorithm successfully leverages CPU architectural strengths.

Conclusion

LookupFFN demonstrates that trading FLOPs for memory lookups is a viable strategy for accelerating Transformer inference on CPUs. By replacing GEMM operations with differentiable lookups and structured projections, we achieve significant speedups without sacrificing model accuracy. As hardware continues to evolve with larger on-die caches, the benefits of memory-centric architectures like LookupFFN are expected to grow further.

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