TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

[Feature]: Support Qrita Sampling support for Eagle-3

Open spurthi-d opened this issue 8 months ago • 2 comments

🚀 The feature, motivation and pitch

Summary

Add support for the Qrita sampling algorithm as an optional backend for Top-k and Top-p truncation in TensorRT-LLM's sampling pipeline. Qrita uses a pivot-based selection strategy that achieves up to 2x throughput and half the memory usage compared to sorting-based approaches, while producing identical outputs.

Motivation

Top-k and Top-p are the dominant truncation operators during LLM sampling, but current implementations typically rely on sorting over the full vocabulary, which incurs significant computation and memory overhead on GPUs. For large vocabulary models (32k–128k+ tokens), sampling can become a non-trivial bottleneck, especially at high batch sizes.

Qrita addresses this with two key techniques:

  1. Gaussian-based sigma-truncation — greatly reduces the search space of target elements before selection, avoiding a full sort over the vocabulary.
  2. Quaternary pivot search with duplication handling — halves the pivot search iterations compared to binary search and guarantees deterministic output identical to sorting-based algorithms.

The paper benchmarks Qrita against the Top-k and Top-p kernels in vLLM, SGLang, and FlashInfer, showing consistent speedups across vocabulary sizes and batch configurations.

Prior art / adoption

Proposed scope

  1. Integrate Qrita as an optional sampling kernel for Top-k and Top-p in TensorRT-LLM (PyTorch engine path).
  2. Expose a configuration option (e.g., sampling_algorithm: "qrita" or similar) so users can opt in without changing default behavior.
  3. Ensure correctness parity — Qrita produces the same output as the existing sorting-based kernels, so this should be a drop-in replacement.
  4. Benchmark against the current TensorRT-LLM Top-k/Top-p kernels across representative vocab sizes (32k, 128k, 256k) and batch sizes.

Expected benefits

  • Up to 2x sampling throughput for Top-k and Top-p operations
  • ~50% reduction in memory usage for the sampling step
  • Particularly impactful for large-vocabulary models and high-batch-size serving scenarios

Alternatives

No response

Additional context

No response

Before submitting a new issue...

  • [x] Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.

spurthi-d avatar Mar 24 '26 11:03 spurthi-d

Hi @laikhtewari @ml-inference — I would like to evaluate this if it is still desired and unowned.

Current main at 3e9932c1e96885e15b906ca9277b7c3763a06da2 uses FlashInfer as the only Torch sampler backend and pins flashinfer-python==0.6.14. That release already contains flashinfer-ai/flashinfer#3461, a large-vocabulary/small-k fast path for the same top-k-first operator, so a full-sort implementation is no longer the relevant baseline.

I have frozen an evidence-only first phase rather than starting implementation:

  • evaluate Eagle-3/needs_probs=True separately from the generic sample-only path;
  • compare the pinned vLLM Qrita kernel with FlashInfer 0.6.14 using paired/interleaved latency and fresh-process memory measurements;
  • validate processed-probability/support properties, deterministic replay and torch.Generator ownership, tie handling, input-logit immutability, and CUDA-graph compatibility;
  • charge Qrita for its mutable work tensor and persistent [min(SM, batch), vocab] buffer;
  • stop if probability semantics fail, net memory grows, or there is no robust benefit over current FlashInfer.

Before I run the GPU matrix or prepare any TensorRT-LLM implementation, could you confirm:

  1. Is this issue still desired and available for an external contribution?
  2. Is the intended scope specifically Eagle-3/speculative decoding, or the generic PyTorch sampler as well?
  3. If Qrita wins, should the primitive be upstreamed to FlashInfer first rather than integrated as a second TensorRT-LLM sampler backend?

I will not start production changes without maintainer approval and ownership direction.

HOYALIM avatar Jul 14 '26 06:07 HOYALIM

Hi @HOYALIM We can close this issue. Thanks for following up.

spurthi-d avatar Jul 14 '26 12:07 spurthi-d