From 98fe7e326ed4ec7ea872f15e351c10611d23a5fe Mon Sep 17 00:00:00 2001 From: Wenqi <88428807+BiggieW@users.noreply.github.com> Date: Wed, 10 Jun 2026 00:30:13 +0100 Subject: [PATCH] fix(gemma4): register image/video/audio token_regex for HF-expanded prompts (#26320) Co-authored-by: wenqi --- python/sglang/srt/multimodal/processors/gemma4.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/sglang/srt/multimodal/processors/gemma4.py b/python/sglang/srt/multimodal/processors/gemma4.py index d8fd6bd0a..f2d218cec 100644 --- a/python/sglang/srt/multimodal/processors/gemma4.py +++ b/python/sglang/srt/multimodal/processors/gemma4.py @@ -12,6 +12,7 @@ # limitations under the License. # ============================================================================== +import re from typing import Dict, List, Optional, Union import numpy as np @@ -41,9 +42,21 @@ class Gemma4SGLangProcessor(SGLangBaseProcessor): self.AUDIO_START_TOKEN_ID = hf_config.boa_token_id self.AUDIO_END_TOKEN_ID = hf_config.eoa_token_id self.mm_tokens = MultimodalSpecialTokens( + image_token="<|image|>", image_token_id=hf_config.image_token_id, + image_token_regex=re.compile( + r"<\|image>(?:<\|image\|>)+|<\|image\|>" + ), + video_token="<|video|>", video_token_id=hf_config.video_token_id, + video_token_regex=re.compile( + r"<\|image>(?:<\|video\|>)+|<\|video\|>" + ), + audio_token="<|audio|>", audio_token_id=hf_config.audio_token_id, + audio_token_regex=re.compile( + r"<\|audio>(?:<\|audio\|>)+|<\|audio\|>" + ), ).build(_processor) # Register image-processor and video-processor outputs so they are stored on