feat: add audio content blocks for Gemma multimodal prompts in model_mm#2240
Open
cliu1003 wants to merge 1 commit into
Open
feat: add audio content blocks for Gemma multimodal prompts in model_mm#2240cliu1003 wants to merge 1 commit into
cliu1003 wants to merge 1 commit into
Conversation
GetUserContent only emitted image and text blocks for the Gemma-style
structured content path, so audio inputs were never inserted into the
chat template. As a result the rendered prompt had no <|audio|> marker
and Gemma-4 audio soft tokens were appended at the very front of the
templated string, causing the model to ignore the audio (e.g. replying
"Please provide the audio...").
Emit one {"type":"audio"} block per audio clip so the chat template
inserts the <|audio|> marker in the correct position within the user
turn. No effect on Gemma-3 since num_audios is 0 for text/vision-only usage.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the C multimodal example prompt construction so Gemma-style structured-content messages include audio content blocks, allowing chat templates to place the audio marker(s) within the user turn (instead of relying on fallback prompt processing).
Changes:
- Extend
GetUserContent()structured-content branch to append one{"type":"audio"}block per audio clip. - Clarify the structured-content comment to reflect Gemma-3/Gemma-4 intent.
kunal-vaishnavi
previously approved these changes
Jun 24, 2026
Contributor
|
Thank you for your contribution! |
7a041ce to
0f470fc
Compare
kunal-vaishnavi
approved these changes
Jun 24, 2026
Author
|
Hi @kunal-vaishnavi, some failed checks are blocking the merge. Could you please re-run them? Thanks. |
Author
|
Hi @kunal-vaishnavi , thanks for you help, there are still one failed. Could you please re-run this? Thanks. |
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.
Description
GetUserContent()inexamples/c/src/common.cpponly emittedimageandtextcontent blocks for the Gemma-style structured-content path. Audioinputs (
num_audios) were silently ignored, so no{"type":"audio"}blockwas added and the chat template never rendered an
<|audio|>marker.As a result, for Gemma-4 audio inference the audio soft tokens were appended
at the very front of the templated prompt (via the fallback in
ProcessGemma4Prompt), outside the user turn. The model therefore did notassociate the audio with the request and replied with things like
"Please provide the audio you would like me to transcribe."
This PR emits one
{"type":"audio"}block per audio clip so the chattemplate inserts the
<|audio|>marker at the correct position within theuser turn, allowing the audio soft tokens to be expanded in place.
Changes
examples/c/src/common.cpp: add a loop that appends N{"type":"audio"}blocks (one per audio clip) in the Gemma-style structured-content branch.