Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1fb56b8
[None][perf] Add self-sampling GVR top-K decode kernels (CuTeDSL, sta…
longcheng-nv Aug 17, 2026
29354d1
[TRTLLM-15293][perf] self-sampling top-K: fix pre_idx hint contract —…
longcheng-nv Aug 18, 2026
b1c5e67
[TRTLLM-15293][perf] self-sampling top-K: n <= topK short path (produ…
longcheng-nv Aug 18, 2026
3953e90
[TRTLLM-15293][perf] self-sampling top-K: opt-in values output (defau…
longcheng-nv Aug 18, 2026
5877b60
[TRTLLM-15293][test] self-sampling top-K: degenerate-hint hardening t…
longcheng-nv Aug 18, 2026
6103232
[TRTLLM-15293][perf] self-sampling top-K: run_varlen production-contr…
longcheng-nv Aug 18, 2026
0349d15
[TRTLLM-15293][perf] self-sampling top-K: two-time-scale dispatch spl…
longcheng-nv Aug 18, 2026
cb23e1d
[TRTLLM-15293][perf] self-sampling top-K: per-row in-kernel varlen en…
longcheng-nv Aug 18, 2026
4ea46e5
[TRTLLM-15293][test] self-sampling top-K: CUDA-graph capture/replay t…
longcheng-nv Aug 18, 2026
7986d32
[TRTLLM-15293][perf] self-sampling top-K: opt-in dsa.py decode seam (…
longcheng-nv Aug 18, 2026
b54eb2b
[TRTLLM-15293][fix] self-sampling top-K: short-row sentinel must surv…
longcheng-nv Aug 18, 2026
2efd66e
[TRTLLM-15293][fix] self-sampling top-K: adversarial-review hardening…
longcheng-nv Aug 18, 2026
06af855
[TRTLLM-15293][chore] self-sampling top-K: apply pre-commit formatting
longcheng-nv Aug 19, 2026
fa12c67
[TRTLLM-15293][chore] self-sampling top-K: demote run/run_ws to testi…
longcheng-nv Aug 19, 2026
18a287e
[TRTLLM-15293][fix] self-sampling top-K: dtype gate, arm observabilit…
longcheng-nv Aug 19, 2026
893eead
[TRTLLM-15293][perf] self-sampling top-K: warmup_varlen pre-compile h…
longcheng-nv Aug 19, 2026
0d60f17
[TRTLLM-15293][perf] self-sampling top-K: wire warmup into ModelEngin…
longcheng-nv Aug 19, 2026
cde2064
[TRTLLM-15293][fix] self-sampling top-K: engine-level fp32 contract +…
longcheng-nv Aug 19, 2026
cdf3396
[TRTLLM-15293][fix] self-sampling top-K: review round 1 (warmup cover…
longcheng-nv Aug 20, 2026
74af517
[TRTLLM-15293][fix] self-sampling top-K: warm the launcher key dispat…
longcheng-nv Aug 20, 2026
facf2a2
[TRTLLM-15293][fix] self-sampling top-K: restrict SM gate to validate…
longcheng-nv Aug 20, 2026
834d29a
[TRTLLM-15293][fix] self-sampling top-K: batch-rows admission envelop…
longcheng-nv Aug 21, 2026
70ece97
[TRTLLM-15293][fix] self-sampling top-K: warm the full rows envelope;…
longcheng-nv Aug 21, 2026
8f3f7dd
[TRTLLM-15293][perf] self-sampling top-K: enable TSH-floor staging fo…
longcheng-nv Aug 21, 2026
c8957cf
[TRTLLM-15293][perf] self-sampling top-K: per-row varlen port of the …
longcheng-nv Aug 21, 2026
bcf6c47
[TRTLLM-15293][perf] self-sampling top-K: full-range dispatch — every…
longcheng-nv Aug 21, 2026
303ac14
[TRTLLM-15293][test] self-sampling top-K: heterogeneous-lengths row-i…
longcheng-nv Aug 21, 2026
4699e5d
[TRTLLM-15293][perf] self-sampling top-K: per-row varlen port of the …
longcheng-nv Aug 21, 2026
6d1354a
[TRTLLM-15293][perf] self-sampling top-K: MUFU.RCP spelling for the r…
longcheng-nv Aug 21, 2026
8244a62
[TRTLLM-15293][perf] self-sampling top-K: per-row varlen port of the …
longcheng-nv Aug 21, 2026
80484e8
[TRTLLM-15293][perf] self-sampling top-K: cheapen the per-row varlen …
longcheng-nv Aug 22, 2026
dc7822f
Merge branch 'main' into feat/gvr-selfsampling-topk
longcheng-nv Aug 22, 2026
3b459c9
Merge branch 'main' into feat/gvr-selfsampling-topk (round 2)
longcheng-nv Aug 22, 2026
7fe0d51
[TRTLLM-15293][chore] self-sampling top-K: pre-commit formatting for …
longcheng-nv Aug 22, 2026
e126c4c
[TRTLLM-15293][chore] self-sampling top-K: lint fixes for the kernel …
longcheng-nv Aug 22, 2026
3584c42
[TRTLLM-15293][chore] self-sampling top-K: ruff-format line wrapping …
longcheng-nv Aug 22, 2026
6576326
[TRTLLM-15293][fix] self-sampling top-K: port fragment creation to CU…
longcheng-nv Aug 23, 2026
8374c6a
[TRTLLM-15293][perf] self-sampling top-K: pin the 128-bit row loads t…
longcheng-nv Aug 23, 2026
01bb310
[TRTLLM-15293][perf] self-sampling top-K: drop the DSL 4.6.1 compile-…
longcheng-nv Aug 23, 2026
41d61c9
[TRTLLM-15293][chore] self-sampling top-K: slim code comments
longcheng-nv Aug 24, 2026
ff08b1d
[TRTLLM-15293][chore] self-sampling top-K: comment slim tail
longcheng-nv Aug 24, 2026
62cfe5d
[TRTLLM-15293][chore] self-sampling top-K: dedupe the per-row prologu…
longcheng-nv Aug 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tensorrt_llm/_torch/attention_backend/sparse/dsa/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,23 @@ def __init__(
self._enable_heuristic_topk = (
sparse_params.enable_heuristic_topk and get_sm_version() >= 100
)
# Opt-in self-sampling GVR top-K decode (CuTeDSL, env-gated:
# TRTLLM_GVR_SELF_SAMPLING=1). Same operator contract as the tiered
# heuristic path (per-request device kv_lens, raw prev-top-K hints,
# per-row MTP window, in-kernel n <= topK short path); tuning is
# frozen from indexer_max_seq_len at capture time, so the launch is
# CUDA-graph-replay safe. The TopK module's hardware-format gate
# falls through to the CUDA GVR path with a one-time warning;
# contract violations inside the engine raise.
self._use_self_sampling_topk = (
os.environ.get("TRTLLM_GVR_SELF_SAMPLING", "0") == "1"
and IS_CUTLASS_DSL_AVAILABLE
# datacenter Blackwell only; consumer Blackwell (sm_120/121)
# lacks thread-block clusters
and get_sm_version() in (100, 103)
and sparse_params.index_topk in (512, 1024, 2048)
and compress_ratio in (1, 4)
)
self.mtp_index_share = sparse_params.mtp_index_share

if self.use_cute_dsl_topk:
Expand All @@ -647,6 +664,10 @@ def __init__(
decode_top_k_implementation = TopKImplementation.CUDA_GVR
else:
decode_top_k_implementation = TopKImplementation.CUDA_RADIX
if self._use_self_sampling_topk and self._enable_heuristic_topk:
# env opt-in overrides the decode implementation; the GVR prior
# contract is identical
decode_top_k_implementation = TopKImplementation.CUTE_DSL_GVR_V2
self.top_k = TopK(
self.index_topk,
prefill_implementation=TopKImplementation.CUDA_RADIX,
Expand Down
76 changes: 76 additions & 0 deletions tensorrt_llm/_torch/attention_backend/sparse/dsa/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import os
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, List, Optional

Expand All @@ -16,6 +17,7 @@
from tensorrt_llm._torch.utils import maybe_compile
from tensorrt_llm._utils import get_sm_version, prefer_pinned
from tensorrt_llm.deep_gemm import get_paged_mqa_logits_metadata
from tensorrt_llm.logger import logger

from .cache_manager import is_dsa_cache_manager
from .indexer import (
Expand Down Expand Up @@ -336,6 +338,80 @@ def warmup_cute_dsl_radix_topk(self, next_n: int) -> None:
num_sms=self.num_sms,
)

def warmup_selfsampling_topk(
self, next_n: int, batch_sizes: Optional[List[int]] = None
) -> None:
"""Pre-compile the self-sampling GVR varlen engine during warmup.

Mirrors ``warmup_cute_dsl_radix_topk``. The varlen launcher is keyed
by the exact row count AND the logits row stride: rows cover the
small eager batches plus every configured CUDA-graph batch size, and
the stride mirrors what the active paged-MQA producer emits, so the
warmed keys are the ones dispatch actually looks up. Batches outside
this set still compile lazily on first touch. The helper enumerates
one representative row per distinct engine compile key, so large
batch lists warm in bounded time and memory. No-op unless the opt-in
gate (TRTLLM_GVR_SELF_SAMPLING=1) selects the engine.
"""
if os.environ.get("TRTLLM_GVR_SELF_SAMPLING", "0") != "1":
return
# same hardware gates as the dispatch flag (indexer __init__): never
# compile these kernels on unsupported stacks during warmup
if not IS_CUTLASS_DSL_AVAILABLE or get_sm_version() not in (100, 103):
return
if not self.enable_gvr_topk or self.kv_cache_manager is None:
return
top_k = getattr(self.sparse_metadata_params, "index_topk", None)
if not top_k or int(top_k) not in (512, 1024, 2048):
return
cr = int(self._indexer_compress_ratio) if self._indexer_compress_ratio else 1
if cr not in (1, 4):
return
try:
from ....cute_dsl_kernels.blackwell.top_k import (
gvr_topk_decode_self_sampling_host as _ss_host,
)
except ImportError:
return
nn = int(next_n)
# warm the small row counts eager mixed batches commonly produce;
# larger eager row counts lazy-JIT on first touch, and CUDA-graph
# geometries are covered through ``batch_sizes`` below
eager_warm_rows = 32
rows = set(range(nn, eager_warm_rows + 1, nn)) or {nn}
for bs in batch_sizes or ():
rows.add(int(bs) * nn)
msl_c = int(self.get_indexer_max_seq_len())
if self.sparse_metadata_params.use_cute_dsl_paged_mqa_logits:
# mirror the DSL paged-MQA arena stride (rows round up to 256
# elements). A drift here only degrades warmup to unused keys —
# dispatch still lazy-JITs the true key outside capture.
row_stride = (msl_c + 255) // 256 * 256
else:
# DeepGEMM emits exact-width rows; a non-float4 width falls
# through at the dispatch format gate, so there is nothing to warm
row_stride = msl_c
if row_stride % 4:
return
# helper takes max_seq_len in kv-token space (get_indexer_max_seq_len
# is compressed — same multiply-back as the dispatch seam)
try:
_ss_host.warmup_varlen(
int(top_k),
msl_c * cr,
compress_ratio=cr,
next_n=int(next_n),
num_rows_list=tuple(sorted(rows)),
row_stride=row_stride,
)
except torch.cuda.OutOfMemoryError:
# warmup is best-effort: the dispatch works without it (engines
# JIT lazily outside capture), so do not fail engine init
logger.warning(
"self-sampling GVR warmup ran out of memory; varlen engines "
"will JIT-compile lazily on first touch instead."
)

def on_update_kv_lens(self) -> None:
# After changing the kv_lens/kv_lens_cuda, we may need to update other metadatas.
# Especially for the changes in the _preprocess_inputs() of model_engine.py.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .gvr_topk_decode_direct import DirectTopKKernel
from .gvr_topk_decode_dispatch import is_tiered_topk_supported, tiered_topk
from .gvr_topk_decode_reg import GvrRegKernel
from .gvr_topk_decode_self_sampling_host import run_varlen as selfsampling_topk_run_varlen
from .gvr_topk_decode_tp import GvrTpKernel
from .single_pass_multi_cta_radix_topk import SinglePassMultiCTARadixTopKKernel

Expand All @@ -34,4 +35,5 @@
"DirectTopKKernel",
"tiered_topk",
"is_tiered_topk_supported",
"selfsampling_topk_run_varlen",
]
Loading
Loading