add t5gemma2 adapter and tests#1495
Open
zinichakraborty wants to merge 3 commits into
Open
Conversation
# Conflicts: # transformer_lens/tools/model_registry/data/supported_models.json # transformer_lens/tools/model_registry/data/verification_history.json
# Conflicts: # transformer_lens/tools/model_registry/data/verification_history.json
Author
|
@jlarson4 ready for review whenever! I followed the T5Gemma adapter implementation from #1433. One design note: I added a dedicated t5gemma2_merged_attention component since T5Gemma2 fuses self- and cross-attention into a single module, but happy to restructure if you'd prefer extending an existing attention bridge. |
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.
Description
Adds a TransformerBridge architecture adapter for T5Gemma2 (
T5Gemma2ForConditionalGeneration), Google's multimodal encoder-decoder follow-up to T5Gemma. The adapter bridges the text path only (the SigLIP vision tower and multi-modal projector are intentionally left unmapped).Key architectural differences from the existing T5Gemma adapter, each reflecting a real change in the HF model:
T5Gemma2MergedAttentionwith shared q/k/v/o projections and one softmax over concatenated decoder+encoder keys. A newT5Gemma2MergedAttentionBridgedelegates the math to the native module and exposes both pattern slices —hook_pattern(self) and a newhook_cross_pattern(cross). The decoder block has no separatecross_attnmodule, no cross-attention layernorms, and a singlehook_resid_mid.model.encoder.text_model.*.q_norm/k_norm) in every attention module, mapped and folded with the +1 RMSNorm offset.lm_head.out_proj(T5Gemma2LMHeadwrapper).Registered in all four sites (factory, sources, registry, seq2seq classification) and added
google/t5gemma-2-270m-270mto the model registry.Verification (
verify_modelsongoogle/t5gemma-2-270m-270m):Phase 1 = 100% (all 475 components), Phase 2 = 100% (logit + loss parity),
Phase 4 = 87 — status VERIFIED. Bridge-vs-HF logit max diff is exactly 0.0.
Tests added:
tests/unit/model_bridge/supported_architectures/test_t5gemma2_adapter.py: structural adapter tests (config flags, component mapping, key translation, conversion-table alignment, registration); no weight loads.tests/integration/model_bridge/test_t5gemma2_adapter.py: 17 tests on a tiny random T5Gemma2 built from config (no Hub download, CI-safe): boot, exact HF logit parity, HF delegation identity, hook shapes, merged-softmax semantics (self + cross pattern rows jointly sum to 1), per-head QK-norm.Local runs:
make test-prtiers all pass (unit, docstring, acceptance, integration),uv run mypy .clean,make formatapplied.Fixes #1454
Type of change
Screenshots
N/A
Checklist: