Instructions to use google/gemma-4-E2B-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-4-E2B-it with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/gemma-4-E2B-it") model = AutoModelForMultimodalLM.from_pretrained("google/gemma-4-E2B-it", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
Fix assistant content order before tool calls
Render an assistant's pre-tool content before its tool_calls and the corresponding tool results in google/gemma-4-E2B-it.
The current template reorders an OpenAI-style message containing both fields as tool_calls → tool_responses → content. It also uses that earlier explanation to close the model turn after the final tool result, preventing continuation in the same turn.
Move the existing content-rendering block before tool calls, remove has_content, and use the existing next-message scan to decide when to close the turn. This preserves this repository's thinking-channel and multimodal handling.
Example model turn, with content="I'll check." and a weather tool returning sunny:
Before: <|tool_call>...<tool_call|><|tool_response>...<tool_response|>I'll check.<turn|>
After: I'll check.<|tool_call>...<tool_call|><|tool_response>...<tool_response|>
Validation: on B300 with Transformers 5.5.4, rendered this exact repository template using AutoTokenizer.apply_chat_template(..., chat_template=template, tokenize=False, add_generation_prompt=True). The tokenizer was the installed Gemma 4 26B-A4B tokenizer; this is a template-rendering test. With the same message history, the original template fails content ordering and continuation; the patched file passes both, plus the next-user turn boundary. The same checks passed for all 23 standalone official Gemma 4 templates audited in this rollout.
Minimal history used:
messages = [
{"role": "user", "content": "Weather?"},
{"role": "assistant", "content": "I'll check.", "tool_calls": [{
"id": "call_1", "type": "function", "function": {
"name": "get_weather", "arguments": {"city": "London"}
}
}]},
{"role": "tool", "tool_call_id": "call_1", "content": "sunny"},
]
Related work:
- 26B-A4B fix and family rollout.
- vLLM shared Gemma 4 template fix #66269.
- Existing 12B ordering fix #12, independently verified and reused for that repository. This PR applies the minimal equivalent fix to a different model repository.
AI assistance (OpenAI Codex) was used for implementation and validation.