Gemma 4 checkpoints are rejected for assistant-only loss: The chat template is not training-compatible
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- machine-learning
Research direction
Start with get_training_chat_template in the TRL chat template utilities, and look at how the existing training templates such as the one from #7967 are stored and registered. The work is to add training variants of gemma4_v5.jinja and gemma4_v10.jinja that carry {% generation %} markers, since the issue says the rest of each template is already prefix-preserving. Done means get_training_chat_template accepts the Gemma 4 E2B/E4B and 31B/12B checkpoints, and return_assistant_tokens_mask=True returns a non-zero mask.
Written by the indexing model from the issue text.
Description
Reproduction
TRL stores the Gemma 4 chat templates (gemma4.jinja to gemma4_v10.jinja) for response parsing, but has no training version of any of them. Gemma 4 templates have no {% generation %} markers, so get_training_chat_template rejects every Gemma 4 checkpoint and SFTTrainer with assistant_only_loss=True fails at init.
from transformers import AutoTokenizer
from trl.chat_template_utils import get_training_chat_template
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
get_training_chat_template(tokenizer)
outputs:
ValueError: The chat template is not training-compatible (missing prefix-preservation or `{% generation %}` markers) and patching is not supported for this template. Please manually modify the chat template for training.
Same for google/gemma-4-31B-it and google/gemma-4-12B-it. return_assistant_tokens_mask=True returns an all-zero mask on all three.
Tested with TRL main (1.18.0.dev0) and transformers 5.22.1.
How did you hit this?
I hit this fine-tuning Gemma 4 E4B on multi-turn agent trajectories (reasoning plus tool calls), and ended up computing the assistant spans myself.
Proposal
Add training templates for the two current revisions, the ones users download today:
gemma4_v5.jinja(google/gemma-4-E2B-it,google/gemma-4-E4B-it)gemma4_v10.jinja(google/gemma-4-31B-it,google/gemma-4-12B-it)
Both templates are already prefix-preserving, including with reasoning and tool calls in the history, so only the {% generation %} markers are needed.
I'd be happy to open the PR, following #7967. Could you assign this to me?
System Info
- Platform: macOS-15.7.7-arm64-arm-64bit
- Python version: 3.12.13
- TRL version: 1.18.0.dev0
- PyTorch version: 2.15.0
- accelerator(s): MPS
- Transformers version: 5.22.1
- Accelerate version: 1.15.0
- Accelerate config: not found
- Datasets version: 5.1.0
- HF Hub version: 2.4.0
- bitsandbytes version: not installed
- DeepSpeed version: not installed
- Liger-Kernel version: not installed
- PEFT version: not installed
- vLLM version: not installed
Checklist
- I have checked that my issue isn't already filed (see open issues)
- I have included my system information
- Any code provided is minimal, complete, and reproducible (more on MREs)
- Any code provided is properly formatted in code blocks, (no screenshot, more on code blocks)
- Any traceback provided is complete
- Dominant language
- Python
- Stars
- 19.7k
- Forks
- 3.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 283
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from huggingface/trl
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
huggingface/trl#8296 ·
Maintainers usually reply within 2 days
-
AsyncGRPO with top_k/top_p crashes on vLLM >= 0.32Possibly taken @rycerzes claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
huggingface/trl#8178 · 3 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
Docs: smol-course links in the SFT, DPO and ORPO trainer pages return 404Possibly taken @erdogan-deniz claimed this 7 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 80/100
huggingface/trl#8051 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
`parse_response` returns tool calls as plain text when `prefix` is omitted (transformers >= 5.13)Possibly taken @Sonica-B claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
huggingface/trl#7895 · 2 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Validate BEMACallback update_freqMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 65/100
huggingface/trl#7806 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
bug pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pydantic/pydantic-ai#13444 ·
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
changelog investigate
Difficulty 1/5 Under an hour Newbie friendliness 68/100
ramnes/notion-sdk-py#502 ·