Repository navigation
Conversation
Add TurboQuant (arXiv:2504.19874) as a second cold-page quantization
format next to NVFP4. Like NVFP4 cold pages, it only changes how KV
Pages are stored in the Host and Disk tiers; the active GPU cache keeps
its runtime KV type.
- Config: ColdPageQuantizationCompressionConfig(quant="turboquant",
turboquant_bits in {2, 2.5, 3, 3.5, 4}, turboquant_mode in {mse, prod},
turboquant_seed). Options of the other format and prod with
fractional bits are rejected; serve schemas, golden manifest and
telemetry docs updated.
- Codec: Haar rotation + Lloyd-Max codebooks + per-vector least-squares
scale (mse, Algorithm 1); prod adds a 1-bit QJL sign of the residual
(Algorithm 2). Fractional bits split channels per Page/head by energy.
No calibration. Triton kernels (SM80+), launched on the KVCM stream
with device-side Page indices.
- Layouts: MHA/MQA/GQA K and V, MLA latents incl. 576-wide rows,
DeepSeek-V4 CSA rows (RoPE and indexer kept lossless), skip_rope with
the NVFP4 rules; FP16/BF16/FP8 runtime KV; target and draft KVCMs.
- Shared row-geometry and DeepSeek-V4 helpers move from the NVFP4
provider to the cold-page base class; NVFP4 behavior is unchanged.
- Tests (codec, KVCacheManagerV2 integration, config), a codec
microbenchmark, a quality script, an end-to-end cold-tier accuracy
example, and docs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fanrong Li <[email protected]>
… benchmark, review fixes Kernels (measured on GB300 with the GLM-5 MLA latent, 78 x 576 BF16, 256 Pages, cold pages in HBM: encode 1813 -> 1076 us, decode 1431 -> 834 us; with pinned memory on the GPU's socket TurboQuant is now 0.98x / 1.11x the NVFP4 time, was 1.65x / 1.71x): - Decode looks the centroids up in a per-codebook fp32 table (one load per value instead of a compare/select chain); for the MLA latent, decoding cold pages of the previous kernels gives bit-identical values. - Encode selects the centroid with the codebook search's own comparison bits, and encodes rows wider than 512 one instance at a time after a prescale pass, so the row no longer stays in registers. - Launch shapes of mse rows wider than 256 were measured on GB300 and apply on SM100-family GPUs only. A single 512-value instance (skip_rope_quantization on GLM-5) decodes its output in two blocks of 256 with 128-row tiles: HBM decode 2097 -> 1032 us. - Decoded FP16 values saturate at the FP16 range instead of becoming inf. Admission: an FP8 active KV cache needs compute capability 8.9 for TurboQuant (Triton FP8); it was admitted from 8.0 and failed in configure(). Benchmark and docs: bench_cold_page_codec.py gets GLM-5, DeepSeek-V3.2 / Kimi-K3 MLA (FP8) and DeepSeek-V4 CSA cases (with skip_rope_quantization for a like-for-like NVFP4 comparison); the encode/decode table is re-measured with pinned memory on the GPU's own and the other CPU socket. Mixed-precision cold pages (first/last N, from main): the real-codec host-tier test also runs with TurboQuant. Review fixes: - Docs: the fractional-bit channel selection (outliers above 4x the median energy, then the lowest-numbered channels), 576-value fractional vectors as two 288-value instances, prod re-encoding, and what the accuracy script's iteration statistics verify. - cold_tier_accuracy.py: sum page sizes and cold capacity over the attention pool groups, require Disk-level reuse with --disk, never read a previous run's result or accept one saved before a failed exit, exit 0 only if every requested format is valid, and reject empty datasets. - turboquant_quality.py: order the hot-buffer writes before the codec stream, and measure distinct K and V inputs. - Tests: determinism also for prod and the QJL projection seed; the factory test follows main, where the estimation build gets the provider too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
Accuracy tool (examples/kv_cache_compression/cold_tier_accuracy.py): - --extra-llm-args may not set model or kv_cache_compression_config; a replaced codec still reuses cold pages and would be reported as the requested format. - An empty --formats list is rejected instead of exiting with success. - The cold reuse is reported as reuse events per prefix block: the counts are summed over attention lifecycles, so they are not a coverage of distinct prefix blocks. Docs: the activation example in turboquant_cold_page.md drains the statistics of the fill phase first and reports the two reuse requests on their own. Serving schemas: the generator mirrors the cross-field rules of ColdPageQuantizationCompressionConfig (no options of the format that is not selected; prod takes 2, 3 or 4 bits) in both serving snapshots, and the schema tests check these cases against the runtime model. Benchmark (bench_cold_page_codec.py): - FP8 cases pass their dtype to the factory, so admission sees the measured cache, and are skipped below compute capability 8.9. - Every (layer, buffer) nMSE must stay within 4x the case-wide nMSE: a layer that decodes to zeros no longer hides in the mean. - Non-finite values are written to --json as null. Tests: - build_codec_state rejects unsupported vector widths (CPU only): alignment, instance size, the power-of-two rest and the piece count. - FP16 decode saturates at +-65504 when values at the FP16 limit reconstruct above it; the test fails without the clamp. - The stream test passes a stream that is not current and holds it on a host flag (cuStreamWaitValue32) instead of a timed sleep. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
Review feedback: KVCacheManagerV2 keeps a Page in one tier at a time, so every offload of an onboarded Page encodes the decoded values again. TurboQuant-mse reproduces its codes over these round trips, but the QJL error of TurboQuant-prod compounds: at 2 bits its nMSE is 0.55 after one round trip, 16.9 after four and 2.3e6 after sixteen. Offer only mse; prod can come back with a mechanism that avoids repeated quantize and dequantize cycles. - Config: remove turboquant_mode. turboquant_bits selects 2, 2.5, 3, 3.5 or 4 bits of TurboQuant-mse. The serve schemas, the golden manifest and the telemetry docs are updated. - Kernels and provider: remove the QJL projection, the residual-norm scalars and the prod-only row split; BLOCKED is now a flag for mse rows wider than 512 values. The cold pages and decoded values of 53 mse and fractional-bit geometries are byte-identical to before (GB300). - Tests, benchmark (llama8b-bf16-prod4), quality tool (1, 4 and 16 round trips instead of inner-product columns), examples and docs: no prod; the docs say why it is not offered. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
- Decode: a single 512-value instance (the GLM-5 latent with skip_rope_quantization, DeepSeek-V4 CSA rows) loads its codes once, as 32-bit words kept in registers, and unpacks them again for the second half of its output columns instead of reading the cold page twice. The decoded values are byte-identical; on GB300 the GLM-5 skip_rope decode goes from 1.51x to 1.10x the NVFP4 time. Remove the decode column split, which no launch configuration enabled. - DeepSeek-V4 CSA rows follow skip_rope_quantization as with NVFP4: by default the whole 512-value row is encoded. - The cold-page base class owns the buffer and layer layouts, the codec state, the skip_rope model check and the draft rule of both formats, and no longer defaults the format name and range alignment to NVFP4's. Reuse pad_up and triton.next_power_of_2; load the copy kernels' modules at configure time. - Tests: 32 repeated round trips must stay finite and settle with period 1 or 2; DeepSeek-V4 with and without skip_rope; the shuffled batch decodes back into its source slots; FP8 cases need SM89; the target KVCM is shut down if the draft one fails. - Benchmark: bytes stored unchanged (indexer rows, kept RoPE) must match exactly, NVFP4 gets an nMSE bound, the check must reject corrupted decodes, and the format order reverses every repetition. - turboquant_quality.py --vectors runs the round trips on real K vectors. The docs add GLM-5.3 latents, describe how round trips settle, state the SM89 requirement of FP8, and call cold_tier_accuracy.py a smoke test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
- Fractional encode: a row votes on the high-bit channel split only if its energy is finite. tl.max skips NaN, so a garbage row holding one NaN among finite values used to pass the amax check, turn a channel's energy into NaN (then zero) and move that channel to the low-bit group, changing how the valid tokens of a partial Page are coded. Finite inputs encode to the same bytes as before. - test_partial_page_garbage_does_not_leak_into_valid_tokens adds rows with a single NaN and checks that the valid tokens restore exactly as with a zero tail. - test_skip_rope_quantization_keeps_rope_bytes copies its parameter dictionary before popping from it, so a rerun sees the same input. - cold_tier_accuracy.py kills the worker's process group when the driver is interrupted, not only on timeout: the worker has its own session, so Ctrl-C does not reach it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
…long Pages Fractional bits (2.5, 3.5) on rows wider than 448 values (an MLA latent of 576, a 512-value row) failed for Pages of more than 32 tokens: - Decoding faulted with a misaligned address on GB300 for Pages of 64+ tokens. A decode tile was the whole KV head, and tensor-core tiles of 64+ rows accumulate in tensor memory (512 fp32 columns, shared with the staged operand), which a row wider than 448 does not fit. Such heads now decode in tiles of at most 32 rows (register accumulators); every tile reads the channel split of its own head (HEAD_ROWS). - Encoding a 512-value row of a 128-token head ran out of shared memory (256 KiB staged). The code chunk now halves until the head and a chunk of the rotation stay within 192 KiB; this changes only that geometry. Pages of up to 32 tokens are unchanged: 55 geometries encode and decode to the same bytes as before. New tests cover 576-wide latents with 64- token Pages and 512/576-wide rows of two heads with 64- and 128-token Pages. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
Fractional bit widths (2.5 and 3.5) move to a separate draft PR until their re-encoding drift is resolved. They choose the high-bit channel half from the Page on every encode, so a Page offloaded again after an onboard can move channels across the outlier threshold, and the error grows with every round trip (x1.7 on 128-value heads and x3.1-3.5 on 576-value MLA latents over 32 round trips; +48% on GLM-5.3 latents). Integer bit widths keep their error exactly. - Kernels: drop the outlier selection, the channel masks, the gathered rotation rows and the second code group (MODE, OFF_B*, OFF_MASK, TILE_ROWS, HEAD_ROWS); tiles are BLOCK_M rows again. - turboquant_bits accepts 2, 3, or 4; the field stays a float, so the telemetry type and the default (4) do not change. Both serve schemas updated. - Docs, examples, the quality tool and the tests drop the fractional settings. The wide-row test (512/576 values on 64/128-token Pages) now runs 3 bits; the garbage-row and DeepSeek-V4 tests use 2 and 3 bits. On GB300 the 2/3/4-bit cold pages and decoded values are byte-identical to those of the previous commit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
Adds turboquant_bits 2.5 and 3.5 on top of the integer settings, and makes 3.5 the default (the paper's quality-neutral setting for the KV cache). For each Page, layer, buffer and KV head, half of the channels get b + 1/2 bits and the other half b - 1/2 bits, each half with its own rotation, codebook and BF16 scale. The high-bit half holds the outlier channels (energy above 4x the median channel energy) and then the lowest-numbered other channels; a channel mask in the Page records the split. No calibration is needed. Bits per value at head dim 128: 2.78 and 3.78. Kernels: - One program per KV head of a Page. The head's rows vote on the channel split in 8-row blocks, so any number of tokens per Page works; rows with NaN or Inf do not vote. - The median channel energy is found four bits at a time (8 steps). - Each group is coded over its channels in channel order: the kernels load and store the channels by index and use fixed rotations (the diagonal blocks) instead of gathering an N x N matrix per head. - Groups are coded one at a time in 32-row tiles with few warps (1-4 by width), chunks of 32 coordinates (64 for rows of 512+ values), and decoding prefetches the next chunk's codes. On GB300 against NVFP4 (encode / decode, 256 Pages, own socket), 3.5 bits: GLM-5 MLA 3.3x / 3.1x, DeepSeek-V3.2 MLA FP8 3.6x / 3.2x, DeepSeek-V4 CSA 1.0x / 1.5x, Llama-3.1-8B 1.8x / 1.0x. Integer bit widths are unchanged. Known issue, to be resolved before this leaves draft: the split is chosen again on every encode, so a Page offloaded again after an onboard can move channels across the outlier threshold, and the error grows with every round trip (in a codec study over 32 round trips: x1.7 on 128-value heads, x3.1-3.5 on 576-value MLA latents, in BF16, FP16 and FP8 alike). The benchmark gains 3.5-bit cases and --bits, which runs any case at every bit width. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fanrong Li <[email protected]>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Note
Draft, stacked on #22095. This branch holds the commits of #22095 plus one commit, "TurboQuant cold pages: fractional bits (2.5 and 3.5)"; review only that commit. It will be rebased once #22095 merges, and it leaves draft only after the re-encoding drift below is resolved.
Adds fractional TurboQuant cold-page bit widths,
turboquant_bits: 2.5and3.5, on top of the 2/3/4-bit settings of #22095, and makes 3.5 the default (the paper's quality-neutral setting for the KV cache, as suggested in the review of #22095).Format. For each Page, layer, buffer and KV head, half of the channels get b+½ bits and the other half b−½ bits, each half with its own rotation, codebook and BF16 scale. The high-bit half holds the outlier channels (energy above 4× the median channel energy) and then the lowest-numbered other channels; a channel mask in the Page records the split. No calibration is needed. Bits per value at head dim 128, side information included: 2.78 at 2.5 bits and 3.78 at 3.5 bits (NVFP4: 4.5).
Kernels. One program per KV head of a Page; the head's rows vote on the split in 8-row blocks (any number of tokens per Page; rows with NaN or Inf do not vote). The median channel energy is found four bits at a time. Each group is coded over its channels in channel order with fixed rotations, in 32-row tiles with 1–4 warps; decoding prefetches the next chunk's codes.
Encode / decode time vs NVFP4 at 3.5 bits (
bench_cold_page_codec.py --bits 3.5, GB300, 256 Pages per call, pinned cold pages on the GPU's own CPU socket):On the other socket (slower link) the MLA cases are 2.1–2.3×. Integer bit widths are unchanged.
Open issue: error grows when a Page is re-encoded
KVCacheManagerV2 re-encodes a Page each time it offloads the Page again after an onboard. Fractional bits choose the split again from the decoded data, which moves channels near the 4×-median threshold between the halves; every code of such a head changes, and the error grows with each round trip instead of staying put as it does at 2/3/4 bits.
Under evaluation: choose the split once per (layer, buffer, KV head), on the first encode, keep it in the codec state, and reuse it for every later encode; decode is unchanged. To do before this PR leaves draft: settle the fix, re-run the codec study and an end-to-end accuracy check at 3.5 bits, and revisit the 3.5-bit default.
Test Coverage
tests/unittest/_torch/kv_cache_compression/test_turboquant_cold_page.py: fractional bits lie between their integer neighbours; repeated round trips (3.5/2.5 settle within the 10% bound of the current test, which the fix should tighten); bit budget; determinism; MLA 576 with a lossless side buffer; heads of 96/512/576 values on 16/64/256-token Pages; DeepSeek-V4 CSA; garbage rows with NaN/Inf do not vote.test_turboquant_cold_page_kvcm.py: a 3.5-bit Host round trip through KVCacheManagerV2.test_turboquant_cold_page_config.py,test_trtllm_serve_config_schemas.py,test_llmapi_config_telemetry_docs.py: 2.5/3.5 accepted, default 3.5.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.🤖 Generated with Claude Code