AI
New Sampling Technique Cuts Token Generation Time by 10% Without Memory Trade-offs
Researchers introduce FlashSampling, a GPU kernel that merges categorical sampling directly into language model computation, eliminating memory bottlenecks in decoder workloads.
Sampling from categorical distributions is a fundamental operation in language model inference, yet it has long been a source of computational inefficiency. Researchers have now proposed FlashSampling, a technique that integrates exact sampling directly into the matrix multiplication layer of large language models, eliminating separate sampling kernels and avoiding memory overhead entirely.
The Core Challenge#
When decoding large language models with extensive vocabularies, generating the next token requires sampling from a probability distribution over thousands or millions of possible words. Traditional approaches compute logits (unnormalized scores), store them in GPU memory, then run a separate sampling kernel. This two-step process wastes bandwidth and creates memory pressure, especially at scale.
How FlashSampling Works#
The method is conceptually straightforward yet elegant:
- Tile-by-tile computation: Logits are computed one chunk at a time on the GPU's fast on-chip cache rather than being fully materialized in slower memory
- Gumbel noise injection: A standard technique for exact categorical sampling, noise is added directly during logit computation
- Hierarchical reduction: Only one maximum value per row and vocabulary tile is preserved, with a final small reduction step across tiles to identify the actual maximum
This approach preserves mathematical exactness—the argmax operation decomposes cleanly over partitioned data, so the result is identical to computing the full logits and sampling normally.
Scaling Across Multiple GPUs#
In tensor-parallel setups (where computation spreads across multiple GPUs), FlashSampling replaces the traditional all-gather operation that collects full logit tensors across devices. Instead, GPUs stream peer-to-peer data writes, overlapping communication with computation and memory loads. The technique scales near-ideally up to 8 GPUs, particularly beneficial at large batch sizes where data movement would otherwise dominate execution time.
Empirical Performance#
Testing across multiple modern datacenter GPUs—including NVIDIA H100, H200, B200, and B300—shows consistent kernel-level speedups. In end-to-end experiments using the vLLM inference framework, FlashSampling reduces time-per-output-token latency by as much as 10% on tested models. These gains come with no approximation: sampling behavior remains statistically identical to exact methods.

