Repository navigation
Conversation
Yu-Haikuo
force-pushed
the
fix/gemma3n-no-cache-kv-sharing
branch
from
October 22, 2026 16:43
a11bc5f to
2d2ca67
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #1674, where Gemma 3n’s KV-shared layers previously computed their own keys and values when no cache was provided, causing paths such as LoRA training, perplexity, and quantization calibration to differ from cached generation.
The fix passes the source layer’s keys and values directly to shared layers, making KV sharing consistent with or without a cache.
Also crediting #1702 for earlier work.
How to Reproduce
Scripts
Both scripts use small models with fixed-seed random weights, so no model download is required.
reproduce_gemma3n_kv_sharing_bug.py
check_gemma3n_cached_output_unchanged.py
reproduce_gemma3n_kv_sharing_bug.py0. The sharing-disabled control is already0.check_gemma3n_cached_output_unchanged.pyHow to Verify
Please run the below commands on this fix branch and
mainbranch:Results
Before the Fix
After the Fix
Environment
AI Disclose