From 26ebb849eb4dffa1e6ec8679d2bc364f16b655a0 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Sun, 18 May 2025 08:08:52 +0800 Subject: [PATCH] Tiny refactor bench_serving to extract RequestFuncOutput.init_new (#6108) --- python/sglang/bench_serving.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/python/sglang/bench_serving.py b/python/sglang/bench_serving.py index dd5aeccb0..1624aaacc 100644 --- a/python/sglang/bench_serving.py +++ b/python/sglang/bench_serving.py @@ -73,6 +73,12 @@ class RequestFuncOutput: error: str = "" output_len: int = 0 + @staticmethod + def init_new(request_func_input: RequestFuncInput): + output = RequestFuncOutput() + output.prompt_len = request_func_input.prompt_len + return output + def remove_prefix(text: str, prefix: str) -> str: return text[len(prefix) :] if text.startswith(prefix) else text @@ -114,8 +120,7 @@ async def async_request_trt_llm( if args.disable_ignore_eos: del payload["min_length"] del payload["end_id"] - output = RequestFuncOutput() - output.prompt_len = request_func_input.prompt_len + output = RequestFuncOutput.init_new(request_func_input) ttft = 0.0 st = time.perf_counter() @@ -186,8 +191,7 @@ async def async_request_openai_completions( } headers = get_auth_headers() - output = RequestFuncOutput() - output.prompt_len = request_func_input.prompt_len + output = RequestFuncOutput.init_new(request_func_input) generated_text = "" output_len = request_func_input.output_len @@ -269,8 +273,7 @@ async def async_request_truss( } headers = get_auth_headers() - output = RequestFuncOutput() - output.prompt_len = request_func_input.prompt_len + output = RequestFuncOutput.init_new(request_func_input) generated_text = "" ttft = 0.0 @@ -355,8 +358,7 @@ async def async_request_sglang_generate( headers = get_auth_headers() - output = RequestFuncOutput() - output.prompt_len = request_func_input.prompt_len + output = RequestFuncOutput.init_new(request_func_input) generated_text = "" output_len = request_func_input.output_len