flashinfer.sampling¶
Kernels for LLM sampling.
Important
Batch-length seed and offset tensors now apply one value per output
row. Previously, all rows used element zero, even when a batch-length tensor
was supplied. Calls with distinct values in these tensors can therefore
produce different samples after this fix. Scalar values, length-one tensors,
and calls using a shared torch.Generator retain their existing behavior.
The output row index still feeds the Philox subsequence. Per-row seeds do not make sampling invariant to batch position, even with the same seed and offset.
See also
For efficient Top-K selection (without sampling), see flashinfer.topk which provides
top_k(), top_k_page_table_transform(), and
top_k_ragged_transform().
|
Fused GPU kernel for category sampling from probabilities. |
|
Fused GPU kernel for category sampling from logits. It's equivalent to sampling from |
|
Fused GPU kernel for online safe softmax with temperature scaling. |
|
Fused GPU kernel for top-p sampling (nucleus sampling) from probabilities, this operator implements GPU-based rejection sampling without explicit sorting. |
|
Fused GPU kernel for top-k sampling from probabilities, this operator implements GPU-based rejection sampling without explicit sorting. |
|
Fused GPU kernel for min_p sampling from probabilities, |
|
Fused GPU kernel for top-k and top-p sampling from pre-softmax logits, |
|
Fused GPU kernel for top-k and top-p sampling from probabilities, |
|
Fused GPU kernel for renormalizing probabilities by top-p thresholding. |
|
Fused GPU kernel for renormalizing probabilities by top-k thresholding. |
|
Fused GPU kernel for masking logits by top-k thresholding. |
|
Fused-GPU kernel for speculative sampling for sequence generation (proposed in paper Accelerating Large Language Model Decoding with Speculative Sampling), where the draft model generates a sequence(chain) of tokens for each request. |