From df111bc0fe55913ef3721b102ea4a28fcb0a92f2 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Sat, 13 Dec 2025 09:45:21 +0800 Subject: [PATCH] Super tiny add gsp-fast-prepare (#14992) --- python/sglang/bench_serving.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/python/sglang/bench_serving.py b/python/sglang/bench_serving.py index 9b3e15c53..5758ba51e 100644 --- a/python/sglang/bench_serving.py +++ b/python/sglang/bench_serving.py @@ -1661,7 +1661,11 @@ def sample_generated_shared_prefix_requests( flat_index = group_idx * prompts_per_group + prompt_idx question = questions[flat_index] full_prompt = f"{system_prompt}\n\n{question}" - prompt_len = len(tokenizer.encode(full_prompt)) + prompt_len = ( + 1 + if getattr(args, "gsp_fast_prepare", False) + else len(tokenizer.encode(full_prompt)) + ) input_requests.append( DatasetRow( @@ -1681,14 +1685,15 @@ def sample_generated_shared_prefix_requests( print(f"Number of groups: {num_groups}") print(f"Prompts per group: {prompts_per_group}") print(f"Total prompts: {len(input_requests)}") - print(f"Total input tokens: {total_input_tokens}") - print(f"Total output tokens: {total_output_tokens}") - print( - f"Average system prompt length: {sum(len(tokenizer.encode(sp)) for sp in system_prompts) / len(system_prompts):.1f} tokens" - ) - print( - f"Average question length: {sum(len(tokenizer.encode(q)) for q in questions) / len(questions):.1f} tokens\n" - ) + if not getattr(args, "gsp_fast_prepare", False): + print(f"Total input tokens: {total_input_tokens}") + print(f"Total output tokens: {total_output_tokens}") + print( + f"Average system prompt length: {sum(len(tokenizer.encode(sp)) for sp in system_prompts) / len(system_prompts):.1f} tokens" + ) + print( + f"Average question length: {sum(len(tokenizer.encode(q)) for q in questions) / len(questions):.1f} tokens\n" + ) # Save to cache cache_path.parent.mkdir(parents=True, exist_ok=True) @@ -2915,6 +2920,11 @@ if __name__ == "__main__": default=1.0, help="Range of sampled ratio of input/output length, used only for gsp dataset.", ) + group.add_argument( + "--gsp-fast-prepare", + action="store_true", + help="Speedup preparing by removing statistics computation, which will make some output statistics inaccurate but suitable for pressure tests.", + ) mooncake_group = parser.add_argument_group("mooncake dataset arguments") mooncake_group.add_argument( "--mooncake-slowdown-factor",