Skip to content

Fix Gemma4 GenAI regression: disable past_present_share_buffer for dual head_dim - #274

Merged
justinchuby merged 1 commit into
mainfrom
fix-attention-bias-dtype
May 6, 2026
Merged

Fix Gemma4 GenAI regression: disable past_present_share_buffer for dual head_dim#274
justinchuby merged 1 commit into
mainfrom
fix-attention-bias-dtype

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

Fix CPU regression where Gemma4 GenAI generation fails with:

inconsistent total_sequence_length (between attn_mask and past_key and past_value)

Root Cause

past_present_share_buffer was set to true in genai_config.json because the default EP maps to cpu (which has supports_past_present_share_buffer=True). However, Gemma4 has dual head_dim (256 for sliding-window, 512 for full-attention), and shared buffers require uniform head_dim across all KV cache layers.

Fix

Force past_present_share_buffer=false in genai_config.json for all Gemma4 model types.

Testing

  • 15 gemma4 tests pass
  • 119 ort_genai tests pass
  • Verified: Gemma4 CPU generation produces correct output with the fix

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing f027a8e2b511ae

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing f027a8e2b511ae

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 53 53 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 61 61 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 59 59 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 61 61 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/integrations/ort_genai/auto_export.py 50.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…_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>
@justinchuby
justinchuby force-pushed the fix-attention-bias-dtype branch from c531042 to 2b511ae Compare May 6, 2026 16:01
@justinchuby
justinchuby requested a review from rui-ren May 6, 2026 16:38
@rui-ren

rui-ren commented May 6, 2026

Copy link
Copy Markdown
Contributor

👍

@justinchuby
justinchuby merged commit 2183a84 into main May 6, 2026
22 of 23 checks passed
@justinchuby
justinchuby deleted the fix-attention-bias-dtype branch May 6, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants