Repository navigation
Conversation
normalize_messages merged consecutive user messages, and consecutive system messages, into one message and put nothing between their texts, so "Hi." followed by "What is 2+2?" reached the model as "Hi.What is 2+2?". Clients send such messages, for example Pi after dropping a reply the user aborted. They are now passed on as separate messages, and the chat template decides how to render them, as llama.cpp, vLLM, MLX-LM, TGI and transformers do. Gemma 4 renders them as separate turns. A template that requires the roles to alternate, such as Gemma 3's, now rejects such a request instead of seeing the messages merged.
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.
normalize_messagesmerges consecutive user messages, and consecutive system messages, into one message, and puts nothing between their texts, so the words of two messages run together:Clients do send such messages. For example, Pi drops a reply the user aborted, which leaves two user messages in a row.
The messages are now passed on as they are, and the chat template decides how to render them. This is what llama.cpp, vLLM, MLX-LM, TGI and transformers do; Ollama merges them only for models on its older template path, and renders them as separate turns for Gemma 4. Gemma 4's template renders separate turns:
A template that requires the roles to alternate, such as Gemma 3's, now rejects such a request, as it does on llama.cpp and vLLM.
How to reproduce
Send two user messages in a row, then ask about the second one:
On
mainthe answer isWhat: the model sees one message, "Apples are red.Bananas are yellow.What is the first word…". On this branch it isBananas.I found this while reading the prompts flm renders, with a small debug branch that logs every prompt to a file (
log-prompt,FLM_LOG_PROMPT=<file>).