Prerequisites
Feature Description
File: models/templates/google-gemma-4-31B-it.jinja, lines 219-230
What it does: For every message, it scans backwards to find the previous non-tool role. After the role is found, the loop does not stop.
What it should be: Google updated the Gemma 4 template. We should either update it to match or remove this scan.
Motivation
Environment: Mac M4 Pro, commit 436f6f8, tested template render times:
The current template scales quadratically with message count. Tested with 64 messages: 11.3 ms -> 3.1 ms and with 184 messages: 72.2 ms -> 10.9 ms (current implementation -> scan-removed version). Rendered output is byte-identical.
The template in the repo has not been updated since #21704 (2026-04-10).
Possible Implementation
Google made the same fix (merged on 2026-07-15): https://huggingface.co/google/gemma-4-31B-it/discussions/118
Possible options are (a) update the whole template to match Google's current implementation or (b) remove this scan. Which option do you prefer?
Prerequisites
Feature Description
File: models/templates/google-gemma-4-31B-it.jinja, lines 219-230
What it does: For every message, it scans backwards to find the previous non-tool role. After the role is found, the loop does not stop.
What it should be: Google updated the Gemma 4 template. We should either update it to match or remove this scan.
Motivation
Environment: Mac M4 Pro, commit 436f6f8, tested template render times:
The current template scales quadratically with message count. Tested with 64 messages: 11.3 ms -> 3.1 ms and with 184 messages: 72.2 ms -> 10.9 ms (current implementation -> scan-removed version). Rendered output is byte-identical.
The template in the repo has not been updated since #21704 (2026-04-10).
Possible Implementation
Google made the same fix (merged on 2026-07-15): https://huggingface.co/google/gemma-4-31B-it/discussions/118
Possible options are (a) update the whole template to match Google's current implementation or (b) remove this scan. Which option do you prefer?