Add Gemma 3 and 4 compatibility#4
Open
jammastergirish wants to merge 1 commit into
Open
Conversation
Gemma 4 uses a multimodal architecture that differs from earlier Gemma models: - Transformer layers are at model.model.language_model.layers - hidden_size is nested under text_config, not top-level config - apply_chat_template returns BatchEncoding instead of list[int] These changes add fallback paths for all three cases while preserving backwards compatibility with existing models (Gemma 2, Llama, Qwen, etc.). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jammastergirish
added a commit
to jacobdaviescam/steering_across_personas
that referenced
this pull request
Apr 5, 2026
Point setup instructions at jammastergirish/assistant-axis fork (gemma4-compat branch) which adds compatibility for Gemma 4's Gemma4ForConditionalGeneration architecture. Upstream PR: safety-research/assistant-axis#4 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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
model.model.language_model.layerspath toProbingModel.get_layers()andActivationSteering._POSSIBLE_LAYER_ATTRSfor Gemma 4'sGemma4ForConditionalGenerationarchitecturetext_configfallback forhidden_size(Gemma 4 nests it undertext_config)_ensure_id_list()helper toConversationEncoderto handleapply_chat_templatereturningBatchEncodinginstead oflist[int](affects Gemma 4 and newer transformers versions)All changes are backwards-compatible. Existing models (Gemma 2, Llama, Qwen) hit the same code paths as before.