-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[None][feat] Add TriAttention KV-cache compression method #16957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hudayday
merged 193 commits into
NVIDIA:main
from
Hudayday:kvcache-v2-triattention-no-engine
Aug 4, 2026
Merged
Changes from all commits
Commits
Show all changes
193 commits
Select commit
Hold shift + click to select a range
69372f3
[None][feat] Request-carried KV-cache compression lengths
Hudayday 8fc7cc9
[None][feat] General KV eviction primitives
Hudayday 25db688
[None][feat] Port TriAttention onto the request-carried compression c…
Hudayday 43c2efc
[None][fix] Keep RoPE unfused under KV-cache compression
Hudayday da8113c
[None][feat] Raise the CuTE-DSL top-k decode limit to 16384
Hudayday ec74781
[None][refactor] Decide speculative compatibility at the executor cal…
Hudayday 9eec866
[None][refactor] Carry algorithm traits on a KV-cache compression mode
Hudayday befec91
Merge branch 'v3-branch' into v4-branch
Hudayday 1ab4e5c
[None][perf] Port register-staged compaction and streamline TriAttention
Hudayday 262cdbb
[None][chore] Trim the compression-mode docstring
Hudayday 6cedd04
[None][chore] Trim the compression-mode docstring
Hudayday f22ca24
Merge branch 'v3-branch' into v4-branch
Hudayday 51afc99
[None][chore] Describe the real compressed-token mechanism in the con…
Hudayday c4d80d3
[None][fix] Fail fast on speculative modes compression cannot support
Hudayday 2813eb8
Merge branch 'v3-branch' into v4-branch
Hudayday 8dab5cc
[None][fix] Fail fast on speculative modes compression cannot support
Hudayday cf1b3ad
[None][chore] Tighten the compression manager step-hook surface
Hudayday 1cda810
[None][refactor] Tighten the KV-cache compression config surface
Hudayday 10ffc1a
[None][chore] Regenerate the LLM args telemetry manifest
Hudayday cd94f76
[None][perf] Put score-kernel token tiles on the fastest grid axis
Hudayday 0f128a0
[None][chore] Polish the batched compaction module
Hudayday 23d654b
Merge branch 'main' of https://github.com/NVIDIA/TensorRT-LLM into v3…
Hudayday af3ec5c
Merge branch 'v3-branch' into v4-branch
Hudayday 16cac99
[None][chore] Regenerate the LLM args telemetry manifest after the ma…
Hudayday fd0d761
[None][fix] Track the reworked speculative acceptance fields in the s…
Hudayday f6ade2c
Merge branch 'main' of https://github.com/NVIDIA/TensorRT-LLM into v4…
Hudayday 213532d
[None][perf] Batch one eviction round across mixed prompt lengths
Hudayday 3c7f3a2
[None][fix] Update the compact-layers instantiation macro signature
Hudayday f88c95d
[None][fix] Order destination_bases before the optional layer indices
Hudayday 31e55fc
[None][refactor] Replace per-shape eviction caches with one resident …
Hudayday dc1107e
[None][chore] Empty the TriAttention package __init__ like the framew…
Hudayday 0097566
[None][fix] Pass the move-index head stride to the compact kernel exp…
Hudayday ef5dd55
[None][chore] Name the compaction entry points for what they physical…
Hudayday 9cd3fdf
[None][chore] Fold the frozen Triton kernel call into the kernels module
Hudayday 9de7766
[None][fix] Catch the score-buffer tests up with the resident-buffer …
Hudayday 165e03b
[None][chore] Drop the device-normalization helper
Hudayday b4070f8
[None][chore] Call the CuTE top-k operation directly
Hudayday 201978e
[None][refactor] Make the keep-set selectors CUDA-only
Hudayday b5a0365
[None][chore] Drop the unused checked entry of the top-k finalizer
Hudayday 32c8bb9
[None][chore] Order the kernels module along the eviction pipeline
Hudayday 1ed3f59
[None][chore] Name the tie-settling kernel by its position after the …
Hudayday 6d2d3de
[None][chore] House the prepared kernel launchers with their kernels
Hudayday ec4998c
Merge branch 'main' of https://github.com/NVIDIA/TensorRT-LLM into v4…
Hudayday bbb907a
[None][refactor] Gather every kernel warmup into one module with one …
Hudayday 0782732
[None][perf] Carry the move offsets on the staged metadata table
Hudayday c7ca77b
[None][chore] Catch the page-table staging test up with the offsets-c…
Hudayday 5933089
[None][refactor] Drop the kernel warmup machinery and dispatch directly
Hudayday 04a7ad5
[None][fix] Keep score launches on the staging CUDA stream
Hudayday f4a895e
[None][fix] Bind the SWA compact family to the staged move offsets
Hudayday 1e035c6
[None][fix] Skip the steady-generation fast prepare under KV compression
Hudayday a6bf4ea
[None][perf] Cut TriAttention score kernel time 1.5x via launch shape…
Hudayday 87484da
[None][perf] Move TriAttention scoring to a folded CUDA op (4.4x scor…
Hudayday aba7609
[None][chore] Trim redundant TriAttention code and dedupe test fixtures
Hudayday 6e0417f
[None][perf] Add pipelined bf16 KV-compact fast path behind a tempora…
Hudayday af786d3
[None][perf] Make the pipelined compact kernel the default bf16 path
Hudayday 661c857
[None][chore] Merge latest main (KV cache compression framework merge…
Hudayday ae3be22
[None][perf] port TriAttention CuTe score kernel onto the rebuilt sco…
Hudayday ae8ed95
[None][perf] tabulate TriAttention mean-score phases at init, rotate …
Hudayday 9e67032
[None][perf] fuse TriAttention keep-set settle and move-source packing
Hudayday 538dcb9
[None][fix] Version-adapt CuTe sqrt and restore score kernel register…
Hudayday d72bb15
[None][fix] Map the CuTe sqrt shim onto cutlass 4.5 fastmath
Hudayday 7233212
[None][perf] rotate TriAttention mean score coefficients in the score…
Hudayday accceea
[None][chore] Move the tie-settlement reference kernel into its unit …
Hudayday 6e24355
[None][chore] Retire the register-staging sparse-KV compaction fallback
Hudayday 6eff0e9
[None][chore] Fold the never-tuned offset ladder bound into a constant
Hudayday 4de5227
[None][chore] Move the cohort-tail test helper into the test conftest
Hudayday c8c6bd7
[None][feat] Generalize the CuTe score kernel to 32-token pages
Hudayday a3c0053
[None][feat] Extend the CuTe score kernel to 64-frequency, GQA-group-…
Hudayday 104f1c1
[None][chore] Log when the CuTe score path engages
Hudayday 9c0cf95
[None][test] Migrate compaction fixtures to the shipped bf16 geometry
Hudayday 727ae54
[None][chore] Warn when the opt-in CuTe score cannot engage
Hudayday 2012bde
[None][feat] Make the CuTe DSL kernel the only TriAttention score path
Hudayday dbaccb8
[None][chore] Drop year-only diffs against main
Hudayday 5013e99
[None][feat] Fuse settle+pack and gather mean phases from a position …
Hudayday 1b3cd45
[None][fix] Clamp gathered phase rows and keep table construction dev…
Hudayday 2b3e973
[None][chore] Drop a stale kernel-name reference from the fused pack …
Hudayday 294176f
[None][feat] Integrate the fused score+stats+union pipeline (opt-in, …
Hudayday c5795bb
[None][fix] Decode staged page ids in the fused score kernel
Hudayday 448db53
[None][perf] Bucket the score scratch by cohort need and widen its ba…
Hudayday 78b7444
[None][feat] Generalize the fused score kernel to 32-token pages
Hudayday b86594e
[None][feat] Extend the fused score kernel to 64 frequencies and GQA …
Hudayday 3936daf
[None][feat] Read the fused score window start from per-request metadata
Hudayday 623df3d
[None][feat] Retire the split union scoring path
Hudayday 56498df
[None][feat] Retire the single-shot CuTe score kernel
Hudayday be073ed
[None][fix] Fold 64-bit score offsets into the union finalizer's tail…
Hudayday 98bab8b
[None][fix] Skip top-k sentinel lanes in the settle threshold gather
Hudayday 2f03cd9
[None][chore] Carry the due count on an ungated eviction-round NVTX r…
Hudayday f0d756d
[None][perf] Emit the approximate FTZ square root in the fused score …
Hudayday 2faf34f
Merge upstream main at 128d020489 into v4-branch
Hudayday 6da91b6
[None][chore] Trim narration comments and drop dead score-runner wrap…
Hudayday 346eb1a
[None][test] Slim TriAttention unit suite: torch oracles, table-drive…
Hudayday f21f1dd
[None][refactor] Flatten keep-set selector hierarchy into direct kern…
Hudayday a05be27
[None][refactor] Straight-line the eviction round flow
Hudayday 90664ff
[None][refactor] Trust the pipeline: delete in-flow re-validation and…
Hudayday 66fe91d
[None][chore] Kernel comment clarity + one-value scaffolding removal
Hudayday c80d714
[None][test] Collapse corner grids and mock-theater to representative…
Hudayday bb506ce
[None][fix] Reject generation requests that skipped on_request_init
Hudayday aa026ff
[None][refactor] Build the eviction cohort where its values are born
Hudayday 0bee387
[None][refactor] Lock the fused dense pack on and drop the compiled-s…
Hudayday 6c4381d
[None][doc] Align the README with the shipped defaults and contracts
Hudayday 563d1cd
[None][test] Retire mock legs and duplicate grids ruled out with the …
Hudayday 95d79f7
[None][refactor] Rename TriAttention top_B to budget (official name, …
Hudayday 30b4cb3
[None][fix] Resolve RoPE tables via the transformers 5.5 rope_paramet…
Hudayday d475bf9
[None][refactor] Hoist compaction to package level and inline the rou…
Hudayday a0b90d4
[None][chore] Zero-risk clarity pass from the findings ledger (knife …
Hudayday 78aab7d
[None][refactor] Codegen-identical dedup batch + scaffolding kills (k…
Hudayday 4f22db1
[None][refactor] Framework census F-batch: compaction contract + hook…
Hudayday c136453
[None][test] Test tranche 3: dedupe scaffolding and fold duplicate gu…
Hudayday 4542815
[None][refactor] Straighten init_eviction_buffers: one construction p…
Hudayday 14d622e
[None][refactor] Fold runner compile ritual and single-heir helpers
Hudayday 16ddb74
[None][perf] Host-work census batch: per-step and per-round dispatch …
Hudayday d069359
[None][refactor] Fold the eight raw-band TMA copy rituals into one tr…
Hudayday 4c39809
[None][chore] Restore the draft-cache property and short hook docstrings
Hudayday 3f28019
[None][chore] Revert the config-time normalize_scores validator to th…
Hudayday af1909e
[None][test] Test tranche 3 wave 2: merges, narration trims, official…
Hudayday 0b959b2
[None][chore] Trim docstrings and comments to upstream brevity
Hudayday 6d8047e
[None][chore] One-line the branch-added comments outside the compress…
Hudayday 2caf43c
[None][perf] Cache launch-path from_dlpack wraps per persistent buffe…
Hudayday 16f34c9
[None][perf] Stage cohort metadata with in-place numpy row writes (kn…
Hudayday 71bbedc
[None][refactor] Inline the mean-phase table wrappers into their call…
Hudayday 3a7c019
[None][chore] Compress docstrings to one or two lines
Hudayday a321e33
[None][refactor] Collapse init parameter transport; compaction become…
Hudayday b423dbc
[None][perf] Size the score-only raw-K smem by its single-buffer stag…
Hudayday 9cb7af7
[None][refactor] Fission the fused settle+pack kernel: decision settl…
Hudayday b83f80c
[None][refactor] Remove the single-value pin_prefill and count_prompt…
Hudayday a611ebd
[None][refactor] One round owner: merge stage, run, and consume; dele…
Hudayday 21add9c
[None][perf] Persist the per-head gather index; refresh only its base…
Hudayday 4de514a
[None][perf] Settle reads per-request prompt offsets; drop the per-ro…
Hudayday 5da7989
[None][perf] Launch eviction rounds at the active cohort size (knife …
Hudayday 470acde
[None][chore] Return one named plane bundle; no anonymous tuple unpac…
Hudayday da7065e
[None][chore] Parameter-hygiene sweep: cluster, rename, and close orp…
Hudayday d604fa1
[None][refactor] P0 closure: dead fields, duplicate guards, per-round…
Hudayday 82c4893
[None][fix] Bind the settle-stats epsilon as a constexpr default; Tri…
Hudayday df979c8
[None][refactor] P1 owner consolidation: canonical pool ids, opaque c…
Hudayday d2c119f
[None][refactor] Move the mean-phase table builder into its owner module
Hudayday f9615bb
[None][test] Test tranche 4: post-restructure orphan leg, matrix sque…
Hudayday 53268b3
[None][refactor] Constructor takes the whole config; drop the Base pr…
Hudayday 368fa8c
[None][refactor] Dissolve the runner shell and the bufs bag; TriAtten…
Hudayday e7819dd
[None][chore] Reflow the compression config docstring for the legacy …
Hudayday e04902c
[None][test] Final backstop: drop the config tautology and reflection…
Hudayday 9a99caf
[None][refactor] Fold the launch-record grouping into init as one fam…
Hudayday 702954a
[None][refactor] Delete the construction-time V2 compatibility valida…
Hudayday 216ffb1
[None][refactor] Resolve manager-lifetime layer facts at construction…
Hudayday fe11a3d
[None][chore] Trim regrown narration comments to the banner bar (knif…
Hudayday 2c5ef37
[None][refactor] One source of truth for calibration/copy state; merg…
Hudayday f5e9c62
[None][refactor] Buffer build reads the layout's own maps; direct bui…
Hudayday c5efed4
[None][refactor] Compaction grouping drops its anachronisms; one owne…
Hudayday 7539fcd
[None][refactor] Drop the dead epilogue parameter and host alias twin…
Hudayday 4877392
[None][test] Trim the draft-contract acceptance test to its live asse…
Hudayday aa9e0e8
[None][chore] Trim comments to plain functional descriptions (knife 40)
Hudayday be747b6
[None][chore] Drop the block-offset gather check wall and dead debug …
Hudayday ae0e190
[None][refactor] Order TriAttention by lifecycle and slim the compact…
Hudayday 9b676a6
[None][refactor] Give compaction a single-cache typed plan builder
Hudayday 7b28954
[None][refactor] Flatten compaction launches into CompactionParams
Hudayday a2614bf
[None][refactor] Make CompactionParams a frozen dataclass
Hudayday ff8bb73
[None][refactor] Fill CompactionParams progressively
Hudayday b57e20b
Merge commit '75b39d4368204267e70fc3daadaf1820d1fc99ed' into v4-branch
Hudayday 18c9695
[None][chore] Order compaction params below the pack kernel
Hudayday cd50a4e
[None][chore] Simplify the compaction kernel comments
Hudayday 1bad4ac
[None][chore] Sync review remediation from compaction PR branch
Hudayday 597ac68
[None][fix] Close three eviction-runtime lifetime gaps: score-capacit…
Hudayday a626ae0
[None][refactor] Straighten the eviction control plane into one trans…
Hudayday c87378c
[None][chore] Fail fast on rope and model-config loading; drop the im…
Hudayday bccdc8d
[None][refactor] Close the resident-state names: one compiled-score m…
Hudayday e6d2cb7
[None][perf] Reduce score windows straight from the scratch and write…
Hudayday 1a32167
[None][fix] Slice the score calibration to this rank's attention head…
Hudayday 5b532d9
[None][fix] Restore the exact global union under TP: gather rank unio…
Hudayday faba603
[None][chore] Align TriAttention kernel-boundary names to the module …
Hudayday 0d68666
[None][chore] Drop the per-round pool-drift poll and legacy rope conf…
Hudayday 77017bc
[None][doc] Note that the native compact op derives batch from tensor…
Hudayday cb0101b
[None][fix] Validate the decision-row layout at the compaction API bo…
Hudayday bb89ca1
[None][test] Preserve compaction tests in TriAttention stack
Hudayday 395e9c8
[None][chore] Keep TriAttention cleanup inside its PR boundary
Hudayday 36090b8
[None][chore] Simplify TriAttention eviction runtime
Hudayday 1a0a26e
Simplify TriAttention eviction flow
Hudayday 418c660
[None][refactor] simplify TriAttention eviction runtime
Hudayday 597f417
Merge commit '5ac225960070e4688a2fc4cfffaaee57fb166c74' into v4-branch
Hudayday 1c309dd
fix: align TriAttention selection buffers
Hudayday 3e3fc88
style: use relative TriAttention imports
Hudayday 66fe4e8
style: make TriAttention imports consistently relative
Hudayday dadffc8
[None][refactor] Simplify TriAttention runtime flow
Hudayday ae6c2c5
Merge remote-tracking branch 'nvidia/main' into v4-branch
Hudayday e72af06
[None][chore] Format TriAttention sources
Hudayday d3e379e
[None][test] Align TriAttention fixtures with KV cache V2
Hudayday 5bf4f3a
[None][fix] Correct TriAttention union tail stores
Hudayday ad35f62
[None][refactor] Encapsulate TriAttention Triton kernel launches
Hudayday 333e7bf
[None][refactor] Centralize KV-cache compression capabilities
Hudayday 693dcba
Merge latest main into kvcache-v2-triattention-no-engine
Hudayday 39d5078
[None][fix] Gate TriAttention on SM100-family GPUs
Hudayday 8f11102
[None][chore] Apply TriAttention factory formatting
Hudayday 7561378
Merge latest main into kvcache-v2-triattention-no-engine
Hudayday aee6c52
Merge latest main into kvcache-v2-triattention-no-engine
Hudayday a27a55c
[None][refactor] Rename TriAttention compression manager
Hudayday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
lfr-0531 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # TriAttention KV-Cache Compression | ||
|
|
||
| This document describes enabling TriAttention KV-cache compression in TensorRT-LLM. | ||
|
|
||
| TriAttention is a training-free, decode-time KV-cache eviction method for long-context LLM inference. During generation it periodically scores the cached tokens by a trigonometric importance measure derived from offline per-head query statistics (calibration), keeps the most important `budget` tokens, and physically compacts the cache — reducing KV-cache memory so more sequences fit on a GPU at once. | ||
|
|
||
| For technical details see the paper [TriAttention](https://arxiv.org/abs/2604.04921) and the official implementation [github.com/WeianMao/triattention](https://github.com/WeianMao/triattention). | ||
|
|
||
| ## Overview | ||
|
|
||
| TriAttention runs entirely in the generation phase and reuses the standard dense attention kernel over the compacted cache: | ||
|
|
||
| 1. **Calibration (offline, one-time per model).** The importance score needs each attention head's mean and magnitude of the pre-RoPE query, gathered over a small calibration corpus. **TensorRT-LLM does not compute calibration** — you produce it once with the official tool and pass the resulting `.pt` file. TensorRT-LLM loads and converts it when the compression manager is created. | ||
| 2. **Periodic eviction (during generation).** Every `beta` confirmed generation tokens, once a sequence is over budget, TriAttention scores the evictable decode region, selects `budget` decode tokens to keep, preserves the prompt, and physically compacts the KV cache down to that set. A speculative iteration may confirm multiple tokens; crossing multiple periods in one update is coalesced into one eviction. | ||
|
|
||
| TriAttention is integrated into TensorRT-LLM as a KV-cache compression manager on top of the `KVCacheManagerV2`. Scoring runs on CuTe DSL (SM100) and Triton kernels; compaction is a native CUDA kernel. | ||
|
|
||
| ## Support Matrix | ||
|
|
||
| * NVIDIA B200 (SM100; the current validated target) | ||
| * Paged KV Cache (`KVCacheManagerV2`) | ||
| * PyTorch backend | ||
|
|
||
| **Notes:** | ||
| 1. TriAttention supports KV-cache block reuse. V2 reuses the committed prompt prefix, while TriAttention preserves that prefix and compacts only the generation suffix. | ||
| 2. TriAttention requires the V2 KV-cache manager (`use_kv_cache_manager_v2=True`). | ||
| 3. TriAttention does not compute calibration. Bring the official tool's calibration `.pt`; see [Calibration](#calibration). | ||
| 4. The current SWA path covers models such as GPT-OSS whose V2 pools remain full length and whose attention kernel applies the window. Native sliding-eviction layouts such as Gemma 4, SSM/hybrid pools, and MLA caches are not supported. | ||
| 5. Speculative decoding is supported for one-model MTP and EAGLE3 with `eviction_mode="union"`. Tensor parallelism beyond TP1, attention DP, and disaggregated serving have not yet been validated end to end. | ||
|
|
||
| ## Calibration | ||
|
|
||
| The calibration file is produced once per model with the official tool, then reused for every inference run with that model. | ||
|
|
||
| Generate the calibration file for your model with the official repository (for | ||
| example `qwen3-8b-calibration.pt` for Qwen3-8B), keep it anywhere on disk, and | ||
| point `calibration_path` at it: | ||
|
|
||
| ```bash | ||
| # Clone + install the official tool | ||
| git clone https://github.com/WeianMao/triattention.git | ||
| cd triattention && pip install -e . | ||
|
|
||
| # Calibrate (writes the official {metadata, stats} .pt) | ||
| python3 scripts/calibrate.py \ | ||
| --model <path_to_model> \ | ||
| --input data/calibration_text.txt \ | ||
| --output <model>_calibration.pt \ | ||
| --max-length 32768 \ | ||
| --device cuda | ||
| ``` | ||
|
|
||
| TensorRT-LLM accepts that file directly: it reads the official `{metadata, stats}` layout and derives the model's RoPE tables from the model config, then converts everything to its runtime schema at load. (An already-converted flat `.pt` is also accepted.) | ||
|
|
||
| ## Usage | ||
|
|
||
| To enable TriAttention, pass a `TriAttentionKvCacheCompressionConfig` (the eviction knobs + the calibration file) to the `LLM` constructor. TriAttention is a pure compression method — there is **no** sparse-attention config and no custom attention backend; decode runs the model's standard attention over the compacted cache. | ||
|
|
||
| ### Python API | ||
|
|
||
| ```python | ||
| from tensorrt_llm import LLM, SamplingParams | ||
| from tensorrt_llm.llmapi import (KvCacheConfig, | ||
| TriAttentionKvCacheCompressionConfig) | ||
|
|
||
| # 1. Configure the eviction manager + point it at the calibration file. | ||
| compression_config = TriAttentionKvCacheCompressionConfig( | ||
| budget=2048, # tokens kept at each eviction (prompt is kept on top) | ||
| beta=64, # eviction period, in confirmed generation tokens | ||
| eviction_mode="union", | ||
| calibration_path="/path/to/qwen3-8b-calibration.pt", # official tool's output | ||
| model_path="<path_to_model>", # used to derive the RoPE tables | ||
| ) | ||
|
|
||
| # 2. TriAttention needs the V2 KV-cache manager and supports block reuse. | ||
| kv_config = KvCacheConfig(enable_block_reuse=True, use_kv_cache_manager_v2=True) | ||
|
|
||
| llm = LLM( | ||
| model="<path_to_model>", | ||
| backend="pytorch", | ||
| kv_cache_compression_config=compression_config, | ||
| kv_cache_config=kv_config, | ||
| ) | ||
|
|
||
| # 3. Generate | ||
| prompts = ["To be or not to be, that is the question."] | ||
| sampling_params = SamplingParams(max_tokens=128) | ||
| outputs = llm.generate(prompts, sampling_params) | ||
| ``` | ||
|
|
||
| ### Usage with `trtllm-bench` and `trtllm-serve` | ||
|
|
||
| Pass the configs via `--config config.yaml`. The field names match the Python configs: | ||
|
|
||
| ```yaml | ||
| backend: pytorch | ||
| kv_cache_compression_config: | ||
| algorithm: triattention | ||
| budget: 2048 | ||
| beta: 64 | ||
| eviction_mode: union | ||
| calibration_path: /path/to/qwen3-8b-calibration.pt | ||
| model_path: <path_to_model> | ||
| kv_cache_config: | ||
| enable_block_reuse: true | ||
| use_kv_cache_manager_v2: true | ||
| ``` | ||
|
|
||
| ```bash | ||
| trtllm-eval --model <path_to_model> --config config.yaml longbench_v2 --max_output_length 1024 ... | ||
| ``` | ||
|
|
||
| ## Configuration Arguments | ||
|
|
||
| `TriAttentionKvCacheCompressionConfig` controls the compression ratio and the eviction algorithm: | ||
|
|
||
| * **`budget`** (int, default=2048): Tokens kept at each eviction. Prompt tokens are always preserved on top of this. Smaller `budget` → more compression. | ||
| * **`beta`** (int, default=128): Eviction period, in confirmed generation tokens (the upstream `divide_length`). Speculative acceptance advances the counter by `1 + accepted_draft_tokens`; at most one eviction is coalesced per final update. | ||
| * **`eviction_mode`** (str, default=`union`): Which token set each eviction keeps. | ||
| * `union`: union of each KV head's top-B, re-ranked by the per-token max score. Matches the official base setting. | ||
| * `per_head`: each KV head keeps its own set, shared across layers (mean of per-layer maxima). | ||
| * `per_layer_perhead`: each head keeps its own set, fully independent per layer. | ||
| * **`normalize_scores`** (bool, default=True): Z-normalize each head's scores over the decode region before selection (upstream default). `union` eviction always z-normalizes: `False` is overridden to `True` with a warning. | ||
| * **`calibration_path`** (str): Path to the calibration `.pt` from the official tool. Required — TensorRT-LLM does not compute calibration. | ||
| * **`model_path`** (str): Checkpoint path, used to derive the model's RoPE tables when converting the official calibration file and to classify kernel-masked sliding-window (SWA) layers from the model config. |
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.