Gemma 4#108
Open
SamuelMarks wants to merge 1 commit into
Open
Conversation
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.
Add support for Gemma 4 Multimodal Architecture
Following the resounding success of jax-ml/bonsai#175 [JAX] I give this other Google repo Gemma 4!
Description
This PR introduces the complete implementation of the Gemma 4 architecture. It brings robust support for multimodality—specifically advanced audio and vision capabilities—along with an extensive suite of tests and updated inference scripts.
Key Changes
🧠 Core Architecture (
gemma/gemma4/)attention.py,rope.py,moe.py,cache.py,decoder_layer.py, andmodeling.py.vision.pyfor processing visual features in the Gemma 4 architecture.gemma4_model.pyandgemma4_multimodal.pyfor cohesive model instantiation and multimodal routing.🎧 Audio Capabilities (
gemma/gemma4_audio/)audio_model.py,audio_attention.py, andaudio_layers.pyto seamlessly project and attend over audio modalities.⚙️ Integration & Refactoring
gemma/__init__.py,gemma/config.py,gemma/model.py, andgemma/tokenizer.pyto support new Gemma 4 configs and routing.gemma/gemma3_model.pyto integrate cleanly alongside the new abstractions.🛠 Scripts & Utilities
scripts/convert_gemma4_weights.pyto facilitate migrating or preparing checkpoint weights.scripts/run_multimodal.pyto supportGemma4ConfigandGemma4ForCausalLM, allowing users to quickly run multimodal inference using Gemma 4 checkpoints.✅ Testing
tests/gemma4/verifyingattention,audio,cache,config,decoder_layer,layers,modeling,moe,rope, andvision.tests/test_gemma4_attention.pyandtests/test_gemma4_moe.pytesting modules.tests/test_workflow_scripts.pyto ensure end-to-end script reliability.Testing Instructions
pytest tests/gemma4/python scripts/run_multimodal.py --ckpt <path_to_gemma4_checkpoint> --variant 4b