FlashSampling: Fast and Memory-Efficient Exact Sampling

Tomas Ruiz, Zhen Qin, Yifan Zhang, Xuyang Shen, Yiran Zhong +1 more
3/16/2026
cs.LGcs.AIcs.CL

Official code: FlashSampling/FlashSampling (90 stars, Apache-2.0, last commit 2026-04-25).

Abstract

Sampling from a categorical distribution is mathematically simple, but in large-vocabulary decoding, it often triggers extra memory traffic and extra kernels after the LM head. We present FlashSampling, an exact sampling primitive that fuses sampling into the LM-head matmul and never materializes the logits tensor in HBM. The method is simple: compute logits tile-by-tile on chip, add Gumbel noise, keep only one maximizer per row and per vocabulary tile, and finish with a small reduction over tiles. The fused tiled kernel is exact because $\argmax$ decomposes over a partition; grouped variants for online and tensor-parallel settings are exact by hierarchical factorization of the categorical distribution. Across H100, H200, B200, and B300 GPUs, FlashSampling speeds up kernel-level decode workloads, and in end-to-end vLLM experiments, it reduces time per output token by up to $19%$ on the models we test. These results show that exact sampling, with no approximation, can be integrated into the matmul itself, turning a bandwidth-bound postprocessing step into a lightweight epilogue. Project Page: https://github.com/FlashSampling/FlashSampling.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

FlashSampling: Fast and Memory-Efficient Exact Sampling (https://huggingface.co/papers/2603.15854)

907Cuda, ShellFeb 28, 20266 months agoApache-2.0

Similar Papers

Cite this paper

@article{ruiz2026flashsampling,
  title  = {FlashSampling: Fast and Memory-Efficient Exact Sampling},
  author = {Tomas Ruiz and Zhen Qin and Yifan Zhang and Xuyang Shen and Yiran Zhong and Mengdi Wang},
  year   = {2026},
  eprint = {2603.15854},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2603.15854v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2603.15854.svg)](https://codeofpaper.com/paper/2603.15854)

Discussion