Skip to content

Commit a028d47

Browse files
authored
fix(kv-cache): log capacity after block resolution (#1764)
Signed-off-by: AlpinDale <alpindale@gmail.com>
1 parent bcdc0e3 commit a028d47

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

aphrodite/v1/core/kv_cache_utils.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,20 @@ def get_kv_cache_capacity(aphrodite_config: AphroditeConfig, kv_cache_config: KV
17521752
return int(max_concurrency * max_model_len), max_concurrency
17531753

17541754

1755+
def update_kv_cache_capacity(aphrodite_config: AphroditeConfig, kv_cache_config: KVCacheConfig) -> None:
1756+
"""Store and log the resolved KV cache capacity."""
1757+
num_tokens, max_concurrency = get_kv_cache_capacity(aphrodite_config, kv_cache_config)
1758+
aphrodite_config.cache_config.kv_cache_size_tokens = num_tokens
1759+
aphrodite_config.cache_config.kv_cache_max_concurrency = max_concurrency
1760+
max_model_len = aphrodite_config.model_config.max_model_len
1761+
logger.info_once(
1762+
"GPU KV cache size: %s tokens, Maximum concurrency for %s tokens per request: %.2fx",
1763+
f"{num_tokens:,}",
1764+
f"{max_model_len:,}",
1765+
max_concurrency,
1766+
)
1767+
1768+
17551769
def _max_memory_usage_bytes_from_groups(
17561770
aphrodite_config: AphroditeConfig,
17571771
kv_cache_groups: list[KVCacheGroupSpec],
@@ -2055,21 +2069,6 @@ def get_kv_cache_configs(
20552069
assert tensor.size % num_blocks_old == 0
20562070
tensor.size = tensor.size // num_blocks_old * min_num_blocks
20572071

2058-
if len(kv_cache_config.kv_cache_groups) > 0:
2059-
max_model_len = aphrodite_config.model_config.max_model_len
2060-
# GPU KV cache size in tokens = max_concurrency * max_model_len:
2061-
# the total tokens of context the pool can hold at peak
2062-
# utilization. Sourcing this from the concurrency calculation
2063-
# handles hybrid layouts correctly.
2064-
num_tokens, max_concurrency = get_kv_cache_capacity(aphrodite_config, kv_cache_config)
2065-
2066-
logger.info_once("GPU KV cache size: %s tokens", f"{num_tokens:,}")
2067-
logger.info_once(
2068-
"Maximum concurrency for %s tokens per request: %.2fx",
2069-
f"{max_model_len:,}",
2070-
max_concurrency,
2071-
)
2072-
20732072
return kv_cache_configs
20742073

20752074

aphrodite/v1/engine/core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
from aphrodite.v1.core.kv_cache_utils import (
4747
BlockHash,
4848
generate_scheduler_kv_cache_config,
49-
get_kv_cache_capacity,
5049
get_kv_cache_configs,
5150
get_request_block_hasher,
5251
init_none_hash,
5352
resolve_kv_cache_block_sizes,
53+
update_kv_cache_capacity,
5454
)
5555
from aphrodite.v1.core.sched.interface import PauseState, SchedulerInterface
5656
from aphrodite.v1.core.sched.output import SchedulerOutput
@@ -287,9 +287,7 @@ def _initialize_kv_caches(self, aphrodite_config: AphroditeConfig) -> KVCacheCon
287287
kv_cache_groups = scheduler_kv_cache_config.kv_cache_groups
288288
if kv_cache_groups:
289289
aphrodite_config.cache_config.block_size = min(g.kv_cache_spec.block_size for g in kv_cache_groups)
290-
num_tokens, max_concurrency = get_kv_cache_capacity(aphrodite_config, scheduler_kv_cache_config)
291-
aphrodite_config.cache_config.kv_cache_size_tokens = num_tokens
292-
aphrodite_config.cache_config.kv_cache_max_concurrency = max_concurrency
290+
update_kv_cache_capacity(aphrodite_config, scheduler_kv_cache_config)
293291

294292
aphrodite_config.validate_block_size()
295293

0 commit comments

Comments
 (0)