Abstract
Large language models have high compute, latency, and memory requirements. While specialized accelerators such as GPUs and TPUs typically run these workloads, CPUs are more widely available and consume less energy. Accelerating LLMs with CPUs enables broader AI access at a lower cost and power consumption. This acceleration potential for CPUs is especially relevant during the memory-bound decoding stage of LLM inference, which processes one token at a time and is becoming increasingly utilized with reasoning models. We utilize Advanced Matrix Extensions (AMX) support on the latest Intel CPUs together with unstructured sparsity to achieve a $1.42 \times$ reduction in end-to-end latency compared to the current PyTorch implementation by applying our technique in linear layers. We provide a set of open-source customized sparse kernels that can speed up any PyTorch model by automatically replacing all linear layers with our custom sparse implementation. Furthermore, we demonstrate for the first time the use of unstructured sparsity in the attention computation achieving a $1.14 \times$ speedup over the current systems without compromising accuracy.
Introduction
While GPUs remain the primary hardware for Large Language Model (LLM) inference, their high cost and limited availability pose significant barriers to widespread deployment. CPUs offer a ubiquitous and energy-efficient alternative, yet they often struggle with the massive computational and memory demands of modern LLMs. The primary bottleneck in LLM inference occurs during the "decoding" stage, where tokens are generated sequentially. This stage is heavily memory-bound; the processor spends more time fetching weights from memory than performing actual calculations.
Unstructured pruning is a common technique to reduce model size by removing unimportant weights. However, traditional hardware often fails to realize speedups from unstructured sparsity because the random distribution of zeros makes efficient computation difficult. SparAMX addresses this by co-designing sparse kernels with Intel's Advanced Matrix Extensions (AMX).
Methodology: Hardware-Aware Sparsity
SparAMX introduces a "Load-as-Sparse, Compute-as-Dense" paradigm designed for Intel Sapphire Rapids CPUs. The system leverages two key hardware features:
- Intel AMX: A dedicated hardware block for matrix multiplication that utilizes 2D "tiles" (registers) to accelerate tensor operations.
- AVX-512 Integration: SparAMX stores weights in a compressed format using a bitmap and a list of non-zero values. During inference, the kernel uses AVX-512 instructions to decompress these weights on-the-fly directly into the AMX tiles.
By decompressing weights just before computation, the system significantly reduces the volume of data transferred over the memory bus. The computational overhead of decompression is offset by the reduction in memory latency, leading to a net performance gain. Additionally, SparAMX applies unstructured sparsity to the Key-Value (KV) cache, pruning individual values rather than entire tokens to maintain accuracy while reducing context-processing overhead.
Experimental Evaluation
The performance of SparAMX was evaluated across several state-of-the-art open-source models, including Llama 3 (8B), Llama 2 (7B), Mistral-7B, and Phi-3-mini-4K. Accuracy was verified using benchmarks such as GSM8K for mathematical reasoning and WikiText-2 for perplexity. Downstream task performance was measured using PIQA, ARC, and BoolQ to ensure that KV cache pruning did not degrade model quality.
Key Results
SparAMX demonstrates significant improvements in end-to-end token generation latency. For the Llama 3 8B model, the system achieved a 1.42× speedup compared to the standard PyTorch implementation.
Beyond end-to-end metrics, individual linear layers (such as k_proj) saw speedups of up to 2.03×. In quantized INT8 scenarios, SparAMX outperformed existing commercial solutions like DeepSparse by up to 1.46×. Furthermore, the unstructured KV cache pruning achieved a 1.14× speedup on 16K context lengths with negligible accuracy loss (<1%).
Discussion and Future Work
SparAMX proves that modern CPUs, when paired with optimized sparse kernels, are viable platforms for high-performance LLM serving. However, several areas for improvement remain:
- Preprocessing: The current implementation requires an offline step to compress weights, which is tied to a fixed thread count.
- Operator Fusion: Future versions could benefit from fusing multiple layers (e.g., linear layers with activation functions) to further reduce overhead.
- Format Support: While BF16 and INT8 are supported, extending the system to INT4 would require additional dequantization logic but could offer even greater memory savings.
The SparAMX kernels are open-source and designed for easy integration, allowing developers to automatically replace standard PyTorch linear layers with optimized sparse versions.
Summary updated