Skip to content

Commit 2b511ae

Browse files
committed
Fix GenAI regression: disable past_present_share_buffer for dual head_dim
Models with different head_dim across layers (e.g., Gemma4 with head_dim=256 for sliding and global_head_dim=512 for full-attention) cannot use shared KV buffers. Dynamically detect dual head_dim from config and set past_present_share_buffer=false. Implementation: - GenaiConfigGenerator: add _search_overrides dict applied in generate() - auto_export: check config.global_head_dim != config.head_dim 134 tests pass (15 gemma4 + 119 ort_genai). Signed-off-by: Justin Chu <justinchu@microsoft.com>
1 parent f027a8e commit 2b511ae

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/mobius/integrations/ort_genai/auto_export.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ def _write_genai_config(
655655
**audio_kwargs,
656656
)
657657

658+
# Disable past_present_share_buffer for models with dual head_dim
659+
# (e.g., different head_dim for sliding vs full-attention layers).
660+
# Shared buffers require uniform head_dim across all KV cache layers.
661+
global_head_dim = getattr(config, "global_head_dim", None)
662+
head_dim = getattr(config, "head_dim", None)
663+
if global_head_dim and head_dim and global_head_dim != head_dim:
664+
generator._search_overrides["past_present_share_buffer"] = False
665+
658666
return generator.write(output_dir)
659667

660668

src/mobius/integrations/ort_genai/genai_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def __init__(
178178
# Optional audio fields (set via with_audio())
179179
self._audio: dict[str, Any] | None = None
180180

181+
# Search config overrides applied in generate()
182+
self._search_overrides: dict[str, Any] = {}
183+
181184
@classmethod
182185
def from_config(
183186
cls,
@@ -407,9 +410,12 @@ def generate(self) -> dict[str, Any]:
407410
model["speech"] = self._audio
408411
model.update(self._vlm_token_ids)
409412

413+
search = _default_search_params(ep=self.ep, context_length=self.context_length)
414+
search.update(self._search_overrides)
415+
410416
return {
411417
"model": model,
412-
"search": _default_search_params(ep=self.ep, context_length=self.context_length),
418+
"search": search,
413419
}
414420

415421
def write(self, output_dir: str) -> str:

0 commit comments

Comments
 (0)