Add kv_cache_fixed_to_max_length search option (AMD RyzenAI) - #2156
Add kv_cache_fixed_to_max_length search option (AMD RyzenAI)#2156Oleksandr Kholodnyi (akholodnamdcom) wants to merge 2 commits into
kv_cache_fixed_to_max_length search option (AMD RyzenAI)#2156Conversation
AMD RyzenAI models with a fixed-size kv-cache require max_length to be pinned to the value in genai_config.json. The new search option is independent of past_present_share_buffer; both must be set explicitly when the model needs them. When enabled, runtime overrides of max_length via SetSearchNumber that change the value are dropped with a warning; same-value sets are silent no-ops. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
|
Baiju Meswani (@baijumeswani) kunal-vaishnavi could you please take a look at the fix |
There was a problem hiding this comment.
Pull request overview
Adds a new model configuration flag to represent a hardware constraint (AMD RyzenAI) where the KV-cache must remain allocated at the genai_config.json max_length, and updates runtime search-option overrides to preserve that invariant.
Changes:
- Adds
search.kv_cache_fixed_to_max_lengthtoConfig::Searchand parses it fromgenai_config.json. - Updates
SetSearchNumberto ignore runtimemax_lengthoverrides whenkv_cache_fixed_to_max_lengthis enabled (with a warning on differing values).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/config.h |
Adds the kv_cache_fixed_to_max_length flag to the search config struct. |
src/config.cpp |
Parses the new JSON key and adds a guard to drop incompatible runtime max_length overrides. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
This pull-request introduces a new config setting
Here are some alternative proposals:
|
|
Closing in favor of #2166 |
Summary
Adds a new
kv_cache_fixed_to_max_lengthboolean to thesearchsection ofgenai_config.json. Some AMD RyzenAI models require the kv-cache to be allocated as a fixed buffer sized tomax_length; this option marks the model as having that constraint so OGA can preserve theinvariant at runtime.
Behavior
kv_cache_fixed_to_max_lengthis true, runtime overrides ofmax_lengthviaOgaGeneratorParamsSetSearchNumber(and equivalents in C#/Python/Java/Objective-C) that would change the value are dropped with a yellowwarninglog entry, preserving the pre-sized buffer.Why a warning instead of an error
Throwing on every override would break clients that pass
max_lengththrough defensively (e.g.model_benchmark's--max_lengthflag, which is set by default toprompt_length + generation_length). Logging a warning and ignoring the override keeps existing tools workingwhile still surfacing that the value was not applied.
Files changed
src/config.h— newbool kv_cache_fixed_to_max_length{}field at the end ofConfig::Search.src/config.cpp— JSON parser branch for the new key (last in the chain, before the unknown-key throw), and a guard at the top ofSetSearchNumberthat warns and drops differingmax_lengthoverrides.Test plan
model_benchmark -ml 1024withkv_cache_fixed_to_max_length: trueandmax_length: 131072ingenai_config.json→ warning printed, benchmark runs withmax_length=131072.model_benchmark -ml 131072(matches config) → no warning, benchmark runs.model_benchmark -ml -1(no override call) → no warning, benchmark runs.Llama-3.2-1B-Instruct(Q4F16).Sample warning output: