-
Notifications
You must be signed in to change notification settings - Fork 25
Add support for gemma3-text #70
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
Merged
IlyasMoutawwakil
merged 13 commits into
huggingface:main
from
thewh1teagle:feat/gemma3-text
Oct 22, 2025
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9744167
feat: add support for gemma3-text
thewh1teagle 9824aec
make uv lock like main
thewh1teagle 9a2a513
add gemma3 text tests
thewh1teagle 4f43910
remove patcher for gemma3 text
thewh1teagle 9de0ce9
Update README.md to include examples section for ONNX model usage
thewh1teagle 1d70ef1
Apply suggestion from @IlyasMoutawwakil
IlyasMoutawwakil ab9669c
Apply suggestion from @IlyasMoutawwakil
IlyasMoutawwakil 82c5a7d
Add gemma3 and gemma3_text to model list
IlyasMoutawwakil 14cec9f
Update optimum/exporters/onnx/model_configs.py
IlyasMoutawwakil 7f1249f
Merge branch 'main' into pr/thewh1teagle/70
IlyasMoutawwakil 801afdb
gemma models don't really need position ids
IlyasMoutawwakil 7c86839
hybrid cache exception
IlyasMoutawwakil 94b7645
gpt_oss and nemotron follow
IlyasMoutawwakil 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
Some comments aren't visible on the classic Files Changed page.
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,25 @@ | ||
| """Simple example: Export Gemma3 270M to ONNX and generate text. | ||
|
|
||
| Usage: | ||
| uv pip install onnxruntime | ||
| uv run examples/gemma3.py | ||
| """ | ||
|
|
||
| from transformers import AutoTokenizer | ||
|
|
||
| from optimum.onnxruntime import ORTModelForCausalLM | ||
|
|
||
|
|
||
| model_id = "google/gemma-3-270m-it" | ||
| tokenizer = AutoTokenizer.from_pretrained(model_id) | ||
| model = ORTModelForCausalLM.from_pretrained(model_id, export=True) | ||
|
|
||
| # Chat with instruction-tuned model | ||
| conversation = [{"role": "user", "content": "Hello! How are you?"}] | ||
| prompt = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True) | ||
| inputs = tokenizer(prompt, return_tensors="pt") | ||
|
|
||
| outputs = model.generate(**inputs, max_new_tokens=50, pad_token_id=tokenizer.eos_token_id) | ||
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | ||
|
|
||
| print(response) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why not 4.50.0 ?
https://github.com/huggingface/transformers/blob/v4.50.0/src/transformers/models/gemma3/modeling_gemma3.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bumped to 4.53.0 and added a comment about why