Skip to content

Render the Gemma 4 chat format when template detection fails - #214

Open
james-333i wants to merge 2 commits into
huggingface:mainfrom
james-333i:fix/llama-gemma4-template
Open

Render the Gemma 4 chat format when template detection fails#214
james-333i wants to merge 2 commits into
huggingface:mainfrom
james-333i:fix/llama-gemma4-template

Conversation

@james-333i

Copy link
Copy Markdown
Contributor

Gemma 4's canonical chat template no longer contains the marker that llama_chat_apply_template keys its detection on, so formatting threw encodingFailed for every Gemma 4 GGUF. When template application fails and the embedded template carries the Gemma 4 turn syntax, this renders it directly. Stacks on the vision PR.

Image segments threw unsupportedFeature because the backend had no
multimodal path, even though the prebuilt llama.cpp binaries ship the
mtmd library and its helpers.

Accept an mmprojPath at initialization and load the projector next to
the model. When a projector is present, prompt formatting replaces
each image segment with the mtmd media marker and collects payloads in
order, then generation tokenizes the marker-annotated prompt with
mtmd_tokenize and evaluates text and image chunks through
mtmd_helper_eval_chunks before sampling continues from the resulting
position. Both respond and streaming support images, and models
without a projector keep rejecting image input.

Adds live tests generating from an embedded test image through both
paths.
Gemma 4's canonical chat template no longer contains the
start_of_turn marker that llama_chat_apply_template keys its Gemma
detection on, so formatting threw encodingFailed for every Gemma 4
GGUF.

When template application fails and the embedded template carries the
Gemma 4 turn syntax, render it directly: turns open with a turn
marker and role, close with the reverse marker, the assistant role is
named model, and generation opens a model turn. The BOS token is
applied during tokenization, and thinking is opt-in in this format so
no suppression is needed.
@james-333i
james-333i force-pushed the fix/llama-gemma4-template branch from af77b51 to 03ada51 Compare September 4, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant