From f4100732b81b9a41689fffb22989866ece2d3869 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:27:55 +0800 Subject: [PATCH] Tiny fix bench serving GSP mode cache file strategy (#15587) --- python/sglang/bench_serving.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python/sglang/bench_serving.py b/python/sglang/bench_serving.py index 3154802d9..ecf036f99 100644 --- a/python/sglang/bench_serving.py +++ b/python/sglang/bench_serving.py @@ -1651,9 +1651,10 @@ def sample_generated_shared_prefix_requests( ) -> List[DatasetRow]: """Generate benchmark requests with shared system prompts using random tokens and caching.""" cache_path = get_gen_prefix_cache_path(args, tokenizer) + should_cache = range_ratio == 1 # Try to load from cache first - if cache_path.exists() and range_ratio == 1: + if cache_path.exists() and should_cache: print(f"\nLoading cached generated input data from {cache_path}") with open(cache_path, "rb") as f: return pickle.load(f) @@ -1740,10 +1741,11 @@ def sample_generated_shared_prefix_requests( ) # Save to cache - cache_path.parent.mkdir(parents=True, exist_ok=True) - print(f"Caching generated input data to {cache_path}") - with open(cache_path, "wb") as f: - pickle.dump(input_requests, f) + if should_cache: + cache_path.parent.mkdir(parents=True, exist_ok=True) + print(f"Caching generated input data to {cache_path}") + with open(cache_path, "wb") as f: + pickle.dump(input_requests, f) return input_requests