Skip to content

[TRTLLM-12317][feat] Match V1 KV event hashes for V2 cache events - #13624

Merged
peihu-nv merged 1 commit into
NVIDIA:feat/deepseek_v4from
peihu-nv:review/pr-13589-v1-hash-fix
Apr 30, 2026
Merged

[TRTLLM-12317][feat] Match V1 KV event hashes for V2 cache events#13624
peihu-nv merged 1 commit into
NVIDIA:feat/deepseek_v4from
peihu-nv:review/pr-13589-v1-hash-fix

Conversation

@peihu-nv

@peihu-nv peihu-nv commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

This PR is stacked on top of #13589 and tightens KV cache event hash compatibility for Dynamo to support DeepSeek V4. It makes V2 KV cache events use the V1 BlockKeyHasher contract by default through kv_cache_event_hash_algo = auto, including parent chaining, LoRA task ID, and cache salt ID. This lets Dynamo consume V2 KV cache events without changing its hash expectations or adding a new config override.

Dynamo currently consumes V1-style KV event block hashes. Without this compatibility path, enabling V2 KV cache events would require Dynamo-side hash changes or could produce mismatched routing/cache state. Matching V1 hashes for supported text-token blocks, including salted cache namespaces, lets #13589 land with lower integration risk. Native V2 hashes remain available as explicit opt-in via v2_sha256 or v2_sha256_64.

Changes:

  • Add a Python implementation of the V1 block-key hash for text-token V2 radix blocks.
  • Make kv_cache_event_hash_algo = auto resolve to v1_block_key for V2 KV cache events.
  • Add cache salt support to V2 KV event hashing and cache-aware routing.
  • Plumb cache_salt_id through request handling, V2 cache creation, root blocks, and event hash generation.
  • Preserve V1 hash semantics for parent chaining, LoRA task ID, and cache salt ID.
  • Fall back to the existing V2 SHA256-derived hash for non-text-token blocks.
  • Disambiguate V2 root keys by tagging LoRA and cache-salt fields.
  • Add parity tests against the C++ V1 hasher and real V1/V2 manager event output.

Test Coverage

  • Focused hash/router unit tests: 7 passed
  • Previously failing test_llm_kv_cache_events.py cases: 4 passed
  • Disaggregated worker integration test file: 4 passed, 2 skipped

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)

  • 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.

@peihu-nv
peihu-nv force-pushed the review/pr-13589-v1-hash-fix branch from 11407fd to 282568c Compare April 29, 2026 23:34
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
@peihu-nv
peihu-nv force-pushed the review/pr-13589-v1-hash-fix branch from 282568c to c9d6d9a Compare April 30, 2026 16:08
@peihu-nv
peihu-nv marked this pull request as ready for review April 30, 2026 17:26
@peihu-nv
peihu-nv requested review from a team as code owners April 30, 2026 17:26
@peihu-nv
peihu-nv requested review from mikeiovine and removed request for a team April 30, 2026 17:26
@schetlur-nv
schetlur-nv requested a review from pcastonguay April 30, 2026 17:33
@peihu-nv
peihu-nv merged commit 4999884 into NVIDIA:feat/deepseek_v4 Apr 30, 2026
4 checks passed
lfr-0531 pushed a commit that referenced this pull request May 7, 2026
…3624)

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
lfr-0531 pushed a commit that referenced this pull request May 14, 2026
…3624)

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
zheyuf added a commit to zheyuf/TensorRT-LLM that referenced this pull request May 30, 2026
…k hashing

The disaggregated orchestrator computes KV-cache block hashes per request for prefix-/conversation-aware routing. hash_v1_block_key is a pure-Python per-token loop; for long prompts (~38k tokens) it dominates the single asyncio event loop's CPU (py-spy: ~89% of one saturated core) and, being GIL-bound, serializes concurrent requests, so TTFT degrades super-linearly with concurrency.

Route block_key_hasher's common path (cache_salt_id is None) to the existing nanobind-exposed C++ BlockKeyHasher, which implements the identical algorithm, removing the per-token Python loop from the orchestrator hot path. Bit-exact with hash_v1_block_key (verified 550/550 incl. the chained per-block pattern), no new dependency. Falls back to the Python implementation only when a cache_salt_id is set (the C++ hash() binding takes no salt) -- which does not occur on the unsalted agent/chat completion path.

Only the serve router's routing-time hashing is changed; the worker-side KV-cache event hashing that Dynamo consumes (kept V1-compatible by NVIDIA#13624) is untouched, so the V1 hash contract is preserved.

Impact (DSv4-Pro 1P1D disagg, GB300, AgentPerf-V2): c128 TTFT p95 3.74s, within SLO60 (p95<5s); c256 p95 26.5s -> 9.5s; orchestrator event-loop core de-saturated.

Signed-off-by: Zheyu Fu <zheyuf@nvidia.com>
zheyuf added a commit to zheyuf/TensorRT-LLM that referenced this pull request May 30, 2026
…k hashing

The disaggregated orchestrator computes KV-cache block hashes per request for prefix-/conversation-aware routing. hash_v1_block_key is a pure-Python per-token loop; for long prompts (~39k tokens) it dominates the single asyncio event loop's CPU (py-spy: ~89% of one saturated core) and, being GIL-bound, serializes concurrent requests, so TTFT degrades super-linearly with concurrency.

Route block_key_hasher's common path (cache_salt_id is None) to the existing nanobind-exposed C++ BlockKeyHasher, which implements the identical algorithm, removing the per-token Python loop from the orchestrator hot path. Bit-exact with hash_v1_block_key (verified 550/550 incl. the chained per-block pattern), no new dependency. Falls back to the Python implementation only when a cache_salt_id is set (the C++ hash() binding takes no salt) -- which does not occur on the unsalted agent/chat completion path.

Only the serve router's routing-time hashing is changed; the worker-side KV-cache event hashing that Dynamo consumes (kept V1-compatible by NVIDIA#13624) is untouched, so the V1 hash contract is preserved.

Impact (DSv4-Pro 1P1D disagg, DEP8, GB300, AgentPerf-V2): c128 TTFT p95 10.71s -> 3.13s (-71%), throughput +50%, req/s +63% at fixed concurrency; SLO60 ceiling (p95<=5s and SSE p25>=60 tok/s) ~c80 -> c160 (~5 -> 10 users/GPU). Post-fix the bottleneck shifts to prefill queueing (ctx_queue), not the orchestrator.

Signed-off-by: Zheyu Fu <zheyuf@nvidia.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
…IDIA#13624)

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 11, 2026
…IDIA#13624)

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
…IDIA#13624)

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants