From 50b6842b4b95ecec6ea555e69e3d5afd9388af91 Mon Sep 17 00:00:00 2001 From: Zaili Wang <109502517+ZailiWang@users.noreply.github.com> Date: Fri, 31 Oct 2025 19:31:40 +0800 Subject: [PATCH] fix: Add default value for backend in sample_mmmu_requests (#12256) --- python/sglang/bench_serving.py | 7 +++++-- scripts/playground/bench_speculative.py | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/python/sglang/bench_serving.py b/python/sglang/bench_serving.py index a5d8228c7..e9e6a77e1 100644 --- a/python/sglang/bench_serving.py +++ b/python/sglang/bench_serving.py @@ -1014,7 +1014,7 @@ async def get_mooncake_request_over_time( def sample_mmmu_requests( num_requests: int, processor: AutoProcessor | AutoTokenizer, - backend: str, + backend: str = "sglang", fixed_output_len: Optional[int] = None, random_sample: bool = True, ) -> List[DatasetRow]: @@ -1369,7 +1369,10 @@ def create_mm_data_row( )["input_ids"].numel() except Exception: # Fallback: just tokenize the text prompt directly - text_prompt_len = len(processor.tokenizer.encode(text_prompt)) + tokenizer_to_use = ( + processor.tokenizer if hasattr(processor, "tokenizer") else processor + ) + text_prompt_len = len(tokenizer_to_use.encode(text_prompt)) # Vision tokens = total tokens - text tokens vision_prompt_len = prompt_len - text_prompt_len diff --git a/scripts/playground/bench_speculative.py b/scripts/playground/bench_speculative.py index c89e99242..e28ba92e4 100644 --- a/scripts/playground/bench_speculative.py +++ b/scripts/playground/bench_speculative.py @@ -57,14 +57,14 @@ class FakeTokenizer: def send_one_batch(base_url, num_prompts, batch_size, tokenizer, is_multimodal): # format: (prompt, input_len, output len). We set input_len as a dummy value 0. if is_multimodal: + backend = "sglang-oai-chat" + api_url = f"{base_url}/v1/chat/completions" input_requests = sample_mmmu_requests( num_prompts, tokenizer, - 512, - apply_chat_template=False, + backend=backend, + fixed_output_len=512, ) - backend = "sglang-oai-chat" - api_url = f"{base_url}/v1/chat/completions" else: padded_prompts = (prompts * ((num_prompts + len(prompts) - 1) // len(prompts)))[ :num_prompts