Repository navigation
convert: fold gemma4 audio projection scaling into the weight reparam - #723
Merged
Merged
Conversation
The gemma4 audio soft-token 1/16 scaling lived in the transpile graph (_gemma4_compute_native_like_audio_features) while the equivalent vision scaling lived in the conversion-time weight reparam. The audio embedder projection is a bias-free Linear with no post-projection norm, so scaling its weight is identical to scaling its output. Add embed_audio_proj to the gemma4 div set and drop the runtime multiply so all multimodal projection scaling is applied in one place, matching vision. Verified by E2E: e2b transcribes test.wav cleanly and identifies the monkey image. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
gemma4's Gemma4MultimodalEmbedder deletes the hard embedding table, so no embed_vision_embedding.weights tensor is ever produced. Remove the name from the gemma4 div set in tensor_io.py and from GEMMA4_DIV_BASENAMES; both were no-ops. The real vision weight (embed_vision_proj) stays scaled. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
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
The gemma4 audio soft-token
1/16scaling was applied at runtime in the transpile graph (_gemma4_compute_native_like_audio_features), while the equivalent vision projection scaling is applied at conversion time via the weight reparameterization. This split meant the same conceptual operation lived in two different stages depending on modality.This change consolidates both into the conversion-time weight reparam:
embed_audio_proj.weightsis added to the gemma4÷16set intensor_io.py.projected = projected * (1.0 / 16.0)is removed from the audio path inmodel_adapters.py.Why this is equivalent
The gemma4 audio embedder projection (
embedding_projection) is a bias-freenn.Linearpreceded by a scale-less pre-norm, with the post-projection norm removed in gemma4. Because the projection is the last operation and has no bias, scaling its weight by1/16is mathematically identical to scaling its output by1/16. Audio now follows the exact pattern vision already uses.Verification
Reconverted and retranspiled gemma-4-e2b, then ran E2E:
test.wavtranscribes cleanly ("Hello hello hello quickly testing out getting a way file through voice memos").