NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Efficient LLM Inference on CPUs

Haihao Shen, Hanwen Chang, Bo Dong, Yu Luo, Hengyu Meng · DOI

Abstract

Large language models (LLMs) have demonstrated remarkable performance and tremendous potential across a wide range of tasks. However, deploying these models has been challenging due to the astronomical amount of model parameters, which requires a demand for large memory capacity and high memory bandwidth. In this paper, we propose an effective approach that can make the deployment of LLMs more efficiently. We support an automatic INT4 weight-only quantization flow and design a special LLM runtime with highly-optimized kernels to accelerate the LLM inference on CPUs. We demonstrate the general applicability of our approach on popular LLMs including Llama2, Llama, GPT-NeoX, and showcase the extreme inference efficiency on CPUs.

Introduction

The deployment of Large Language Models (LLMs) like Llama 2 is often hindered by their massive parameter counts. While GPUs are the conventional choice for inference, they face challenges related to high costs, availability, and memory capacity limits. Conversely, CPUs offer larger memory capacities but have traditionally struggled with inference speed. The primary bottleneck in CPU-based LLM inference is memory bandwidth—the time taken to move data from RAM to the processor often exceeds the computation time itself. To address this, we propose a solution that combines model compression via quantization with a highly optimized software runtime tailored for CPU architectures.

Proposed Methodology

Our approach centers on two main components: an automated quantization pipeline and a specialized runtime engine.

Automatic INT4 Weight-Only Quantization

Traditional INT8 quantization often suffers from accuracy degradation due to "outlier" values in model activations. To mitigate this, we employ weight-only quantization, compressing model weights to 4-bit integers while maintaining activations at higher precision (16-bit). We utilize the Intel Neural Compressor to automate this process, integrating techniques such as GPTQ, AWQ, and TEQ to optimize the trade-off between model size and accuracy.

Workflow of the proposed INT4 quantization and LLM runtime.

Specialized LLM Runtime

We developed a custom tensor library specifically for x86 CPUs to maximize hardware utilization. Key optimizations include:

  • Instruction Set Optimization: Leveraging advanced features like AVX512_VNNI and AMX (Advanced Matrix Extensions) to accelerate matrix multiplications.
  • KV Cache Optimization: Instead of frequent memory reallocations for the Key-Value (KV) cache, our runtime uses a pre-allocated cache system. This "Indirect Access KV Cache" updates only the necessary new tokens, significantly reducing memory overhead during the generation phase.

Experimental Evaluation

We evaluated our approach using the lm-evaluation-harness across several benchmarks, including LAMBADA (contextual word prediction), HellaSwag and Piqa (reasoning), Wikitext (language modeling), and Winogrande (adversarial resolution). The tests covered a range of popular open-source models such as Llama, Llama 2, GPT-NeoX (20B), and Falcon (7B).

Performance and Accuracy

The results demonstrate that our INT4 models maintain high fidelity, with a relative accuracy loss of less than 1% compared to original FP32 versions.

Accuracy comparison between FP32 and INT4 models across various LLMs.

In terms of speed, the system achieved token latencies between 20ms and 80ms on 4th Gen Intel Xeon Scalable processors for models ranging from 6B to 20B parameters. This performance is well within the 200ms threshold required for real-time human-interactive applications. Furthermore, our runtime outperformed the standard ggml library by up to 1.6x.

Memory Efficiency

Quantization led to dramatic reductions in memory footprint. For instance, the GPT-j-6B model's memory requirement decreased from 22GB in FP32 to just 4GB in INT4, enabling deployment on hardware with significantly lower specifications.

Conclusion and Future Work

This work demonstrates that with proper quantization and architectural optimization, CPUs can serve as efficient platforms for LLM inference. Future efforts will focus on improving thread scheduling, extending support to consumer-grade PCs and laptops, and integrating these optimizations into the Hugging Face transformers ecosystem to broaden accessibility for developers.

Reference: Shen, H., et al. (2023). Efficient LLM Inference on CPUs. 37th Conference on Neural Information Processing Systems (NeurIPS 2023).

Summary updated

BibTeX
@misc{shen2023efficient,
  author = {Haihao Shen and Hanwen Chang and Bo Dong and Yu Luo and Hengyu Meng},
  title = {{Efficient LLM Inference on CPUs}},
  year = {2023},
  eprint = {2311.00502},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.00502},
}
Figure