Skip to content

Commit c34bd25

Browse files
kmbandyclaude
andcommitted
feat: --kv-warm-device CLI flag + set_warm_elem_bytes wiring
Adds --kv-warm-device <N> flag (env: LLAMA_ARG_KV_WARM_DEVICE) to specify a HIP device index for the warm KV cache tier. Wires through common_params into llama_tier_config.warm_device and calls set_warm_elem_bytes() before init() so hipMalloc sizing is correct. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d4ce1af commit c34bd25

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

common/arg.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
13581358
params.kv_tier_attention_threshold = float(value) / 100.0f;
13591359
}
13601360
).set_env("LLAMA_ARG_TIER_ATTENTION_THRESHOLD").set_examples({LLAMA_EXAMPLE_SERVER}));
1361+
add_opt(common_arg(
1362+
{"--kv-warm-device"}, "DEVICE",
1363+
"HIP device index to use as warm KV cache tier (e.g. 1 for 6900XT eGPU); requires --kv-tiered",
1364+
[](common_params & params, int value) {
1365+
params.kv_warm_device = value;
1366+
}
1367+
).set_env("LLAMA_ARG_KV_WARM_DEVICE").set_examples({LLAMA_EXAMPLE_SERVER}));
13611368
add_opt(common_arg(
13621369
{"-kvu", "--kv-unified"},
13631370
{"-no-kvu", "--no-kv-unified"},

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ struct common_params {
582582
int kv_tier_eviction_policy = 3; // 0=LRU, 1=LFU, 2=attention, 3=hybrid (default)
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
585+
int kv_warm_device = -1; // HIP device index for warm KV tier (-1 = disabled)
585586

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

src/llama-kv-cache-tiered.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ class llama_kv_cache_tiered {
182182
bool resize(uint32_t new_total_ctx);
183183
bool set_eviction_policy(llama_eviction_policy policy);
184184
bool set_attention_threshold(float threshold);
185+
#ifdef GGML_USE_HIP
185186
void set_warm_elem_bytes(size_t n) { warm_elem_bytes = n; }
187+
#else
188+
void set_warm_elem_bytes(size_t) {}
189+
#endif
186190

187191
// Eviction interface
188192
bool evict_tokens(uint32_t n_tokens_to_evict, llama_cache_tier from_tier);

tools/server/server-tiered-cache.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bool server_tiered_cache::init_slot(int slot_id, const llama_model& model) {
6161
config.warm_percent = params.kv_tier_warm_pct;
6262
config.cold_percent = params.kv_tier_cold_pct;
6363
config.total_ctx = params.n_ctx;
64+
config.warm_device = params.kv_warm_device;
6465

6566
// Create tiered cache instance
6667
manager.tiered_cache = std::make_unique<llama_kv_cache_tiered>(
@@ -72,6 +73,14 @@ bool server_tiered_cache::init_slot(int slot_id, const llama_model& model) {
7273
attention_threshold
7374
);
7475

76+
// set bytes-per-token for warm device hipMalloc sizing
77+
if (params.kv_warm_device >= 0) {
78+
int32_t n_kv_heads = llama_model_n_head_kv(&model);
79+
int32_t head_dim = llama_model_n_embd(&model) / llama_model_n_head(&model);
80+
manager.tiered_cache->set_warm_elem_bytes(
81+
(size_t)n_kv_heads * head_dim * sizeof(ggml_fp16_t));
82+
}
83+
7584
// Initialize the tiered cache
7685
if (!manager.tiered_cache->init()) {
7786
return false;

0 commit comments

Comments
 (0)