Commit be1309c
committed
[None][perf] kv_cache_manager_v2: batch block-key SHA-256 hashing
Hasher.update hashed each token of a block with its own int.to_bytes(8) +
sha256.update() call. For long warm prefix matches this is the dominant cost
of BlockRadixTree.match, which the attention-DP KV-cache-aware router
(KVCacheAwareADPRouter) runs as a per-request probe on every DP rank before
routing -- and which create_kv_cache repeats for the actual reuse lookup.
Pack the whole token block into bytes once (array("Q", block).tobytes()) and
do a single sha256.update(). All NVIDIA GPU host platforms (x86_64, aarch64/
Grace) are little-endian, so this is byte-identical to the per-token
to_bytes(8, "little") loop -- block reuse / cross-run cache-hit behavior is
unchanged. Multimodal blocks (which contain bytes items) fall back to the
per-token loop via except (TypeError, OverflowError).
Speeds up the probe and the create-time reuse lookup equally. On a GB300 Grace
node the real BlockRadixTree.match warm-prefix cost at ISL~38k drops 2.85-3.05x
at tokens_per_block=128/256 (DeepseekV4CacheManager). Adds TestBlockKeyHashing
to lock in the bit-identical contract incl. multi-modal blocks.
Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>1 parent e47f26e commit be1309c
2 files changed
Lines changed: 50 additions & 7 deletions
File tree
- tensorrt_llm/runtime/kv_cache_manager_v2
- tests/unittest/kv_cache_manager_v2_tests
Lines changed: 16 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
98 | 109 | | |
99 | 110 | | |
100 | 111 | | |
| |||
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
109 | 113 | | |
110 | 114 | | |
111 | 115 | | |
| |||
2556 | 2560 | | |
2557 | 2561 | | |
2558 | 2562 | | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
2559 | 2591 | | |
2560 | 2592 | | |
0 commit comments