From 97fff98c6809df9bf5d75188b0b914978da1d784 Mon Sep 17 00:00:00 2001 From: blzheng Date: Tue, 9 Sep 2025 11:12:32 +0800 Subject: [PATCH] [CPU] Fix phi4-mm prompt issue in bench_serving (#9900) --- python/sglang/bench_serving.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/python/sglang/bench_serving.py b/python/sglang/bench_serving.py index f05658052..27ff8a6da 100644 --- a/python/sglang/bench_serving.py +++ b/python/sglang/bench_serving.py @@ -995,17 +995,25 @@ def sample_mmmu_requests( prompt = f"Question: {question}\n\nAnswer: " if apply_chat_template: try: + is_phi4_multimodal = ( + "phi-4-multimodal" in tokenizer.name_or_path.lower() + ) + if is_phi4_multimodal: + # <|endoftext10|> is the image token used in the phi-4-multimodal model. + content = prompt.replace("image 1", "<|endoftext10|>") + else: + content = [ + { + "type": "image_url", + "image_url": {"url": image_data}, + }, + {"type": "text", "text": prompt}, + ] prompt = tokenizer.apply_chat_template( [ { "role": "user", - "content": [ - { - "type": "image_url", - "image_url": {"url": image_data}, - }, - {"type": "text", "text": prompt}, - ], + "content": content, } ], add_generation_prompt=True,