Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions rust/src/bench/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::metrics::steady_state;
use crate::output::console::print_results;
use crate::output::json::{append_result, build_result_json, compute_result_filename, save_result};
use crate::rate_control::compute_schedule;
use crate::ready_checker::wait_for_endpoint;
use crate::ready_checker::run_initial_ready_check;

/// Pre-resolve the hostname in `base_url` and pin all resolved IPs on the
/// client builder via [`reqwest::ClientBuilder::resolve_to_addrs`]. This
Expand Down Expand Up @@ -358,6 +358,8 @@ pub async fn run_benchmark(config: &BenchConfig) -> Result<serde_json::Value> {
(id, Some(name))
};

run_initial_ready_check(config, &client, &model_id, &model_name).await?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[correctness — confirmed] Model auto-resolution still hits the server before this ready check, so the readiness timeout never applies when --model is omitted.

When --model is omitted while the server is still starting (the exact scenario this PR targets), get_first_model_from_server (line 352) sends a single unretried GET /v1/models (request.send().await?) before run_initial_ready_check is reached, so the benchmark exits immediately with a connection-refused error instead of waiting --ready-check-timeout-sec. Same gap in run_multi_turn_benchmark (multi_turn.rs:77 via get_first_model).

Consider moving the ready check above model resolution (probing a health-ish endpoint first), or retrying the /v1/models fetch under the same timeout.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[efficiency] This serializes the server-boot wait before tokenizer load and dataset generation instead of overlapping them. On main, dataset generation (minutes for large random/HF datasets) ran while the server booted, and the ready check at the end consumed only the remaining boot time; now wall-clock startup is boot_time + generation_time instead of roughly max of the two.

A cheaper shape that keeps the fix: spawn the ready check as a concurrent task here and await it before the first server-dependent step (server-side tokenizer fallback, /tokenize verification, warmup).


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[correctness — plausible] With the probe moved before tokenizer download and dataset generation (which can take minutes for HF tokenizer fetch / ShareGPT / 100k-prompt random datasets), readiness is stale by the time the timed run starts:

  • reqwest's default pool_idle_timeout (90s, not overridden by this client builder) evicts the probe's connection in the interim, so for datasets that skip the /tokenize sample verification and with default num_warmups=0, the first benchmark request absorbs a fresh TCP/TLS handshake — inflating TTFT max/percentiles on small runs.
  • A server that crashes or restarts during dataset preparation — previously caught by the just-before-run probe — now surfaces as failed requests mid-benchmark instead of an upfront abort.

Same applies to multi_turn.rs:86.

// Load tokenizer (if needed)
let tokenizer = if config.skip_tokenizer_init {
None
Expand Down Expand Up @@ -681,26 +683,6 @@ pub async fn run_benchmark(config: &BenchConfig) -> Result<serde_json::Value> {
prompt_list: first.prompt_list.clone(),
};

// Ready check
if config.ready_check_timeout_sec > 0 {
tracing::info!("starting initial single-prompt test run");
let test_output = wait_for_endpoint(
config.backend,
&client,
&test_input,
config.ready_check_timeout_sec,
5,
)
.await?;
if !test_output.success {
return Err(BenchError::Backend(format!(
"Initial test run failed: {}",
test_output.error
)));
}
tracing::info!("initial single-prompt test run completed");
}

// Verify and fix prompt token lengths against the server's /tokenize endpoint.
// Runs after the ready check so a still-starting server isn't mistaken for a
// tokenize failure, and after the dry-run exit so dry runs stay offline.
Expand Down
38 changes: 2 additions & 36 deletions rust/src/bench/src/multi_turn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub async fn run_multi_turn_benchmark(config: &BenchConfig) -> Result<serde_json
(id, Some(name))
};

crate::ready_checker::run_initial_ready_check(config, &client, &model_id, &model_name).await?;

// Load tokenizer
let tokenizer = if config.skip_tokenizer_init {
None
Expand Down Expand Up @@ -244,42 +246,6 @@ pub async fn run_multi_turn_benchmark(config: &BenchConfig) -> Result<serde_json
return Ok(serde_json::json!({"dry_run": true, "mode": "multi_turn"}));
}

// Ready check with a simple single request
if config.ready_check_timeout_sec > 0 {
let first_turn = &conversations[0].turns[0];
let test_input = RequestFuncInput {
prompt: first_turn.user_message.clone(),
api_url: config.api_url.clone(),
prompt_len: first_turn.user_message_len,
output_len: first_turn.expected_output_len,
model: model_id.clone(),
model_name: model_name.clone(),
logprobs: config.logprobs,
extra_headers: config.extra_headers.clone(),
extra_body: config.extra_body.clone(),
ignore_eos: config.ignore_eos,
request_id: None,
..Default::default()
};

tracing::info!("starting initial single-prompt test run");
let test_output = crate::ready_checker::wait_for_endpoint(
config.backend,
&client,
&test_input,
config.ready_check_timeout_sec,
5,
)
.await?;
if !test_output.success {
return Err(BenchError::Backend(format!(
"Initial test run failed: {}",
test_output.error
)));
}
tracing::info!("initial single-prompt test run completed");
}

