TL;DR
SonicSampler is a unified suite of tile-aware Triton kernels that vertically fuses the entire LLM sampling and speculative verification pipeline into a single, CUDA Graph-compatible execution model. By replacing fragmented kernel launches with a novel two-stage hierarchical top-$k$ algorithm, it achieves up to a 10x speedup in top-$k$ selection and up to a 16x speedup across heterogeneous speculative decoding workloads without sacrificing downstream accuracy.
What Problem Does This Paper Address?
While massive engineering effort has been poured into accelerating the forward pass of Large Language Models (LLMs), the downstream sampling pipeline—which converts raw model logits into discrete token decisions—has increasingly become a performance bottleneck. This is especially acute in speculative decoding, where a lightweight draft model proposes tokens that must be rapidly verified against a target distribution.
In production environments, the sampling pipeline is a messy, heterogeneous mix of operations: grammar masking, repetition penalties, temperature scaling, top-$k$/top-$p$/min-$p$ filtering, and speculative verification. Existing solutions suffer from three major flaws:
- Fragmentation: They accelerate only subsets of the pipeline, requiring multiple sequential kernel launches that incur high memory traffic and launch overhead.
- Homogeneity Assumptions: They assume every request in a batch uses the same sampling parameters, making it difficult to mix greedy and stochastic requests under continuous batching.
- CUDA Graph Incompatibility: Many top-$k$ implementations rely on data-dependent control flow that breaks CUDA Graph capture, forfeiting critical launch-overhead amortization.
Methods
SonicSampler addresses these challenges by vertically fusing the entire post-logit pipeline into a fixed, workload-aware execution model using Triton.
The core architectural shift is decomposing the global vocabulary reduction into a two-stage hierarchical operation:
- Stage 1 (Tile-Local Reduction): Independent thread blocks process localized vocabulary tiles ($B_N$). Each block applies the entire logit-processing prologue (penalties, masking, scaling) and reduces the tile to a bounded set of $k=128$ candidates using either an optimized bitonic network or an adaptive radix-bitonic filter. These candidates are written to a compact global memory scratchpad.
- Stage 2 (Cross-Tile Merge): A second set of programs gathers the packed candidates from the scratchpad, performs a cross-tile merge, applies the final probability truncation (top-$p$/min-$p$), injects Gumbel noise, and selects the final token via an argmax operation.
To handle batch heterogeneity without breaking CUDA Graphs, SonicSampler introduces Bit-Level Indicators. Each request's sampling configuration is encoded into a compact bitmask loaded at runtime. This allows greedy and stochastic requests to coexist within a single batched kernel launch without host-side branching.
Datasets
The authors evaluated SonicSampler across both synthetic and real-world workloads:
- Isolated Kernel Benchmarks: Synthetic logit inputs drawn from a Zipf distribution ($\alpha = 1.1$) were used to benchmark top-$k$ selection across vocabulary sizes ranging from $2^{13}$ to $2^{18}$ and batch sizes up to 32.
- Downstream Accuracy Validation: The framework's accuracy and distributional fidelity were validated using GPQA-Diamond and AIME 2024 datasets with the DeepSeek-v3.1 model.
Key Insights and Ideas
- Entropy Sufficiency: The authors provide a theoretical and empirical proof showing that next-token probability distributions in well-trained LLMs are highly concentrated (low entropy). Bounding the local candidate selection to $k=128$ captures virtually all relevant probability mass under standard top-$p$ thresholds, making the hierarchical map-reduce approach practically lossless.
- Hardware-Fused Bitonic CAS: By expressing the bitonic network's Compare-and-Swap (CAS) primitive as explicit min/max operations followed by a conditional select, the compiler can emit fused
IMNMXinstructions. This executes each swap in a single cycle on NVIDIA SM90+ hardware. - Adaptive Radix Screening: Recognizing that ~99.82% of vocabulary tiles share a single mode in their most significant bits, the adaptive strategy uses a single-pass screening reduction to bypass expensive radix counting passes for the majority of execution blocks.
Key Results
- End-to-End Throughput: Integrating SonicSampler into a TensorRT-LLM baseline decoding Qwen3-8B with Eagle3 speculative decoding yielded a 15–17% end-to-end throughput increase (+80 to 120 tokens/sec).
- Sampling Latency Reduction: Across five distinct decoding regimes, SonicSampler consistently achieved the lowest latency, outperforming
torch.compileby 2.5–4×, native PyTorch by 5–6×, and FlashInfer by 10–16×. - Top-$k$ Efficiency: The isolated two-stage top-$k$ algorithm demonstrated a robust 2–5× speedup over competitive baselines (including TileLang and FlashInfer) across most vocabulary and batch configurations.
- Preserved Accuracy: On GPQA-Diamond, SonicSampler achieved 78.2% accuracy compared to the exact baseline's 78.0%, confirming that the bounded-support optimization does not degrade task performance.
Limitations and Future Work
While highly effective for standard configurations, the bounded candidate assumption ($k=128$) is theoretically lossy. Under extreme edge cases—such as exceptionally high decoding temperatures ($\tau \to \infty$) or ultra-high nucleus thresholds ($p > 0.9999$) where the probability distribution flattens completely—the excluded probability mass could become non-negligible.
For future work, the authors plan to extend SonicSampler's architecture to support beam search and explore deeper vertical integration with upstream language model heads.
Summary updated