-
Notifications
You must be signed in to change notification settings - Fork 31.1k
T5gemma2 #41834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bzhangGo
wants to merge
14
commits into
huggingface:main
Choose a base branch
from
bzhangGo:t5gemma2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
T5gemma2 #41834
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb6be0f
Fix small bug in T5Gemma 1 in __init__
bzhangGo 87ebcf6
Add t5gemma2 model & configurations.
bzhangGo 866c521
Add auto support
bzhangGo 0b42844
Add test case.
bzhangGo 9e7fd25
Add doctree.
bzhangGo 62a0931
Update positional embeddings to match latest update.
bzhangGo a5bfd95
Style fix & add use of final_logit_softcapping for attributes check.
bzhangGo 124dcb7
Update tests and embedding design.
bzhangGo bc6ab94
Add t5gemma2 to image-text-to-text category.
bzhangGo 5c8b891
Add T5Gemma2 doc.
bzhangGo fb49d99
remove unused imports.
bzhangGo e83d0fd
minor update following comments.
bzhangGo 2275a9f
minor style fixes.
bzhangGo 8133938
fix config.
bzhangGo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
|
|
||
| <!--Copyright 2025 The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
|
|
||
| ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # T5Gemma 2 | ||
|
|
||
| T5Gemma 2 is a family of pretrained encoder-decoder large language models with strong multilingual, multimodal and long-context capability, available in 270M-270M, 1B-1B and 4B-4B parameters. Following T5Gemma, it is built via model adaptation (based on Gemma 3) using UL2. The architecture is similar to T5Gemma and Gemma 3, enhanced with tied word embeddings and merged self- and cross-attention to save model parameters. | ||
|
|
||
| > [!TIP] | ||
| > Click on the T5Gemma 2 models in the right sidebar for more examples of how to apply T5Gemma 2 to different language tasks. | ||
|
|
||
| The example below demonstrates how to chat with the model with [`Pipeline`] or the [`AutoModel`] class, and from the command line. | ||
|
|
||
| <hfoptions id="usage"> | ||
| <hfoption id="Pipeline"> | ||
|
|
||
| ```python | ||
| import torch | ||
| from transformers import pipeline | ||
|
|
||
| generator = pipeline( | ||
| "image-text-to-text", | ||
| model="google/t5gemma-2-270m-270m", | ||
| dtype=torch.bfloat16, | ||
| device_map="auto", | ||
| ) | ||
|
|
||
| generator( | ||
| "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg", | ||
| text="<start_of_image> in this image, there is", | ||
| generate_kwargs={"do_sample": False, "max_new_tokens": 50}, | ||
| ) | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| <hfoption id="AutoModel"> | ||
|
|
||
| ```python | ||
| import torch | ||
| import requests | ||
| from PIL import Image | ||
| from transformers import AutoProcessor, AutoModelForSeq2SeqLM | ||
|
|
||
| processor = AutoProcessor.from_pretrained("google/t5gemma-2-270m-270m") | ||
| model = AutoModelForSeq2SeqLM.from_pretrained( | ||
| "google/t5gemma-2-270m-270m", | ||
| device_map="auto", | ||
| dtype=torch.bfloat16, | ||
| ) | ||
|
|
||
| url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg" | ||
| image = Image.open(requests.get(url, stream=True).raw) | ||
| prompt = "<start_of_image> in this image, there is" | ||
|
|
||
| model_inputs = processor(text=prompt, images=image, return_tensors="pt") | ||
| generation = model.generate(**model_inputs, max_new_tokens=20, do_sample=False) | ||
| print(processor.decode(generation[0])) | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| </hfoptions> | ||
|
|
||
| ## T5Gemma2Config | ||
|
|
||
| [[autodoc]] T5Gemma2Config | ||
|
|
||
| ## T5Gemma2ModuleConfig | ||
|
|
||
| [[autodoc]] T5Gemma2ModuleConfig | ||
|
|
||
| ## T5Gemma2Model | ||
|
|
||
| [[autodoc]] T5Gemma2Model | ||
| - forward | ||
|
|
||
| ## T5Gemma2ForConditionalGeneration | ||
|
|
||
| [[autodoc]] T5Gemma2ForConditionalGeneration | ||
| - forward | ||
|
|
||
| ## T5Gemma2ForSequenceClassification | ||
|
|
||
| [[autodoc]] T5Gemma2ForSequenceClassification | ||
| - forward | ||
|
|
||
| ## T5Gemma2ForTokenClassification | ||
|
|
||
| [[autodoc]] T5Gemma2ForTokenClassification | ||
| - forward |
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright 2024 The HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import _LazyModule | ||
| from ...utils.import_utils import define_import_structure | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_t5gemma2 import * | ||
| from .modeling_t5gemma2 import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.