Abstract
Transformer based Large Language Models (LLMs) have been widely used in many fields, and the efficiency of LLM inference becomes hot topic in real applications. However, LLMs are usually complicatedly designed in model structure with massive operations and perform inference in the auto-regressive mode, making it a challenging task to design a system with high efficiency. In this paper, we propose an efficient LLM inference solution with low latency and high throughput. Firstly, we simplify the LLM decoder layer by fusing data movement and element-wise operations to reduce the memory access frequency and lower system latency. We also propose a segment KV cache policy to keep key/value of the request and response tokens in separate physical memory for effective device memory management, helping enlarge the runtime batch size and improve system throughput. A customized Scaled-Dot-Product-Attention kernel is designed to match our fusion policy based on the segment KV cache solution. We implement our LLM inference solution on Intel GPU and publish it publicly. Compared with the standard HuggingFace implementation, the proposed solution achieves up to 7x lower token latency and 27x higher throughput for some popular LLMs on Intel GPU.
Introduction
Large Language Models (LLMs) have revolutionized natural language processing, but their deployment remains computationally expensive. The auto-regressive nature of inference, where tokens are generated one by one, makes these models heavily memory-bound. This paper introduces a highly optimized software stack for running LLM inference on Intel GPUs, focusing on reducing memory access overhead and improving memory management through the Intel® Extension for PyTorch.
Addressing Bottlenecks in LLM Inference
LLM inference faces two primary challenges that limit performance on modern hardware:
- Structural Complexity: Standard transformer implementations involve hundreds of small operations, each requiring a separate kernel launch on the GPU. This leads to excessive overhead and frequent data movement between processors and slow global memory.
- KV Cache Inefficiency: Storing Key and Value vectors to avoid re-computation often involves large, contiguous memory allocations. This leads to significant fragmentation and waste, particularly during beam search where multiple sequences are explored simultaneously.
Proposed Methodology
The proposed solution utilizes three main strategies to overcome these bottlenecks:
Model Structure Simplification & Deep Fusion
By fusing multiple operations—such as Linear, RoPE, and RMSNorm—into single, high-performance kernels, the researchers drastically reduced the number of operations per decoder layer. Furthermore, they optimized memory layouts by strategically switching between "batch-first" and "sequence-first" formats only when necessary, minimizing internal data movement.
Segment KV Cache Policy
To improve memory utilization, the KV cache is split into "prompt" and "response" segments. The prompt KV is shared across all beams in a search, while the response KV grows in discrete 16-token increments. This approach minimizes fragmentation and avoids the costly re-allocation and copying of memory as sequences lengthen, which is a common issue in standard implementations.
Customized SDPA Kernel
A specialized Scaled-Dot-Product-Attention (SDPA) kernel was developed to natively support the segmented KV cache. This kernel integrates index selection for beam search directly into the attention calculation, further streamlining the data path and reducing latency.
Performance Evaluation
The solution was evaluated using popular models including GPT-J-6B, Llama2-13B, OPT-30B, and Bloom-176B on Intel® Data Center Max 1550 GPUs.
Memory Efficiency
The segment KV cache policy demonstrated substantial memory savings across all tested models. For instance, in a GPT-J-6B model with a batch size of 32, the policy saved approximately 51GB of device memory, consuming only 63% of the memory required by standard methods. This efficiency allows for significantly larger batch sizes on the same hardware.
Latency and Throughput Gains
The optimizations yielded dramatic performance improvements over the standard HuggingFace (v4.31.0) implementation:
- Latency: Llama2-13B saw a 4x to 7x reduction in token latency during beam search.
- Throughput: GPT-J-6B achieved up to a 27x increase in tokens per second.
Conclusion
By rethinking model structure and memory management, this research provides a path toward highly efficient LLM deployment on Intel hardware. The combination of deep kernel fusion and segmented memory allocation addresses the fundamental memory-bound nature of transformer inference, enabling larger batch sizes and significantly faster response times. Future work will explore combining these structural optimizations with low-precision quantization (INT8/INT4) to further enhance performance.
Summary updated