Add Gemma 4 (26B A4B) prompt-mode handler - #1340
Open
tumbak wants to merge 1 commit into
Open
Conversation
BFCL has no handler for Gemma 4, whose chat template differs from Gemma 3 (new turn-token format) and whose multimodal config breaks context-length detection. Adds Gemma4Handler (prompt mode) plus registration. - apply_chat_template for the correct Gemma 4 template - decode_ast/decode_execute: convert native <|tool_call>call:fn(args)<tool_call|> syntax to BFCL's [fn(args)] form (multi-turn parser fix) - _add_execution_results_prompting: role="tool_response" so tool feedback is rendered (the template silently drops role="tool"; multi-turn floors ~3% otherwise) - inference(): correct max_context_length to 262144 from text_config Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tumbak
marked this pull request as ready for review
June 1, 2026 08:53
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.
Summary
Adds a prompt-mode handler for Google Gemma 4 26B A4B Instruct
(
google/gemma-4-26B-A4B-it), which BFCL does not currently support. Theexisting Gemma 3 handler hardcodes the Gemma 3 chat template and is
incompatible with Gemma 4's new turn-token format, so a dedicated handler is
needed.
To my knowledge these are the first BFCL numbers published for Gemma 4. Full
methodology, per-category scores, and reproduction commands:
https://algollabs.com/blog/gemma4-bfcl
What this changes
bfcl_eval/model_handler/local_inference/gemma4.py—Gemma4Handler(subclasses
OSSHandler).bfcl_eval/constants/model_config.py— register the model + import.bfcl_eval/constants/supported_models.py— add the model id.SUPPORTED_MODELS.md— add the table row.Implementation notes
Chat template.
_format_promptdelegates totokenizer.apply_chat_template(...)so the correct Gemma 4 template ispicked up from the HF tokenizer (same approach as
QuickTestingOSSHandler),rather than hardcoding tokens like the Gemma 3 handler.
Native tool-call syntax (
decode_ast/decode_execute). With--jinja, Gemma 4 emits<|tool_call>call:fn(arg="x")<tool_call|>ratherthan the legacy
[fn(arg="x")]. Single-turn cases are coerced by thesystem-prompt preprocessing; in multi-turn the model reverts to native
syntax and the default parser fails ("Failed to decode the model response").
A small converter rewrites native → BFCL form before delegating to the
default decoder, handling five observed emission variants (standard,
empty-args, bracket-prefix, fullwidth colon, JSON-dict args). Responses
already in BFCL format and plain-prose refusals pass through untouched.
Tool results in multi-turn (
_add_execution_results_prompting). TheGemma 4 chat template silently drops
role="tool"messages (BFCL'sdefault), so the model never sees tool feedback and loops on failed
actions. Switching to
role="tool_response", which the template renders,is required — multi-turn accuracy floors at ~3% without it.
Context-length detection. Gemma 4 is multimodal; its top-level HF config
has no
max_position_embeddings(it lives undertext_config), sospin_up_local_serverfalls back to the tokenizer sentinel (~1e18). Thehandler corrects
max_context_lengthto the real value, 262144. See theopen question below.
Evaluation details
is_fc_model=False).temperature=1.0, top_p=0.95, top_k=64per Google's Gemma guidance (BFCL default is 0.001).
Open question for maintainers
The context-length fix is currently handler-local (corrected in
inference()because
spin_up_local_serveris decorated@final). The root cause isgeneric to multimodal HF configs, so it may belong in
base_oss_handler.pyinstead — reading
text_config.max_position_embeddingswhen the top-levelattribute is absent. Happy to move it there if you'd prefer the general fix.
🤖 Generated with Claude Code