Skip to content

Address PR #239 follow-up: GQA limit, GGUF k_eq_v, DRY expert rename, tests - #240

Merged
justinchuby merged 2 commits into
mainfrom
pr239-followup
May 4, 2026
Merged

Address PR #239 follow-up: GQA limit, GGUF k_eq_v, DRY expert rename, tests#240
justinchuby merged 2 commits into
mainfrom
pr239-followup

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Addresses 4 review comments from PR #239:

1. GQA rewrite rule head_dim limit (#1)

Updated _MAX_GQA_HEAD_DIM from 256 to 512 in the Attention→GQA rewrite rule to match latest ORT support for head_dim=512.

2. GGUF path missing attention_k_eq_v (#2)

Added attention_k_eq_v=True to Gemma4 GGUF postprocessor when num_global_key_value_heads is detected. Fixes build_from_gguf() for 26b-a4b/31b checkpoints.

3. DRY expert weight rename (#3)

Extracted _remap_moe_expert_weights() shared helper used by both Gemma4CausalLMModel.preprocess_weights() and Gemma4Model.preprocess_weights(). Single source of truth for expert rename + router scale folding.

4. Missing multimodal preprocess_weights test (#4)

Added gemma4_test.py with 5 targeted tests covering both Gemma4CausalLMModel and Gemma4Model weight preprocessing: expert rename, router scale folding, and per_expert_scale passthrough.

Testing

  • 5/5 new preprocess_weights tests pass
  • 2668/2668 full suite pass

1. Update GQA rewrite rule MAX_HEAD_DIM from 256 to 512 — latest ORT
   supports head_dim=512 for Gemma4 full-attention layers
2. Set attention_k_eq_v in GGUF postprocessor when num_global_key_value_heads
   differs from num_key_value_heads, fixing build_from_gguf for 26b/31b
3. Extract _remap_moe_expert_weights() shared helper to avoid duplicating
   expert rename + router scale folding in CausalLM and multimodal paths
4. Add targeted preprocess_weights tests for both Gemma4CausalLMModel
   and Gemma4Model (multimodal)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 353dcdf8cee3d6

Model Sub-model Changes Status
gemma4 (gemma4) decoder 0
gemma4 (gemma4) embedding 0
gemma4 (gemma4) vision_encoder 0
gemma4_text model 0

No architecture changes detected.


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

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 353dcdf8cee3d6

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 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses follow-ups from PR #239 across optimization rewrite rules, GGUF config extraction, Gemma4 weight preprocessing, and adds targeted unit tests to prevent regressions.

Changes:

  • Increase the Attention→GroupQueryAttention rewrite rule’s head-dim limit from 256 to 512.
  • Set attention_k_eq_v in the Gemma4 GGUF config postprocessor when num_global_key_value_heads is detected.
  • DRY Gemma4 MoE weight preprocessing by extracting a shared _remap_moe_expert_weights() helper and add new preprocess_weights tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/mobius/rewrite_rules/_group_query_attention.py Raises _MAX_GQA_HEAD_DIM to allow GQA fusion for larger head dims (now 512).
src/mobius/integrations/gguf/_config_mapping.py Infers attention_k_eq_v from GGUF-derived per-layer KV head metadata for Gemma4.
src/mobius/models/gemma4.py Extracts shared MoE expert rename + router scale folding helper used by both Gemma4 preprocess paths.
src/mobius/models/gemma4_test.py Adds unit tests validating expert-weight renames and router scale folding behavior for Gemma4 models.

Comment thread src/mobius/rewrite_rules/_group_query_attention.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby merged commit d39b13b into main May 4, 2026
5 checks passed
@justinchuby
justinchuby deleted the pr239-followup branch May 4, 2026 18:12
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