From 23583ee28cd383a0a961f31b53725b32770be5e7 Mon Sep 17 00:00:00 2001 From: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Date: Thu, 16 Oct 2025 17:36:39 -0400 Subject: [PATCH] [Bug] Add Assertion for `random-input-len` / `random-output-len` (#26834) Signed-off-by: yewentao256 --- vllm/benchmarks/datasets.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vllm/benchmarks/datasets.py b/vllm/benchmarks/datasets.py index 20a15bbc31e38..fc46fc6ec94ca 100644 --- a/vllm/benchmarks/datasets.py +++ b/vllm/benchmarks/datasets.py @@ -478,6 +478,22 @@ class RandomDataset(BenchmarkDataset): batchsize: int = 1, **kwargs, ) -> list[SampleRequest]: + # validate total input tokens (prefix + sampled) is at least 1. + num_special = int(tokenizer.num_special_tokens_to_add()) + real_input_len = max(0, int(input_len) - num_special) + min_sampled_input = math.floor(real_input_len * (1.0 - float(range_ratio))) + min_total_input = int(prefix_len) + min_sampled_input + if min_total_input < 1: + raise ValueError( + "--random-input-len is too small: with tokenizer special " + f"tokens {num_special} and --random-range-ratio {range_ratio}, " + "the minimum possible total input tokens (prefix + sampled) is " + f"{min_total_input}. Increase --random-input-len and/or " + "--random-prefix-len, or decrease --random-range-ratio so that " + "prefix_len + floor(max(0, random_input_len - num_special)) " + "* (1 - range_ratio) >= 1." + ) + input_lens, output_lens, offsets = self.get_sampling_params( num_requests, range_ratio, input_len, output_len, tokenizer )