Skip to content

Fix Gemma4 RoPE handling - #1293

Draft
nsivalin wants to merge 1 commit into
quic:release/v1.22.8.0from
nsivalin:gemma4_rope_fix
Draft

nsivalin wants to merge 1 commit into
quic:release/v1.22.8.0from
nsivalin:gemma4_rope_fix

Conversation

@nsivalin

Copy link
Copy Markdown
Contributor

Gemma4 was the only QEff model still using HF’s runtime rotary embeddings, recomputing RoPE cos/sin via Cos/Sin ops on every forward pass. This caused the computations to be repeatedly traced into the exported ONNX graph across decoder and vision-encoder layers, triggering a compiler tensor-aliasing issue.
The fix introduces QEffGemma4TextRotaryEmbedding and QEffGemma4VisionRotaryEmbedding, which precompute static cos/sin tables during initialization. As a result, forward() now performs a simple Gather, aligning Gemma4 with the implementation pattern used by all other QEff models and eliminating the decode corruption issue.

@vbaddi

vbaddi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@ochougul @quic-rishinr do we need this?

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