Skip to content

Add Gemma 3 and 4 compatibility#4

Open
jammastergirish wants to merge 1 commit into
safety-research:masterfrom
jammastergirish:gemma4-compat
Open

Add Gemma 3 and 4 compatibility#4
jammastergirish wants to merge 1 commit into
safety-research:masterfrom
jammastergirish:gemma4-compat

Conversation

@jammastergirish

@jammastergirish jammastergirish commented Apr 5, 2026

Copy link
Copy Markdown

Summary

  • Add model.model.language_model.layers path to ProbingModel.get_layers() and ActivationSteering._POSSIBLE_LAYER_ATTRS for Gemma 4's Gemma4ForConditionalGeneration architecture
  • Add text_config fallback for hidden_size (Gemma 4 nests it under text_config)
  • Add _ensure_id_list() helper to ConversationEncoder to handle apply_chat_template returning BatchEncoding instead of list[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.

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>
@jammastergirish jammastergirish changed the title Add Gemma 4 compatibility Add Gemma 3 and 4 compatibility Apr 11, 2026
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.

1 participant