IceFormer: Accelerated Inference with Long-Sequence Transformers on CPUs

Yuzhen Mao, Martin Ester, Ke Li

Abstract

Transformer-based models have become the standard for natural language processing, yet their quadratic computational complexity ($O(n^2)$) remains a significant barrier for long-sequence inference, particularly on CPU-based commodity hardware. This paper introduces IceFormer, a "plug-and-play" acceleration method designed to speed up long-sequence Transformer inference without requiring model retraining. By leveraging a specialized $k$-nearest neighbor search (k-NNS) and a novel mathematical transformation for unnormalized keys, IceFormer identifies critical attention weights on the fly. Experimental results demonstrate speedups of up to 7.6x on the Long Range Arena (LRA) benchmark and 3.0x on Large Language Models (LLMs) like Vicuna-7b, while maintaining over 99% of the original model's accuracy.

Introduction

The self-attention mechanism is the core of the Transformer architecture, but it is also its primary bottleneck. As input sequences grow, the cost of computing the $N \times N$ attention matrix becomes prohibitive in terms of both time and memory. While various "Efficient Transformer" variants have been proposed, they often suffer from significant drawbacks: the requirement for expensive retraining, a lack of generality across different model architectures, or compounding errors that degrade accuracy in deep models.

IceFormer addresses these challenges by introducing an adaptive sparsity approach that works out-of-the-box for pretrained models. It is specifically optimized for CPU environments, where the quadratic bottleneck is most acute, providing a viable path for deploying long-context LLMs on standard hardware.

Methodology

IceFormer is built on the observation that attention patterns in pretrained Transformers are inherently sparse—only a small subset of "heavy hitter" keys contribute significantly to the final output for any given query. The framework employs three primary technical innovations to exploit this sparsity efficiently.

1. $k$-NNS for General Keys

Standard $k$-NNS algorithms often require keys to be normalized to unit length to function correctly. However, many pretrained models use unnormalized keys. IceFormer overcomes this by applying a mathematical transformation that embeds keys and queries into a $(d+1)$-dimensional space. This transformation allows the system to accurately identify the highest attention weights using $k$-NNS without requiring any changes to the underlying model weights.

2. Prioritized DCI

Rather than using traditional bucketing algorithms like Locality Sensitive Hashing (LSH), which can be suboptimal for the relative nature of attention, IceFormer utilizes Prioritized DCI (Data-dependent Concept Indexing). This ranking-based $k$-NNS algorithm projects data onto random directions and ranks them. This approach is significantly more effective at retrieving the true top-k neighbors in high-dimensional spaces, ensuring that the most relevant information is captured even with high levels of sparsity.

3. Incremental Updates for Causal Masking

Generative LLMs require causal masking, where each token can only attend to preceding tokens. To support this during autoregressive decoding, IceFormer implements a dynamic data structure based on binary search trees. This allows for the incremental addition of new keys to the $k$-NNS index, avoiding the need to rebuild the entire index at every generation step and maintaining high throughput during inference.

Experimental Evaluation

The authors evaluated IceFormer across several rigorous benchmarks to test its speed, accuracy, and scalability:

  • Long Range Arena (LRA): Tested on tasks like ListOps and text classification with sequences up to 4k tokens.
  • ZeroSCROLLS: A zero-shot benchmark for long-context tasks such as summarization and question answering.
  • LongEval: Specifically used to test retrieval limits up to 16k tokens.
  • Fashion MNIST: Used for controlled algorithmic comparisons.

Performance and Fidelity

IceFormer achieved an average speedup of 7.63x on the LRA benchmark compared to vanilla Transformers. When applied to the Vicuna-7b model, it delivered a 3.0x speedup during the prompt processing phase. Crucially, this performance gain does not come at the cost of model integrity; IceFormer retained between 98.6% and 99.6% of the original model's accuracy across all tested benchmarks.

Memory and Scalability

In addition to temporal gains, IceFormer significantly reduces the memory footprint. On LRA tasks, peak memory usage was reduced by up to 0.862 GB. Scalability tests on LongEval showed that IceFormer's latency grows much more linearly compared to the steep quadratic growth of standard Transformers as sequence lengths increase from 3k to 16k tokens.

Discussion and Insights

A key insight of this work is that retraining is often unnecessary for achieving efficiency. Because pretrained Transformers already exhibit sparse attention patterns, the challenge is not creating sparsity, but rather providing a fast mechanism to find those sparse indices. By focusing on a "retraining-free" approach, IceFormer is immediately compatible with the extensive ecosystem of models available on platforms like HuggingFace.

Furthermore, the shift from bucketing-based to ranking-based $k$-NNS (Prioritized DCI) highlights that attention is essentially a relative competition between keys. Ranking-based methods are inherently better suited for this dynamic than absolute distance thresholds.

Conclusion and Future Work

IceFormer represents a significant step forward for CPU-based Transformer inference. By combining adaptive sparsity with efficient $k$-NNS techniques, it enables the processing of long sequences on commodity hardware with minimal accuracy loss. While current implementation focuses on CPUs, future research could explore integrating these ranking-based sparsity techniques with GPU-centric optimizations like FlashAttention. Additionally, automating the selection of the hyperparameter $k$ could further simplify the deployment of IceFormer across diverse tasks.

Summary updated

BibTeX
@inproceedings{mao2024iceformer,
  author = {Yuzhen Mao and Martin Ester and Ke Li},
  title = {{IceFormer: Accelerated Inference with Long-Sequence Transformers on CPUs}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=6RR3wU4mSZ},
}
Figure