// For random datasets in multi-turn mode, auto-set min_tokens to enforce
// output length without using ignore_eos (which causes unbounded context growth).
// min_tokens + max_completion_tokens together control output length precisely.
Expand Down
47 changes: 47 additions & 0 deletions rust/src/bench/src/ready_checker.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright contributors to the vLLM project

use std::sync::Arc;
use std::time::Instant;

use indicatif::{ProgressBar, ProgressStyle};

use crate::backends::{RequestFuncInput, RequestFuncOutput, get_backend};
use crate::cli::BackendKind;
use crate::config::BenchConfig;
use crate::error::{BenchError, Result};

/// Wait for the configured backend before tokenizer and dataset initialization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[conventions] The move dropped the original inline comments — // Ready check (benchmark.rs) and // Ready check with a simple single request (multi_turn.rs) — contrary to rust/AGENTS.md: "When refactoring or reconstructing code, always preserve the original comments and documentation VERBATIM, if applicable." The note that the multi-turn probe is intentionally "a simple single request" is lost.

pub async fn run_initial_ready_check(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[test-coverage] run_initial_ready_check ships with no test coverage for its skip conditions or the rerank special case. The guard (return Ok on dry_run or ready_check_timeout_sec == 0) and the VllmRerank two-element prompt_list construction are pure, unit-testable logic. A future edit that inverts the dry_run guard would make --dry-run start issuing network requests (breaking the "dry runs stay offline" invariant documented in benchmark.rs) with nothing failing in CI.

config: &BenchConfig,
client: &reqwest::Client,
model_id: &str,
model_name: &Option<String>,
) -> Result<()> {
if config.dry_run || config.ready_check_timeout_sec == 0 {
return Ok(());
}

let prompt_list = (config.backend == BackendKind::VllmRerank).then(|| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[simplification] This rerank special case duplicates the pooling backend's payload contract (prompt_list = [query, doc1, ...], enforced in backends/pooling.rs::build_payload) at the ready-check layer. If another structured-input backend is added or rerank's minimum-input requirement changes, this probe silently becomes invalid and every run against a healthy server spins until the full --ready-check-timeout-sec, then dies with EndpointTimeout.

A probe-input constructor owned by the backend layer (e.g. a method on BackendKind/Backend in backends/mod.rs next to the payload builders) would keep the knowledge in one place.

Arc::from([
Arc::<str>::from("test query"),
Arc::<str>::from("test document"),
])
});
let test_input = RequestFuncInput {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[correctness — confirmed] The ready check no longer exercises the real benchmark request shape — multi_modal_content, chat_messages_json, and prompt_token_ids from the first dataset request are all dropped. Shape incompatibilities that previously aborted upfront now produce a full benchmark run with 0 completed requests.

Example: a multimodal dataset (VisionArena via openai-chat) against a model that rejects image input. Previously every probe got the server's 400 and the run aborted early with the underlying error in BenchError::EndpointTimeout. Now the text-only probe succeeds immediately, all N multimodal requests fail during the run, and — since metrics/calculator.rs has no all-requests-failed guard — the user waits out the whole run and gets a saved JSON result with completed=0 and zero/NaN metrics. Same applies to token-id probes if the server rejects token-array inputs.

Deriving the probe from the first dataset request (as before) while keeping the new early placement would need the dataset ready first — which conflicts with the goal here — but the probe could at least carry the request-shape-relevant fields once the dataset exists, e.g. by keeping a second shape-check before the timed run (see the staleness comment on benchmark.rs).

prompt: Arc::from("test"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[correctness — confirmed] The probe sends a text prompt ("test") without prompt_token_ids, which breaks the ready check against servers running with --skip-tokenizer-init: such servers reject string prompts on /v1/completions with a 400 on every attempt, so the check retries until --ready-check-timeout-sec expires and aborts with EndpointTimeout.

The removed single-turn ready check cloned first.prompt_token_ids into the probe, so this setup previously worked (e.g. random dataset with token-id prompts, which sets prompt="" and relies on prompt_token_ids).

api_url: config.api_url.clone(),
prompt_len: 1,
output_len: 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[correctness — confirmed] The synthetic probe hardcodes output_len: 1 (rendered as max_tokens: 1) while still merging the user's extra_body, so --extra-body '{"min_tokens": 32}' (a common way to force output length) makes every probe fail with 400 min_tokens must be less than or equal to max_tokens against a perfectly healthy server. wait_for_endpoint treats each 400 as "not ready" and retries every 5s, so the run stalls for the full --ready-check-timeout-sec and then aborts with EndpointTimeout.

The removed code used the first dataset request's expected_output_len as max_tokens (normally >= min_tokens), so this configuration previously worked.

model: model_id.to_string(),
model_name: model_name.clone(),
logprobs: config.logprobs,
extra_headers: config.extra_headers.clone(),
extra_body: config.extra_body.clone(),
ignore_eos: config.ignore_eos,
prompt_list,
..Default::default()
};

tracing::info!("starting initial single-prompt test run");
wait_for_endpoint(
config.backend,
client,
&test_input,
config.ready_check_timeout_sec,
5,
)
.await?;
tracing::info!("initial single-prompt test run completed");
Ok(())
}

/// Wait for the serving endpoint to become available.
///
/// Sends test requests with retry until success or timeout.
Expand Down
Loading