SonicSampler: Unified Tile-Aware Kernels for LLM Sampling and Speculative Verification

Pragaash Ponnusamy, Shivam Sahni, Jue Wang, Tri Dao

TL;DR

SonicSampler is a high-performance, unified sampling pipeline for Large Language Models (LLMs) that fuses logit processing, token selection, and speculative verification into a single, CUDA Graph-compatible execution model. By leveraging a novel two-stage hierarchical top-$k$ algorithm and exploiting the "peaky" nature of LLM distributions, it achieves up to 16x speedup over state-of-the-art baselines while supporting the heterogeneous per-request behaviors required for production serving.

What Problem Does This Paper Address?

In the world of LLM inference, the "forward pass" (the heavy matrix multiplications) gets most of the optimization glory. However, the sampling pipeline—the steps that turn raw model scores (logits) into actual words—is becoming a significant bottleneck.

This pipeline is surprisingly complex, involving grammar masking, penalties (to prevent repetition), logit biasing, temperature scaling, and various truncation rules like top-$k$, top-$p$, or min-$p$. In speculative decoding, this cost is multiplied because the system must sample from a "draft" model and then verify those tokens against a "target" model.

Existing solutions suffer from three main issues:

  1. Fragmentation: They launch many small, separate GPU kernels, leading to high overhead and excessive memory traffic.
  2. Inflexibility: They often assume every request in a batch uses the same sampling settings, which breaks down in "continuous batching" environments where one user might want greedy decoding while another wants high-creativity stochastic sampling.
  3. Graph Incompatibility: Many efficient top-$k$ implementations are incompatible with CUDA Graphs, a key technology for reducing CPU-side overhead in production.

Methods

SonicSampler introduces a unified suite of tile-aware kernels written in Triton. The core innovation is a two-stage hierarchical top-$k$ algorithm designed to maximize GPU occupancy and minimize memory movement.

The Two-Stage Pipeline

As illustrated in the pipeline overview, the process is split to maximize parallelism:

Figure 1: SonicSampler’s two-stage tile-aware fused sampling pipeline for the Singular (non- speculative) workload. Stage 1 (top, left-to-right) vertically fuses grammar masking, repetition penalties, logit bias, and temperature scaling with Lexicographic Encoding and per-tile Local Top-k via Opti- mized Bitonic or Adaptive Radix-Bitonic selection (right panel), writing only the packed k results per tile to the HBM scratchpad as the sole cross-kernel memory boundary. Stage 2 (bottom, right-to-left) re-indexes across tiles, performs global Top-k reduction through bitonic merge networks with ascend- ing / descending alternating tile layout, applies probability truncation, and emits the selected token via Gumbel-Noise and ArgMax, completing a clockwise data loop through the shared HBM band. The Adaptive Radix-Bitonic strategy (right) screens on the 6 most-significant bits via a single-pass optimized reduction tree, branching to a 2-Pass Radix Select on the lower 10 bits or falling back to an Optimized Bitonic selection.
  • Stage 1 (Tile-Local Reduction): The vocabulary is split into tiles. Each GPU thread block loads a tile, applies the entire "prologue" of logit transformations (masking, penalties, etc.), and reduces the tile to its local top-$k$ candidates.
  • Stage 2 (Cross-Tile Merge): A second kernel gathers these local winners, performs a global merge, applies final truncation rules (like top-$p$), and selects the final token.

Key Technical Innovations

  • Lexicographic Encoding: To handle comparisons efficiently, the authors encode bfloat16 values and their vocabulary indices into a single uint32. This allows the GPU to use fast integer comparison instructions while preserving the correct floating-point order and stable indexing.
  • Adaptive Radix-Bitonic Strategy: For the local reduction, the system uses a hybrid approach. It first performs a fast "6-bit screen" to see if the values are concentrated enough for a radix-based selection. If the distribution is too flat, it falls back to a highly optimized bitonic sort.
  • Bit-Level Indicators: To support heterogeneous batches, SonicSampler encodes each request's sampling configuration into a compact bitmask. This allows a single kernel launch to handle different sampling behaviors per request without expensive branching.
  • Min-p Simplification: The authors mathematically reformulate the min-p truncation rule to work entirely in logit space, avoiding a costly global softmax operation before truncation.

Datasets

The authors evaluated SonicSampler across a variety of modern LLMs and benchmarks:

  • Models: Qwen3 (8B to 235B MoE) and DeepSeek-V3.1.
  • Benchmarks:
    • GPQA-Diamond and AIME 2024 for end-to-end task accuracy.
  • EQ-Bench for "stress testing" the sampling behavior across different temperatures.
  • HumanEval for coding performance.
  • Synthetic Data: Top-$k$ kernels were isolated and tested using a Zipf distribution ($\alpha=1.1$), a standard way to simulate the power-law distribution of natural language.

Key Insights and Ideas

  • Entropy Sufficiency: A major "aha" moment is the realization that for well-trained LLMs, the output distribution is extremely "peaky." The authors show that at standard temperatures, the top 128 candidates almost always capture the vast majority of the probability mass.
Figure 2: Bounded-support fidelity on DeepSeek v3.1 logits at standard temperature. (a) Residual probability mass outside top-k. (b) fraction of decoding steps whose top-k mass exceeds a given top-p threshold.
  • Bounded Top-k is "Lossless enough": By capping the candidate set at $k=128$, they can use much more efficient GPU registers and shared memory structures. They empirically prove this doesn't hurt accuracy on hard benchmarks like GPQA.
  • Vertical Fusion is King: By fusing the "prologue" (logit processing) and "epilogue" (token selection) directly into the reduction stages, they eliminate the need to write massive intermediate logit tensors back to global memory.

Key Results

  • Kernel Speedup: Achieves up to 10x speedup for top-$k$ selection on large (128K) vocabularies compared to competitive baselines like FlashInfer and TileLang.
  • Speculative Decoding: In real-world speculative decoding workloads, SonicSampler delivers up to 16x speedup for draft sampling and 10x for target verification.
  • End-to-End Gains: When integrated into TensorRT-LLM, it provides a 15-21% increase in total tokens per second across various model scales.
  • Accuracy Preservation: On GPQA-Diamond with DeepSeek-V3.1, SonicSampler matched the baseline accuracy (78.2% vs 78.0%) within run-to-run variance.

Limitations and Future Work

  • High-Temperature Regime: The "bounded top-128" assumption starts to fail at very high temperatures ($\tau > 1.5$), where the distribution flattens out. In these rare cases, the truncation becomes "lossy" and can degrade model performance.
  • Future Directions: The authors plan to extend this unified approach to beam search and explore even deeper integration between the model's final layer (the "LM Head") and the sampling kernels to further reduce memory traffic.

Summary updated

BibTeX
@inproceedings{ponnusamy2026sonicsampler,
  author = {Pragaash Ponnusamy and Shivam Sahni and Jue WANG and Tri Dao},
  title = {{SonicSampler: Unified Tile-Aware Kernels for LLM Sampling and Speculative Verification}},
  booktitle = {COLM},
  year = {2026},
  url = {https://openreview.net/forum?id=dr4CKyzzh4},
}
Figure