Skip to content

Commit a9280d1

Browse files
kmbandyclaude
andcommitted
fix: scale hot KV allocation to hot_pct of total ctx
The tiered cache percentages define hard capacity limits per tier that sum to the full ctx budget. Previously the R9700 KV buffer was still allocated at full n_ctx despite the hot tier being only a fraction. - Add kv_tier_total_ctx to common_params to preserve the full budget - Before common_init_from_params, reduce n_ctx to hot_pct * n_ctx so the GPU KV buffer only allocates for the hot tier - server-tiered-cache.cpp uses kv_tier_total_ctx for config.total_ctx so warm/cold capacity calculations remain correct Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f90365a commit a9280d1

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ struct common_params {
583583
int kv_tier_compression = 1; // 0=none, 1=int4, 2=int8, 3=lz4, 4=quantized
584584
float kv_tier_attention_threshold = 0.1f; // attention threshold for eviction
585585
int kv_warm_device = -1; // HIP device index for warm KV tier (-1 = disabled)
586+
int kv_tier_total_ctx = 0; // full ctx budget across all tiers (set at load time)
586587

587588
std::string hostname = "127.0.0.1";
588589
std::string public_path = ""; // NOLINT

tools/server/server-context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ struct server_context_impl {
750750
SRV_INF("loading model '%s'\n", params.model.path.c_str());
751751

752752
params_base = params;
753+
if (params_base.kv_tiered_enabled && params_base.kv_tier_hot_pct > 0.0f && params_base.kv_tier_hot_pct < 100.0f) {
754+
params_base.kv_tier_total_ctx = params_base.n_ctx;
755+
params_base.n_ctx = std::max(512, (int)(params_base.n_ctx * params_base.kv_tier_hot_pct / 100.0f));
756+
SRV_INF("tiered KV: total ctx=%d, hot ctx=%d (%.0f%%)\n", params_base.kv_tier_total_ctx, params_base.n_ctx, params_base.kv_tier_hot_pct);
757+
}
753758

754759
llama_init = common_init_from_params(params_base);
755760

tools/server/server-tiered-cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool server_tiered_cache::init_slot(int slot_id, const llama_model& model) {
6060
config.hot_percent = params.kv_tier_hot_pct;
6161
config.warm_percent = params.kv_tier_warm_pct;
6262
config.cold_percent = params.kv_tier_cold_pct;
63-
config.total_ctx = params.n_ctx;
63+
config.total_ctx = params.kv_tier_total_ctx > 0 ? params.kv_tier_total_ctx : params.n_ctx;
6464
config.warm_device = params.kv_warm_device;
6565

6666
// Create tiered cache instance

0 commit comments

Comments
 (0)