Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates the T5Gemma2 model into the Keras Hub, providing a more advanced and versatile encoder-decoder architecture. The new model leverages the Gemma 3 framework, featuring innovations like merged attention and tied embeddings to enhance efficiency and performance. Its native multimodal capabilities and expanded context window significantly broaden its application scope compared to previous versions, enabling more complex and diverse tasks. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the T5Gemma2 model, a significant and well-structured contribution that aligns with the repository's modular design. The implementation correctly follows naming conventions and architectural patterns.
However, there are several critical issues to address:
- Missing Tests: A number of new modules (
t5gemma2_tokenizer,t5gemma2_seq_2_seq_lm_preprocessor,t5gemma2_attention,t5gemma2_decoder,t5gemma2_encoder,t5gemma2_layers) are missing their corresponding test files (_test.py). This is a violation of the repository's testing requirements (Style Guide, line 406) and is critical for ensuring code quality and correctness. - Unrunnable Examples: The docstring examples for
T5Gemma2TokenizerandT5Gemma2Seq2SeqLMuse a preset that is not yet available, which will lead to errors for users. The examples should be updated to be runnable or clearly marked as placeholders. - PR Description Discrepancy: The description mentions that
T5Gemma2is natively multimodal with a vision encoder, but the current implementation appears to be text-only. It would be helpful to clarify this in the description.
Please address the missing tests and unrunnable examples to finalize this contribution.
…ltimodel variants
|
can you please address the gemini review comments and once does, please resolve the comments you have addressed |
Those are related to test files creating and are not required. Included necessary test files to cover the code. Thanks |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the T5Gemma2 model, a significant architectural update from T5Gemma1, featuring merged attention and multimodal capabilities. The implementation is comprehensive, including the backbone, task model, preprocessor, tokenizer, and a detailed checkpoint conversion script with numerical verification. The code is well-structured and adheres to the repository's patterns.
However, the pull request is missing the required Colab notebooks for numerical validation, as specified in the repository's contribution guidelines (rule #516). Please add links to Colabs demonstrating numerical equivalence for the backbone, preprocessor, and the end-to-end task model against the original implementation.
I have also found one potential correctness issue in the decoder's sliding window attention implementation, which I've detailed in a specific comment.
| sliding_mask = ( | ||
| q_indices[:, None] - self.sliding_window | ||
| ) <= kv_indices[None, :] |
There was a problem hiding this comment.
The implementation of the causal sliding window mask appears to be off by one. The current condition (q_indices[:, None] - self.sliding_window) <= kv_indices[None, :] creates a window of size self.sliding_window + 1, as it allows a token to attend to self.sliding_window previous tokens plus itself.
To ensure the window size is exactly self.sliding_window, the condition should be adjusted.
| sliding_mask = ( | |
| q_indices[:, None] - self.sliding_window | |
| ) <= kv_indices[None, :] | |
| sliding_mask = ( | |
| q_indices[:, None] - (self.sliding_window - 1) | |
| ) <= kv_indices[None, :] |
References
- Your goal is to critically test the logic. Actively search for and point out failing edge cases, race conditions, or unhandled exceptions in the implementation.
Description of the change
This model implementation is reference to the issue #2613
Foundation Model: T5Gemma 1 is based on the Gemma 2 framework, whereas T5Gemma 2 is built using the Gemma 3 architecture.
Tied Embeddings: Unlike the original T5Gemma, which uses separate word embeddings for the encoder and decoder, T5Gemma 2 ties all word embeddings (encoder input, decoder input, and decoder output) to reduce parameter count and memory footprint.
Merged Attention: T5Gemma 2 features a "merged attention" module that unifies the decoder's self-attention and cross-attention into a single joint module, whereas T5Gemma 1 maintains them as separate sub-layers.
Multimodality: T5Gemma 2 is natively multimodal and includes a frozen SigLIP vision encoder, allowing it to process images and text together. T5Gemma 1 is a text-only model.
Context Window: T5Gemma 2 supports a much larger context window of up to 128K tokens.
Model Numerics Verification screenshots:
Param count difference , This is expected and not a bug:
KerasHub counts encoder embedding + decoder embedding as separate weight matrices.
HF shares a single nn.Embedding instance for encoder/decoder/lm_head and counts it once.
Colab Notebook
Checklist