AI Navigate

FlashSampling: Fast and Memory-Efficient Exact Sampling

arXiv cs.LG / 3/18/2026

📰 NewsDeveloper Stack & InfrastructureTools & Practical UsageModels & Research

Key Points

  • FlashSampling introduces an exact sampling primitive that fuses sampling into the LM-head matmul and avoids materializing the logits tensor in high-bandwidth memory.
  • The method computes logits tile-by-tile on chip, adds Gumbel noise, keeps only the argmax per row and per vocabulary tile, and finishes with a small reduction over tiles.
  • The fused tiled kernel is exact because argmax decomposes over a partition, and hierarchical factorization enables grouped variants for online and tensor-parallel settings.
  • Across H100, H200, B200, and B300 GPUs, FlashSampling speeds up kernel-level decode workloads and yields up to 19% reduction in time per output token in end-to-end vLLM experiments, with the project page at https://github.com/FlashSampling/FlashSampling.

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.