Repository navigation
fix(gemma4): current Gemma 4 chat template for E2B/E4B; 400 for non-object tool arguments (#975) - #1039
Draft
zaneni6 wants to merge 3 commits into
Draft
fix(gemma4): current Gemma 4 chat template for E2B/E4B; 400 for non-object tool arguments (#975)#1039zaneni6 wants to merge 3 commits into
zaneni6 wants to merge 3 commits into
Conversation
Security scan found no critical or high findings on lines changed by this pull requestView the security scan run for complete reports. “New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta. |
…bject tool arguments (#975) Template: gemma4-it:e2b/e4b and gemma4e-flash:e2b/e4b now pin chat_template.jinja oid 9d494178d6f050c786d4b6fa70a0e1a24fac4ae6 (18454 bytes): Google's current Gemma 4 template (null arguments render as null, turn closing around tool calls, reasoning kept after the last user message, image_url/input_audio parts) without the line that opens a thought channel after a tool response. The server drops reasoning from history, so a prompt ending in "<|channel>thought\n" is never a prefix of the next request and every agent-loop step would prefill the whole conversation again; 12B already ships without that line for the same reason. The file has to be uploaded to FastFlowLM/Gemma4-E2B-IT-NPU2 and Gemma4-E4B-IT-NPU2 before this merges. Tool arguments: the template refuses arguments that are not an object or null. gemma4_template_messages (shared by Gemma4e and Gemma4_12B) now turns those into HTTP 400 naming the call, not a 500 from minja. The gemma4-open extension test frontend maps empty-string arguments to {}, as Gemma4e does. Co-Authored-By: Claude <noreply@anthropic.com>
zaneni6
force-pushed
the
fix/gemma4-template-975
branch
from
December 6, 2026 04:50
002ec50 to
08876e6
Compare
…lls refresh the template (#975) The new chat template only reached fresh pulls: an installed E2B/E4B package stays Ready while its config.json is current, and keeps the old template. Their Hugging Face config.json now says flm_version 1.0.15 (E2B git oid a2222087, E4B git oid e504aebc; sizes unchanged), so: - src/model_info.json: the new config.json oid for gemma4-it:e2b/e4b and gemma4e-flash:e2b/e4b, which share the two packages; - src/model_list.json: flm_min_version 1.0.15 for the same four tags. An older download is then Outdated: run/serve/pull re-check every file, remove the template and config.json that no longer match, and download those two again. The weights are kept. Until the files are on Hugging Face, fresh pulls of these four tags fail the hash check. Co-Authored-By: Claude <noreply@anthropic.com>
…zer fix (#975, #1057) The new chat template and the 1.0.15 config.json are on a new branch, flm_1.0.15, of FastFlowLM/Gemma4-E2B-IT-NPU2 and Gemma4-E4B-IT-NPU2, not on main. Released FLM versions keep pulling main and its hashes keep matching; this version pulls the branch. The branch also carries Google's fixed tokenizer.json for each model (google/gemma-4-E2B-it 4adf1574, google/gemma-4-E4B-it 4ecc2ba6: glitch-token merges pruned, vocabulary and ids unchanged; #1057). The NPU packages shipped Google's pre-fix tokenizer (sha256 cc8d3a0c). - src/model_list.json: url, file_url and ms_url of gemma4-it:e2b/e4b and gemma4e-flash:e2b/e4b point at flm_1.0.15; - src/model_info.json: the tokenizer.json records of those four tags, as the branch's tree API lists them. Every record of the four tags now equals the branch; - src/test/model_extension_gemma4e/model-list.json: gemma4-open-it:e2b reads gemma4-it:e2b's records, so it points at the branch with flm_min_version 1.0.15 too. Until amd/Gemma4-E2B-IT-NPU2 and amd/Gemma4-E4B-IT-NPU2 on ModelScope have the same branch, --modelscope pulls of these tags fail. Co-Authored-By: Claude <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #975. Also fixes #1057 for the NPU packages (
gemma4-it:e2b/e4b,gemma4e-flash:e2b/e4b); #1108 coversgemma4-it-core.Problem
gemma4-it:e2b/e4b(andgemma4e-flash:e2b/e4b, which use the same HF packages) ship an older Gemma 4 chat template than Google's current one. Rendered through FLM's minja, the old template turns anulltool argument intonote:,/nested:{a:}. It also lacks Google's later fixes:image_url/input_audiopart names.Changes
Template (
src/model_info.json, 4 records). Pins Google's current Gemma 4 template minus the line that opens<|channel>thought\nafter a tool response. 12B ships without that line for the same reason (65240918). The server strips reasoning from history, so a prompt ending in that open channel is never a prefix of the next request. Every agent-loop step would re-prefill the whole conversation, andcontinue_final_messageafter a tool result would land inside a thought channel. The 12B template is unchanged.Tool-call arguments that are not a JSON object (e.g.
"oops","[1]"):gemma4_template_messages(used byGemma4eandGemma4_12B), returns HTTP 400 naming the call. Empty strings still become{}.Branch, not
main.url,file_urlandms_urlof the four tags point atflm_1.0.15(the same pattern asflm_q4k_high_precisionfor Qwen3.5). Released FLM versions keep pullingmain, whose files still match their pinned hashes, so updating Hugging Face does not break them.src/test/model_extension_gemma4e/model-list.jsonreadsgemma4-it:e2b's records, so it moves to the branch too.Tokenizer (#1057). The NPU packages shipped Google's pre-fix
tokenizer.json(sha256cc8d3a0c…). The branch carries Google's fixed file for each model (google/gemma-4-E2B-it4adf1574,google/gemma-4-E4B-it4ecc2ba6): glitch-token merges are pruned, while the vocabulary and token ids are unchanged, so the weights are unaffected. Themodel_info.jsonrecords are copied from the branch's tree API; every record of the four tags equals the branch.Existing installs (
config.jsonflm_version1.0.15,flm_min_version1.0.15). Without this, an installed package stays Ready and keeps the old template. With it, an older download is Outdated.flm run,serve,benchandpullre-check every file, remove the files that no longer match, and download only those again (template,config.json, tokenizer); the weights are kept. Same pattern as5c07ada0(Gemma3 4B family).gemma4_open_frontend.cpp(extension test frontend): empty-string arguments become{}, as inGemma4e.Testing
Upgrade path, from the real Hugging Face branch: copies of existing E2B and E4B installs (old template, old tokenizer,
config.jsonat 0.9.43).flm listshows all four tags outdated (0.9.43 < 1.0.15).flm pullverifies every file, removes and re-downloads onlychat_template.jinja,config.jsonandtokenizer.jsonfromflm_1.0.15, all three hash to the pinned values, andflm listshows all four tags ready.Tokenizer (#1057), NPU: with the fixed tokenizer, E2B and E4B repeat
drawingCodehint(Google's repro),CYCLONEDBandHello worldexactly. The API suite on the full new file set (template, config, tokenizer): e4b 178 / 0 / 44, e2b 179 / 0 / 43, the same as below.Rebased on main (
3077edfd). The 12B empty-thought fix this PR used to carry landed separately as #1053, so it is no longer here.Host:
test_chat_toolspasses, with new cases for argument handling. They fail when the helper is broken.test_chat_gemma4_args,test_chat_continueandtest_gemma4_12b_thoughtpass.NPU (Linux, HRX,
fastflow-sdk-v0.1.0.dev202611100004),src/test/openai_api_test/run_all.py. The baseline is the shipped template on the same binary:The one 12B failure,
test_tool_calls.function_nested_long_bounded_pattern("unexpected key 'data'"), also fails on plainorigin/mainwith the same package. It is not from this PR.NPU tool and reasoning scenarios, on all three models:
nullargument, thinking on/off, stream and non-stream;tool_choice=requiredandresponse_formatafter a tool result;session_cleared:false;On e4b,
/v1/messages(Anthropic) and/v1/responsesboth complete a tool round trip with anullargument, and/v1/responsesreturns 400 for non-objectfunction_call.arguments.Known: e2b, thinking off, greedy, tool call with a
nullargument. The first token after the tool result is a near tie between<|tool_response>(−0.63, a stop token) andThe(−0.76), so the reply comes back empty. With the old template's malformedunit:the gap was wider (−0.13 vs −2.07); without thenullit answers. This is the model's own close call on the correct prompt, not something this PR changes.Follow-ups (not in this PR)
test_tool_calls.function_nested_long_bounded_patternfails on 12B on main.[T, "null"]still fail the request."x", key:.gemma4-itserver path JSON-parses tool output strings ("1.10"becomes1.1).🤖 Generated with Claude Code