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
Drop the trailing space after the last system text part
#53
by qgallouedec HF Staff - opened
A system message whose content is a list of text parts renders with a space after every part, including the last one:
tok.apply_chat_template([{"role": "system", "content": "SYS."}, {"role": "user", "content": "U"}], tokenize=False)
# '<bos><|turn>system\nSYS.<turn|>\n<|turn>user\nU<turn|>\n'
tok.apply_chat_template([{"role": "system", "content": [{"type": "text", "text": "SYS."}]}, {"role": "user", "content": "U"}], tokenize=False)
# '<bos><|turn>system\nSYS. <turn|>\n<|turn>user\nU<turn|>\n'
The same message gives two different token sequences. This shows up in fine-tuning. Trainers that convert content to parts for processors (TRL does this for every vision-language model) train on SYS. <turn|>, while inference with a plain string sees SYS.<turn|>. User and model turns don't have the problem, because they only trim and don't append anything.
This change emits the space only between parts. A string and a single part now render identically, and two parts still render as A. B.. Every Gemma 4 -it template (E2B, E4B, 12B, 26B-A4B, 31B) has the same line.