Multiprocess Parallel Random Data Generation for Benchmark Serving.#1038
Open
Duyi-Wang wants to merge 1 commit intoSemiAnalysisAI:mainfrom
Open
Multiprocess Parallel Random Data Generation for Benchmark Serving.#1038Duyi-Wang wants to merge 1 commit intoSemiAnalysisAI:mainfrom
Duyi-Wang wants to merge 1 commit intoSemiAnalysisAI:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Accelerate random prompt generation in
benchmark_serving.pyby parallelizing thesample_random_requests()function using Pythonmultiprocessing.Pool. This addresses the bottleneck where generating large numbers of long prompts (e.g., 20K+ prompts at 8K+ input tokens) takes tens of minutes due to sequential tokenizer encode/decode operations.Problem
When running benchmarks with high concurrency and long input sequences, the data preparation phase dominates total wall time. For example:
The root cause is that each prompt requires multiple
tokenizer.decode()→tokenizer.encode()round-trips (up to 10 retries) to calibrate token length, and this entire loop runs sequentially in a single process.Solution
sample_random_requests()viamultiprocessing.PoolPool(initializer=...))--random-num-workersCLI argument (grouped with other--random-*options):0(default): auto-selectmin(cpu_count, 8)workers1: force serial execution (original behavior, full backward compatibility)N: use exactly N worker processestokenizer_id,tokenizer_mode,trust_remote_code,num_workers) added tosample_random_requests()function signature; all are optional with backward-compatible defaultsTest Results
Tested with DeepSeek-R1 tokenizer (vocab_size=128,000),
input_len=8192,output_len=1024,range_ratio=0.8:Correctness Verification (2,048 prompts, serial vs parallel)
Performance (8 worker processes)
Statistical Consistency
Files Changed
utils/bench_serving/benchmark_serving.py— Added multiprocessing support for prompt generation (+152/-28 lines)Usage
Reproducibility Verification
The parallel path is fully deterministic: given the same
--seedand--random-num-workers, multiple runs produce byte-identical results.Verified by running 3 consecutive executions with
seed=0,num_workers=4,num_prompts=200,input_len=1024and computing MD5 over all prompt texts and lengths:This is guaranteed because:
np.random.seed()makesinput_lens,output_lens,offsets, and per-worker seeds all deterministicnp.random.RandomState(seed)with its assigned fixed seedpool.map()returns results in chunk order (not completion order)Backward Compatibility
--random-num-workers 1preserves exact original behaviormultiprocessing)