Skip to content

[TRTLLM-16288][feat] Integrate sparse KV offload for DeepSeek-V4 Flash and GLM5.2 on KVCM2 - #21350

Merged
cascade812 merged 26 commits into
NVIDIA:mainfrom
cascade812:guiju/sparse-kv-offload
Nov 11, 2026
Merged

cascade812 merged 26 commits into
NVIDIA:mainfrom
cascade812:guiju/sparse-kv-offload

Conversation

@cascade812

@cascade812 cascade812 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds sparse KV cache offload for DeepSeek-V4 and DSA (GLM-5.2) layers on KV cache manager v2, building on its sparse attention core (#21129).

On a decode-only worker, the KV history that sparse attention selects from lives in pinned host memory. Each decode step fetches the units the indexer selects into a per-request GPU cache, so the GPU holds each request's working set rather than its whole sequence. What moves to the host is the MLA latent cache for DSA and the ratio-4 compressed cache for DeepSeek-V4. The indexer and sliding-window caches stay on the GPU.

Resident vs offload performance

The figures compare resident KV and sparse KV offload with NVFP4 weights, FP8 KV, and the same 32,768-token prompt with 160 output tokens per request. Eight GB300 GPUs run three TP2/EP2 prefill workers and one TP2/EP2 decoder with attention DP2. Concurrency and throughput are totals across the two decoder GPUs. The left panels show decoder tokens/s; the right panels show median decode-step intervals.

DeepSeek-V4 Flash, m=4. Offload reaches 55,794 tokens/s at 3,000 requests, versus 41,743 tokens/s at 1,264 requests for resident KV (+33.7% peak throughput). The largest batch grows from 1,266 to 3,000 requests (2.37×).

image

GLM-5.2, m=2. Offload reaches 8,643 tokens/s at 302 requests, versus 3,063 tokens/s at 58 requests for resident KV (2.82× peak throughput). The largest admitted batch grows from 58 to 316 requests (5.45×); the throughput peak occurs below that admission limit.

image

Configuration

  • enable_kv_cache_offload on DeepSeekSparseAttentionConfig (DSA) and DeepSeekV4SparseAttentionConfig turns offload on. kv_cache_offload_config (SparseKvCacheOffloadConfig) sizes it:
    • gpu_cache_factor: each request's GPU cache, in selections. The default is 2.0.
    • host_history_size: pinned host bytes per rank for the history pools and their staging buffers, held as an upper bound: the pools pin only what the GPU quota's slots pair with. A size below what the manager must always hold, such as one max_seq_len request, is rejected. It is separate from kv_cache_config.host_cache_size; the two together must fit the rank's share of available host memory and the pinned-memory limit.
    • When host_history_size is unset, the history pools come first. They may take the host memory a rank may pin (half its share of MemAvailable, and 80% of RLIMIT_MEMLOCK), less the staging buffers and, unless host_cache_size or a disk tier is set, room in the host tier for one max_seq_len request. The automatic host tier then takes the memory they leave, up to the GPU KV cache quota.
  • Offload leaves the indexer's use_cute_dsl_paged_mqa_logits default as it is (CuTe DSL on SM100-family GPUs, DeepGEMM elsewhere); an explicit value is honored.
  • The serve schemas, the llm_args golden manifest and the telemetry reference are updated.

Supported configurations

Offload runs only on a decode-only worker, the generation server of disaggregated serving. Executor creation rejects it without a cache_transceiver_config. The offloading worker also requires:

  • a single beam and no speculative decoding;
  • KV cache compression, CP Helix and draft KV caches disabled;
  • no pipeline parallelism.

Block reuse can stay on. The offloading worker commits each received prompt to its reuse tree, so a later request with the same prompt prefix skips that part of the KV transfer. Only prompt blocks are reused; decode output is not committed.

Runtime

  • KVCacheManagerV2 owns the attention Batch. It seats a request on admission, publishes once per step, flushes the units a watermark is about to pass, and returns the request's arena lease when the request leaves.
  • DeepSeek-V4 and DSA share one fetch path (sparse/offload.py, sparse/offload_kernels.py): resolve each selection, then fetch its member layers into the arena.
  • Memory sizing (kv_cache/sparse_offload_memory.py):
    • the arena and offload buffers come out of the device KV budget before max_tokens sizes the pools;
    • host history is held to the native manager's floor and reserved against the capacity synced across ranks;
    • host memory is measured from MemAvailable.
  • An offloading worker skips KV cache estimation, warms up generation shapes only, and captures no prefill CUDA graphs.

Disaggregated serving

  • Sparse KV can be transferred into an offloading generation worker. The page table takes each pool's memory type (GPU memory, or host memory for the offloaded history) from the native manager, and the sender groups its writes by memory type.

KV cache manager v2

  • The sparse resolve keeps its eviction state in one 32-bit word per cached entry: a 7-bit step timestamp, a bit recording whether the entry was already resident at its last use, and the unit ordinal. Victims come from a 256-bucket staleness histogram.
  • The resolve kernel is built for 256 and 512 threads, and the occupancy query picks the width. On B200 it takes 14.98 µs instead of 21.32 µs at GLM-5.2's peak shape, and 23.68 µs instead of 35.71 µs at DeepSeek-V4's.
  • A negative Batch row is rejected.
  • The ScratchDesc / get_scratch_desc(), resume(is_decoding=) and enter_decode() compatibility shims are removed. Callers use get_swa_scratch_range() and get_scratch_slots().
  • SPARSE_ATTENTION_DESIGN.md documents the sparse attention design.

Known limitations

  • SparseOffloadCacheMixin._refresh_sparse_page_index_bufs copies every member's page row, up to the widest block count, into the host block-offset table each step. An incremental copy would have to track the sliding-window rows, which change every step.
  • Without physical-ownership enforcement, the disaggregated sender waits for each memory-type group of a transfer before submitting the next. This serializes a request's GPU and host transfers.

Test Coverage

  • Sparse offload:
    • tests/unittest/_torch/attention/sparse/test_sparse_offload_kernels.py (new)
    • tests/unittest/_torch/pyexecutor/kv_cache/test_sparse_offload_memory.py (new)
    • tests/unittest/_torch/pyexecutor/kv_cache/test_kvcm2_integration.py
    • tests/unittest/_torch/pyexecutor/kv_cache/test_kvv2_host_tier_sizing.py
  • KV cache manager v2 sparse resolve: tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py, TestSparseResolve
  • DeepSeek-V4: tests/unittest/_torch/attention/sparse/deepseek_v4/, covering:
    • test_deepseek_v4_offload.py
    • test_deepseek_v4_cache_manager.py
    • test_deepseek_v4_kernels.py
    • test_compressor_kernel.py
    • test_compressor_module.py
    • test_prims_ts_sparse_mla_fmha.py
  • DSA:
    • tests/unittest/_torch/attention/sparse/dsa/test_dsa_offload_cache_manager.py (new)
    • tests/unittest/_torch/attention/sparse/dsa/test_dsa_offload_config.py (new)
  • Disaggregated:
    • tests/unittest/disaggregated/test_sparse_kv_transfer.py (new)
    • tests/unittest/disaggregated/test_extractor.py
    • tests/unittest/disaggregated/test_deepseek_v4_kv_transfer.py
    • tests/unittest/disaggregated/test_chunked_transfer.py
  • Executor and warmup:
    • tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_warmup.py
    • tests/unittest/_torch/pyexecutor/test_py_executor.py
    • tests/unittest/_torch/pyexecutor/test_resource_manager.py
    • tests/unittest/_torch/compilation/test_phase_selective_forward.py
  • Configuration:
    • tests/unittest/llmapi/test_llm_args.py
    • tests/unittest/llmapi/test_trtllm_serve_config_schemas.py
  • Disaggregated E2E with offload (new), in tests/integration/defs/accuracy/test_disaggregated_serving.py. Each test runs one context server and one generation server and turns offload on for the generation server only, with gpu_cache_factor 1.0 so the history cannot fit the GPU cache. It sends 32 whole GovReport documents of 6,144–8,192 prompt tokens at once, with a batch of 16 and up to 512 output tokens, and checks the summaries' ROUGE-L against a reference measured with the history resident. It also checks that decode ran batched and that at least a full batch of summaries decoded past the GPU cache's free slots:
    • TestDeepSeekV4Flash::test_kv_cache_offload: TP2 + TP2 on 4 GPUs, NVFP4 KV cache, attention DP on the generation server.
    • TestGLM52NVFP4::test_kv_cache_offload: TP4 + TP4 on 8 GPUs, attention DP, run with the checkpoint's FP8 KV cache (kv_dtype=fp8) and with NVFP4 (kv_dtype=nvfp4).
    • TestDeepSeekV4Flash::test_kv_cache_offload_block_reuse: the V4-Flash setup with block reuse on both servers. It sends every prompt twice and requires the second round to find the prompts in the generation worker's reuse tree and to pass the same accuracy check.
  • Test lists:
    • l0_dgx_b200.yml gains the E2E tests above;
    • l0_gb300.yml gains TestSparseResolve::test_colliding_selections_preserve_slots_and_eviction.

Results. On one 8-GPU B200 node, all four E2E tests passed on this code. GovReport ROUGE-L, 32 samples:

Test ROUGE-L Reference / threshold
TestDeepSeekV4Flash::test_kv_cache_offload 33.28 32.81 / 31.81
TestDeepSeekV4Flash::test_kv_cache_offload_block_reuse 33.69, then 33.43 on the repeated round 32.81 / 31.81
TestGLM52NVFP4::test_kv_cache_offload[kv_dtype=fp8] 31.57 31.62 / 30.62
TestGLM52NVFP4::test_kv_cache_offload[kv_dtype=nvfp4] 31.95 31.83 / 30.83

The KV cache manager and offload unit tests (test_kvcm2_integration.py, test_sparse_offload_memory.py, test_dsa_offload_cache_manager.py, test_dsa_offload_config.py, test_deepseek_v4_offload.py, test_deepseek_v4_cache_manager.py) passed in the same build. The other unit tests above run in CI.

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-compatible or api-breaking. For api-breaking, include BREAKING in 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

…DSA on KVCM2

Sparse KV cache offload for DeepSeek-V4 and DSA (GLM-5.x) layers, on the
KVCM2 sparse attention core (NVIDIA#21129). A decode-only worker keeps the KV
history that sparse attention selects from in host memory, and each decode
step fetches the selected units into a per-request GPU cache.

- SparseKvCacheOffloadConfig, enabled with enable_kv_cache_offload on the
  DSA and DeepSeek-V4 sparse attention configs. The serve schemas and the
  llm_args golden manifest follow. With offload on, the indexer's paged MQA
  logits default to DeepGEMM.
- KVCacheManagerV2 owns the attention Batch, with one arena lease per Batch
  row. Offload sizing (sparse_offload_memory.py) takes the arena and offload
  buffers from the device budget before max_tokens sizes the pools, and
  measures host memory from MemAvailable.
- One fetch path (sparse/offload.py, offload_kernels.py) serves the
  DeepSeek-V4 and DSA attention backends. The MLA RoPE write reads the
  token-major block table, PrimTS sparse MLA stays off offloaded ratio-4
  layers, and the offload NVFP4 scratch carries the zeroed KV-tile tail.
- An offloading worker is decode-only: it skips KV cache estimation, warms
  up generation shapes only, and captures no prefill CUDA graphs. Block
  reuse, and offload without a cache transceiver, are rejected.
- Sparse KV transfers into an offloading generation worker.
- KVCM2: the sparse resolve keeps one 32-bit eviction word per cached entry
  and picks its CTA width at dispatch; a negative Batch row is rejected; the
  ScratchDesc / get_scratch_desc(), is_decoding and enter_decode
  compatibility shims are removed; SPARSE_ATTENTION_DESIGN.md describes the
  design.
- For resident-versus-offload parity runs: FORCE_DETERMINISTIC=1 and the
  FORCE_TOPK_KERNEL_DETERMINISTIC / FORCE_MHC_KERNEL_DETERMINISTIC switches
  make TopK, mHC and the trtllm-gen FMHA reduction repeatable, the
  disaggregated sender keeps unclaimed REQUEST_DATA for the transfer timeout
  when that exceeds 120 s, and token_parity.md records the runs.

Signed-off-by: Guiju Zhang <[email protected]>
…he mixed-precision tests

_KVCache.resume no longer takes is_decoding; NVIDIA#21129 kept it only as an
ignored keyword until the full sparse attention support landed. The cached
context and decode tests still passed it, so both would raise TypeError.
Dropping the argument leaves their behaviour unchanged.

Signed-off-by: Guiju Zhang <[email protected]>
Runtime:
- Hold the host history pools to the native manager's floor: the pages
  of its largest constraint batch at max_util_for_resume, plus one pool
  granule per host pool. An explicit host_history_size below the floor
  is rejected with what to change; the automatic budget is raised to it.
  An offloading worker's typical step is a decode step, so it adds no
  context-warmup constraint.
- Reserve host history against the capacity synced across ranks, and
  read host memory limits from effective_available_host_memory().
- Reject pipeline parallelism: the attention Batch seats one
  micro-batch's requests at a time.
- Count the converted index tables and DSA's attention indices in the
  device reservation.
- Disaggregated transfer: only generation-first REQUEST_DATA waits for
  the transfer timeout. Context-first REQUEST_DATA is failed after the
  base TTL, and the warning reports how long it waited. The page table
  takes each pool's memory type from the native storage_medium.
- Size host-backed pools from the native sparse_backing_medium() and
  get_num_bytes() instead of a Python mirror of the layer config.
- PyExecutor declares _is_kv_manager_v2 = False on the class, so the
  forward step reads it on executors the tests build without __init__.

Consolidation:
- One sparse_arena_rows Triton function and input check serve the DSA
  and DeepSeek-V4 index merges. TLLM_SPARSE_OFFLOAD_DEBUG_ASSERT=1
  checks that the merged rows cover every selected block.
- get_scratch_entry() replaces three copies of the scratch lookup, and
  DeepSeek-V4 takes its scratch slot count from the native manager.
- DeepSeek-V4 offload uses DSA's batch validation (decode only), and
  its config check runs once, in the base manager. SparseOffloadState
  drops is_prefill.
- Remove the Python initial_pool_ratio override,
  sparse_offload_pool_ratio and LifeCyclePage.pages_per_request.
- Warmup uses one generation_only flag for Helix CP and decode-only
  workers.
- _raise_on_every_rank uses _sync_kv_cache_manager_init_status.
- DeepSeekV4SparseAttentionConfig inherits enable_kv_cache_offload.

Tests and CI:
- Fix the phase-selective forward stub and the transceiver config of
  the decode-only creator test.
- Add enable_kv_pool_rebalance to the KvCacheConfigV2 stubs: the
  offload config check reads it off kv_cache_config.
- Build fmhaDeterministicTest with add_tllm_gtest and FULL_STACK.
- The DSA offload gate checks for the SM100 family first.
- Remove token_parity.md; the PR description summarizes it.

Docs: the llm_args descriptions (schemas regenerated), the sparse
offload memory docstrings and the Python surface in
SPARSE_ATTENTION_DESIGN.md.

Signed-off-by: Guiju Zhang <[email protected]>

# Conflicts:
#	tests/unittest/_torch/executor/test_py_executor.py
…rminism changes

These changes served only benchmark and validation runs, not production.

- The disaggregated sender kept generation-first REQUEST_DATA for the
  whole transfer timeout instead of 120 s. Only the 32K capacity run
  needed it: it used generation-first scheduling, a 600 s transfer
  timeout and a test-only barrier that held decodes until every prefill
  finished. With the default context-first schedule and 60 s timeout it
  changed nothing. The sender is back to main's fixed 120 s TTL.
- FORCE_DETERMINISTIC, and the new FORCE_TOPK_KERNEL_DETERMINISTIC and
  FORCE_MHC_KERNEL_DETERMINISTIC switches, made TopK, mHC and the
  trtllm-gen FMHA KV reduction repeatable for exact resident-versus-
  offload token comparisons. top_k.py, mhc_cuda.py and fmhaKernels.h
  are back to main. Their tests are removed, along with
  fmhaDeterministicTest and the test_top_k.py entry in l0_b200.yml.

Signed-off-by: Guiju Zhang <[email protected]>
…r DeepSeek-V4-Flash and GLM-5.2

Each test runs one context server and one generation server, turns on
sparse KV cache offload on the generation server only, and checks GSM8K
against the model's reference.

- TestDeepSeekV4Flash::test_kv_cache_offload: TP2 + TP2 on 4 GPUs with an
  NVFP4 KV cache. The generation server uses attention DP and turns off
  block reuse, which offload does not support.
- TestGLM52NVFP4::test_kv_cache_offload: TP4 + TP4 on 8 GPUs with the
  checkpoint's FP8 KV cache and attention DP. It drops the MTP of
  test_nvfp4_nixl, since offload takes no speculative decoding. The
  generation server's batch is 16: each row holds a 177.5 MiB GPU cache
  for its selected history.

Both join the 8-GPU B200 pre-merge stage in l0_dgx_b200.yml.

Signed-off-by: Guiju Zhang <[email protected]>
Conflicts:
- py_executor.py: keep both class attributes, _is_kv_manager_v2 from this
  branch and shutdown_all_ranks from main.
- py_executor_creator.py: import both create_py_executor_resources (main)
  and is_decode_only (this branch).
- test_deepseek_v4_offload.py: keep this branch's removal of the old fetch
  tests. Main's only edit there adapted them to _prepare_sparse_forward_args
  returning the forward args.
- test_py_executor_creator_mla_cache_reuse_sync.py: keep both new tests.
- test_sparse_offload_memory.py moves to tests/unittest/_torch/pyexecutor/
  kv_cache/ with main's rename of tests/unittest/_torch/executor.

Semantic conflict:
- test_optional_checkpoint.py: main's new buffer-group scratch test read
  scratch through get_scratch_desc(), which this branch removes. It now
  passes get_swa_scratch_range() and get_scratch_slots() to the converter.

Signed-off-by: Guiju Zhang <[email protected]>
@cascade812 cascade812 added the api-compatible Accepted LLM API contract change that is backwards-compatible label Oct 30, 2026
@cascade812
cascade812 force-pushed the guiju/sparse-kv-offload branch from bd4e0ff to efe1e2e Compare October 30, 2026 20:43
@cascade812
cascade812 marked this pull request as ready for review October 30, 2026 21:59
@cascade812
cascade812 requested review from a team as code owners October 30, 2026 21:59
@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83594 [ run ] completed with state SUCCESS. Commit: 60c7163
/LLM/main/L0_MergeRequest_PR pipeline #69108 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

… offload tests

- Raise NotImplementedError in DSA get_sparse_offload_descriptors when mixed-precision KV is configured; the offload path does not overlay the high-precision rows. Add a unit test.
- Move the GLM-5.2 fp8 and V4-Flash offload parity tests from l0_gb300 (pre-merge) to l0_gb300_multi_gpus (post-merge).
- Drop enable_attention_dp settings that _test_sparse_offload_long_context overrides to False.

Signed-off-by: Guiju Zhang <[email protected]>
@cascade812

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83664 [ run ] triggered by Bot. Commit: 34d4c5d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83664 [ run ] completed with state FAILURE. Commit: 34d4c5d
/LLM/main/L0_MergeRequest_PR pipeline #69179 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@cascade812

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83683 [ run ] triggered by Bot. Commit: 34d4c5d Link to invocation

Signed-off-by: Guiju Zhang <[email protected]>

# Conflicts:
#	tensorrt_llm/_torch/attention/backends/sparse/deepseek_v4/cache_manager.py
#	tensorrt_llm/_torch/pyexecutor/kv_cache/kv_cache_manager_v2.py
@cascade812

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83713 [ run ] triggered by Bot. Commit: cf50ffe Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83683 [ run ] completed with state ABORTED. Commit: 34d4c5d

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83713 [ run ] completed with state SUCCESS. Commit: cf50ffe
/LLM/main/L0_MergeRequest_PR pipeline #69224 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

… receiver changes

- Set mixed_precision_high_layers on the mocked KVCacheManagerV2, which the page-table builder now iterates.
- Expect the per-rank report token as the third argument of Receiver._request_sender_data.

Signed-off-by: Guiju Zhang <[email protected]>
@cascade812

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83887 [ run ] triggered by Bot. Commit: 7091a3c Link to invocation

@cascade812
cascade812 enabled auto-merge (squash) November 11, 2026 04:16
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83887 [ run ] completed with state SUCCESS. Commit: 7091a3c
/LLM/main/L0_MergeRequest_PR pipeline #69380 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@cascade812
cascade812 merged commit 15e973a into NVIDIA:main Nov 11, 2026
VALLIS-NERIA added a commit to VALLIS-NERIA/TensorRT-LLM that referenced this pull request Nov 11, 2026
Resolve the conflicts with main's sparse KV offload for KVCM2 (NVIDIA#21350):
- KVCacheManagerV2.__init__: main moved the guard-page, fresh-page and
  IndexMapper capacity setup ahead of the quota, as this branch did. Keep
  main's block, computing the capacity with _compute_index_mapper_capacity
  (which takes main's index-slot wording and the note that sparse cache
  leases do not follow the count), then declare the regions. The regions
  are laid out after the mixed-precision layers, before main's sparse arena
  check. _sparse_layer_group_ids goes with main's sparse support.
- Imports, module helpers, class attributes and methods: keep both sides.
- kvCacheManagerV2ConfigTest.cpp and test_kvcm2_integration.py: keep both
  sides' includes and imports.

Signed-off-by: Xiwen Yu <[email protected]>
VALLIS-NERIA added a commit to VALLIS-NERIA/TensorRT-LLM that referenced this pull request Nov 11, 2026
…ping (By Agent)

KVCacheManagerV2 reads the native manager's buffer_grouping, which split
layers need. The fakes of main's sparse KV offload tests (NVIDIA#21350) set
only layer_grouping, so the constructor failed iterating a Mock.

Signed-off-by: Xiwen Yu <[email protected]>
VALLIS-NERIA added a commit to VALLIS-NERIA/TensorRT-LLM that referenced this pull request Nov 12, 2026
…grouping (By Agent)

The disaggregation page-table builder reads the native manager's
buffer_grouping. The fake manager of main's sparse KV transfer tests
(NVIDIA#21350) set only layer_grouping.

Signed-off-by: Xiwen Yu <[email protected]>
thorjohnsen added a commit to thorjohnsen/TensorRT-LLM that referenced this pull request Nov 17, 2026
… sparse KV cache offload with copy-based rebalancing

Phase 1 of combining sparse attention KV cache offload (NVIDIA#21350) with copy-based rebalancing.

Offload keeps sparse layers' history in host-backed (pinned, device-mapped) pools that share their
pool group's slot ids, and plans that host memory once at startup. The GPU arena cannot hold them,
and resizing them would change pinned memory and stale the host plan. Instead:

- A pool group with a fixed slot count no longer lives in the arena. ArenaGpuCacheLevelStorage
  builds it as the VMM path does (GpuPoolGroup with its own allocation and slot ids from 0,
  host-backed pools included) and lays out and moves only the other ("elastic") groups. Fixed
  groups keep their windows in computePoolWindows, and the arena's move ordering
  (adjustArenaLevel, adjustArenaPools) skips them: their ids are not arena offsets. The level's
  byte counts include them; arenaBytes() is the arena alone.
- With copy-based rebalancing, StorageManager fixes every group holding a host-backed pool at the
  slot count the VMM allocator gives it at startup (the same call, so offload's host plan sees the
  same counts). The arena gets the rest of the GPU quota. If every group is fixed there is nothing
  to rebalance and the VMM storage is used.
- Main's fixed-capacity groups (RegionConfig::fixedSlotCount, NVIDIA#21324) now work with copy-based
  rebalancing too; they were rejected.
- _check_sparse_kv_offload_config allows rebalancing with copy_based_rebalancing; VMM rebalancing
  stays rejected.
- copy_based_rebalancing's description says so (schemas updated).

Tests:
- kvCacheManagerV2ArenaFixedGroupTest (new, GPU): a manager with a dense + host-backed sparse
  full-attention group and two sliding-window groups; forced rebalances move the elastic groups
  while the fixed group's windows and base addresses stay, and every block's bytes survive (dense,
  host-backed sparse, and a bound pool through its bindings); elastic windows follow the target and
  do not overlap; an all-fixed config falls back to the VMM storage. Removing either fixed-group
  skip in the move ordering fails them ("Cyclic arena window dependency").
- test_coreba_config.py: offload with rebalancing is accepted with copy_based_rebalancing and
  rejected without.

Design: CoReba worklog doc 38 (phase 1). Phase 1 does not let the dense part of a sparse-carrying
group rebalance (phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thor Johnsen <[email protected]>
thorjohnsen added a commit to thorjohnsen/TensorRT-LLM that referenced this pull request Nov 17, 2026
… sparse KV cache offload with copy-based rebalancing

Phase 1 of combining sparse attention KV cache offload (NVIDIA#21350) with copy-based rebalancing.

Offload keeps sparse layers' history in host-backed (pinned, device-mapped) pools that share their
pool group's slot ids, and plans that host memory once at startup. The GPU arena cannot hold them,
and resizing them would change pinned memory and stale the host plan. Instead:

- A pool group with a fixed slot count no longer lives in the arena. ArenaGpuCacheLevelStorage
  builds it as the VMM path does (GpuPoolGroup with its own allocation and slot ids from 0,
  host-backed pools included) and lays out and moves only the other ("elastic") groups. Fixed
  groups keep their windows in computePoolWindows, and the arena's move ordering
  (adjustArenaLevel, adjustArenaPools) skips them: their ids are not arena offsets. The level's
  byte counts include them; arenaBytes() is the arena alone.
- With copy-based rebalancing, StorageManager fixes every group holding a host-backed pool at the
  slot count the VMM allocator gives it at startup (the same call, so offload's host plan sees the
  same counts). The arena gets the rest of the GPU quota. If every group is fixed there is nothing
  to rebalance and the VMM storage is used.
- Main's fixed-capacity groups (RegionConfig::fixedSlotCount, NVIDIA#21324) now work with copy-based
  rebalancing too; they were rejected.
- _check_sparse_kv_offload_config allows rebalancing with copy_based_rebalancing; VMM rebalancing
  stays rejected.
- copy_based_rebalancing's description says so (schemas updated).

Tests:
- kvCacheManagerV2ArenaFixedGroupTest (new, GPU): a manager with a dense + host-backed sparse
  full-attention group and two sliding-window groups; forced rebalances move the elastic groups
  while the fixed group's windows and base addresses stay, and every block's bytes survive (dense,
  host-backed sparse, and a bound pool through its bindings); elastic windows follow the target and
  do not overlap; an all-fixed config falls back to the VMM storage. Removing either fixed-group
  skip in the move ordering fails them ("Cyclic arena window dependency").
- test_coreba_config.py: offload with rebalancing is accepted with copy_based_rebalancing and
  rejected without.

Design: CoReba worklog doc 38 (phase 1). Phase 1 does not let the dense part of a sparse-carrying
group rebalance (phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thor Johnsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-compatible Accepted LLM API contract change that is backwards-compatible ci: full pre-merge approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.