Optimized Speculative Sampling for GPU Hardware Accelerators

Dominik Wagner, Seanie Lee, Ilja Baumann, Philipp Seeberger, Korbinian Riedhammer, Tobias Bocklet

Introduction

Large Language Models (LLMs) have revolutionized natural language processing but face significant deployment challenges due to their autoregressive nature. Generating text one token at a time makes inference memory-bound, as model weights must be repeatedly fetched from High-Bandwidth Memory (HBM). Speculative sampling mitigates this by using a smaller "draft" model to predict multiple tokens, which a larger "target" model then verifies in parallel. However, the verification step itself—involving probability ratio calculations and resampling—often becomes a secondary bottleneck on modern GPU hardware.

Proposed Methods

Researchers from TH Nürnberg and KAIST have introduced two optimization strategies to accelerate the verification phase by better utilizing GPU parallelism and memory hierarchies.

Hardware-Aware Exact Optimization

The first method focuses on a hardware-aware "tiling" approach. The researchers observed that the intermediate matrices required for draft token acceptance can be computed independently across the vocabulary. By implementing a custom GPU kernel, they "tile" the workload: data is loaded from HBM into fast, on-chip SRAM (shared memory), and the vocabulary is distributed across multiple threads for simultaneous computation.

Figure 1: The Exact Optimization workflow, showing the three-stage process of loading data into SRAM, computing acceptance criteria in parallel, and writing results back to HBM.

This "exact" optimization produces mathematically identical results to standard implementations but significantly reduces latency by minimizing slow HBM accesses and maximizing thread occupancy.

Sigmoid-Based Approximation

The second method addresses the "global" bottleneck of the Softmax function. Standard sampling requires summing across the entire vocabulary to normalize probabilities, necessitating thread synchronization. The authors propose replacing Softmax with an element-wise Sigmoid function. Since Sigmoid operations are independent for each token, they can be computed entirely in parallel without inter-thread communication. While this introduces a mathematical approximation, it offers a substantial increase in hardware throughput.

Experimental Evaluation

The optimizations were tested across diverse tasks, including Automatic Speech Recognition (ASR) using the Whisper family and text summarization using Llama2, Qwen, and Gemma models.

Performance Results

The results highlight a clear trade-off between computational efficiency and model accuracy:

  • Exact Optimization: Improved profiling time by 6% to 13% with zero loss in accuracy (identical Word Error Rate and ROUGE scores).
  • Sigmoid Approximation: Achieved dramatic profiling time improvements ranging from 37% to 94%. In ASR tasks, this came with a minor increase in Word Error Rate (e.g., from 0.08 to 0.09 on LibriSpeech). In summarization, ROUGE-1 scores saw a slight decline, representing a viable trade-off for nearly doubling speed in some configurations.
Figure 6: Performance comparison on the Gemma 7B/2B model for the Xsum task. The plot shows consistent latency reductions for both Exact and Sigmoid optimizations across various draft token lengths.

Conclusion

By optimizing the verification step of speculative sampling for GPU architectures, this work demonstrates that significant inference speedups are possible without altering the underlying model weights. The hardware-aware tiling provides a "free" performance boost, while the Sigmoid approximation offers a tunable knob for extreme low-latency requirements. Future work will explore calibration techniques to further bridge the accuracy gap of the Sigmoid-based approach.

Summary updated

BibTeX
@inproceedings{wagner2024optimized,
  author = {Dominik Wagner and Seanie Lee and Ilja Baumann and Philipp Seeberger and Korbinian Riedhammer and Tobias Bocklet},
  title = {{Optimized Speculative Sampling for GPU Hardware Accelerators}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.370},
}
Figure