Skip to content

Commit 586fbad

Browse files
jadewang21Mu Huai
authored and
Mu Huai
committed
Fix range_ratio Bug in RandomDataset (vllm-project#16126)
Signed-off-by: jadewang21 <[email protected]> Signed-off-by: Mu Huai <[email protected]>
1 parent ffffc3b commit 586fbad

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

benchmarks/benchmark_dataset.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def process_image(image: Any) -> Mapping[str, Any]:
288288
class RandomDataset(BenchmarkDataset):
289289
# Default values copied from benchmark_serving.py for the random dataset.
290290
DEFAULT_PREFIX_LEN = 0
291-
DEFAULT_RANGE_RATIO = 1.0
291+
DEFAULT_RANGE_RATIO = 0.0
292292
DEFAULT_INPUT_LEN = 1024
293293
DEFAULT_OUTPUT_LEN = 128
294294

@@ -308,19 +308,32 @@ def sample(
308308
output_len: int = DEFAULT_OUTPUT_LEN,
309309
**kwargs,
310310
) -> list[SampleRequest]:
311+
# Enforce range_ratio < 1
312+
assert range_ratio < 1.0, (
313+
"random_range_ratio must be < 1.0 to ensure a valid sampling range"
314+
)
315+
311316
vocab_size = tokenizer.vocab_size
312317

313318
prefix_token_ids = (np.random.randint(
314319
0, vocab_size, size=prefix_len).tolist() if prefix_len > 0 else [])
315320

316-
input_low = int(input_len * range_ratio)
317-
output_low = int(output_len * range_ratio)
321+
# New sampling logic: [X * (1 - b), X * (1 + b)]
322+
input_low = int(input_len * (1 - range_ratio))
323+
input_high = int(input_len * (1 + range_ratio))
324+
output_low = int(output_len * (1 - range_ratio))
325+
output_high = int(output_len * (1 + range_ratio))
326+
327+
# Add logging for debugging
328+
logger.info("Sampling input_len from [%s, %s]", input_low, input_high)
329+
logger.info("Sampling output_len from [%s, %s]", output_low,
330+
output_high)
318331

319332
input_lens = np.random.randint(input_low,
320-
input_len + 1,
333+
input_high + 1,
321334
size=num_requests)
322335
output_lens = np.random.randint(output_low,
323-
output_len + 1,
336+
output_high + 1,
324337
size=num_requests)
325338
offsets = np.random.randint(0, vocab_size, size=num_requests)
326339

benchmarks/benchmark_serving.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -996,18 +996,23 @@ def main(args: argparse.Namespace):
996996
random_group.add_argument(
997997
"--random-range-ratio",
998998
type=float,
999-
default=1.0,
1000-
help="Range of sampled ratio of input/output length, "
1001-
"used only for random sampling.",
999+
default=0.0,
1000+
help="Range ratio for sampling input/output length, "
1001+
"used only for random sampling. Must be in the range [0, 1) to define "
1002+
"a symmetric sampling range"
1003+
"[length * (1 - range_ratio), length * (1 + range_ratio)].",
10021004
)
10031005
random_group.add_argument(
10041006
"--random-prefix-len",
10051007
type=int,
10061008
default=0,
1007-
help="Number of fixed prefix tokens before random "
1008-
" context. The length range of context in a random "
1009-
" request is [random-prefix-len, "
1010-
" random-prefix-len + random-prefix-len * random-range-ratio).")
1009+
help=("Number of fixed prefix tokens before the random context "
1010+
"in a request. "
1011+
"The total input length is the sum of `random-prefix-len` and "
1012+
"a random "
1013+
"context length sampled from [input_len * (1 - range_ratio), "
1014+
"input_len * (1 + range_ratio)]."),
1015+
)
10111016

10121017
hf_group = parser.add_argument_group("hf dataset options")
10131018
hf_group.add_argument("--hf-subset",

benchmarks/benchmark_throughput.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,22 @@ def validate_args(args):
594594
default=None,
595595
help="Path to the lora adapters to use. This can be an absolute path, "
596596
"a relative path, or a Hugging Face model identifier.")
597-
parser.add_argument("--prefix-len",
598-
type=int,
599-
default=None,
600-
help="Number of prefix tokens per request."
601-
"This is for the RandomDataset and SonnetDataset")
597+
parser.add_argument(
598+
"--prefix-len",
599+
type=int,
600+
default=0,
601+
help="Number of fixed prefix tokens before the random "
602+
"context in a request (default: 0).",
603+
)
602604
# random dataset
603605
parser.add_argument(
604606
"--random-range-ratio",
605607
type=float,
606-
default=None,
607-
help="Range of sampled ratio of input/output length, "
608-
"used only for RandomDataSet.",
608+
default=0.0,
609+
help="Range ratio for sampling input/output length, "
610+
"used only for RandomDataset. Must be in the range [0, 1) to define "
611+
"a symmetric sampling range "
612+
"[length * (1 - range_ratio), length * (1 + range_ratio)].",
609613
)
610614

611615
# hf dtaset

0 commit comments

Comments
 (0)