LLM Inference Unveiled: Survey and Roofline Model Insights

Zhihang Yuan, Yuzhang Shang, Yang Zhou, Zhen Dong, Zhe Zhou, Chenhao Xue, Bingzhe Wu, Zhikai Li, Qingyi Gu, Yong Jae Lee, Yan Yan, Beidi Chen, Guangyu Sun, Kurt KeutzerarXiv 2024 · DOI

Introduction

The explosion of Large Language Models (LLMs) like ChatGPT and Llama has created a massive demand for efficient inference. While researchers have proposed hundreds of ways to make these models faster—ranging from quantization to speculative decoding—it is often difficult to predict which method will actually help on a specific piece of hardware.

"LLM Inference Unveiled" provides a much-needed map for this territory. Beyond just surveying the landscape, the authors introduce LLM-Viewer, an open-source tool that uses the Roofline Model to diagnose exactly why an LLM is slow on a given device. This paper provides a comprehensive taxonomy of LLM inference optimization techniques across parameter, algorithm, system, and hardware levels.

A Taxonomy of Optimization Techniques

The authors categorize the vast world of LLM optimization into four distinct layers, providing a systematic framework for understanding the field.

Taxonomy of efficient LLM inference techniques across four levels: parameter, algorithm, system, and hardware.
  1. Parameter Level: Techniques like Quantization (reducing bit-width), Pruning (removing redundant weights), and Knowledge Distillation.
  2. Algorithm Level: Structural changes like Early Exiting (skipping layers), Mixture-of-Experts (MoE), and Speculative Decoding (using a small "draft" model to predict tokens).
  3. System Level: Software optimizations like Operator Fusion (e.g., FlashAttention), PagedAttention (efficient KV cache management), and Workload Offloading.
  4. Hardware Level: Specialized chips like the Groq LPU (spatial architecture) and Processing-in-Memory (PIM).

The Roofline Model and LLM-Viewer

The standout method introduced is the application of the Roofline Model. This theoretical framework plots a model's "Arithmetic Intensity" (operations performed per byte of data moved) against the hardware's peak performance.

The Roofline Model visualizes performance bottlenecks, distinguishing between memory-bound and compute-bound execution regions based on arithmetic intensity.

This allows developers to see if a layer falls into the "Memory-Bound" (red) zone or the "Compute-Bound" (green) zone. The LLM-Viewer tool automates this analysis, helping engineers understand why LLMs are memory-bound and how to choose the right hardware/software stack. This is crucial because hardware capabilities (FLOPs) have grown much faster than memory speeds (bandwidth), creating an "Efficiency Gap."

Key Insights and Analysis

  • The Prefill vs. Decode Split: The two stages of LLM inference have opposite bottlenecks. The Prefill stage (processing the prompt) has high arithmetic intensity and is usually compute-bound. The Decode stage (generating tokens one-by-one) has very low intensity and is almost always memory-bound.
  • The "Free" Compute of Speculative Decoding: Because the Decode stage is memory-bound, the GPU's compute units are often sitting idle. Speculative decoding exploits this by using those idle cycles to verify multiple tokens at once, effectively getting "free" work out of the hardware.
  • The KV Cache Crisis: As sequence lengths grow (e.g., 100k+ tokens), the memory used to store previous keys and values (KV Cache) becomes a bigger bottleneck than the model weights themselves. This has shifted research focus toward KV cache quantization (like KIVI).
  • Quantization Diminishing Returns: Quantizing a model from 16-bit to 4-bit provides a massive speedup when memory-bound. However, if you increase the batch size enough to become compute-bound, further quantization may yield zero performance gain.

Results and Performance

Evaluation of popular open-source models like Llama-2 (7b, 13b, 70b), Vicuna, OPT, and BLOOM across hardware targets like Nvidia A100 and Intel CPUs yielded several key results:

  • Roofline Diagnostics: For a Llama-2-7b model on an A6000, the Prefill stage hits ~155 Tera-operations per second (TOPS), while the Decode stage languishes at only ~768 Giga-operations per second (GOPS) due to memory bandwidth limits.
  • FlashAttention Impact: Fusing operators can reduce memory access by up to 40% in the decode stage, directly translating to lower latency.
  • Hardware Efficiency: Spatial architectures (like Groq) can achieve over 300 tokens/sec on Llama-2-70b by avoiding the traditional "Memory Wall" found in standard GPU architectures.

Limitations and Future Work

While powerful, aggressive compression (like 2-bit quantization) can lead to "hallucinations" and weaken safety alignment. Furthermore, compressed models may struggle with Out-of-Distribution (OOD) data. The authors point to Large Multimodal Models (LMMs) as the next frontier, where vision-language interactions create new, unstudied bottlenecks. The LLM-Viewer project remains an open-source effort for the community to analyze custom deployments.

Summary updated

BibTeX
@misc{yuan2024llm,
  author = {Zhihang Yuan and Yuzhang Shang and Yang Zhou and Zhen Dong and Zhe Zhou and Chenhao Xue and Bingzhe Wu and Zhikai Li and Qingyi Gu and Yong Jae Lee and Yan Yan and Beidi Chen and Guangyu Sun and Kurt Keutzer},
  title = {{LLM Inference Unveiled: Survey and Roofline Model Insights}},
  year = {2024},
  eprint = {2402.16363},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.16363},
}
Figure