Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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: 24 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,30 @@ before the final usage chunk arrives. Each emitted chunk carries cumulative
native token counts; text chunks can combine multiple tokens, so counting
chunks does not measure generated tokens. The final usage chunk is also emitted.

## Per-request metrics

`--enable-per-request-metrics`, or `[server] per_request_metrics = true`, makes
OpenAI Chat and Completions responses carry a `metrics` object with the timing
of that request, matching vLLM's per-request metrics. The option is off by
default. A non-streaming response carries the object at the top level; a
streaming response carries it only on the final usage chunk, so a stream needs
`"stream_options": {"include_usage": true}` to receive it. With `n` choices the
object is null, because one sequence's timing cannot describe the whole
response. Anthropic Messages and OpenAI Responses responses do not include it.

| Field | Meaning |
| --- | --- |
| `time_to_first_token_ms` | HTTP admission to the first output token; vLLM measures from scheduler admission, which the HTTP layer cannot observe |
| `time_to_first_content_token_ms` | HTTP admission to the first non-empty answer or reasoning text; streaming only, and null for non-streaming requests |
| `generation_time_ms` | First output token to the last output token |
| `queue_time_ms` | Always null: the HTTP layer does not separate queueing from prefill |
| `mean_itl_ms` | `generation_time_ms` divided by output tokens after the first; null for a single-token response |
| `tokens_per_second` | Output tokens over the interval from HTTP admission to the last output token |

Fields are null when the request produced no such interval. Enabling the option
makes the serving process read the clock once per output token and keep the
first and last instants; disabling it reads no clock for timing.

## Raw completions

`prompt` accepts a string, an array of strings, a token-ID array, or an array of
Expand Down
3 changes: 2 additions & 1 deletion docs/cli-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ Help exits with status 0; usage errors go to stderr with status 2. Its options a
| `--port N` | Listener port | `[server] port`, otherwise `8000` |
| `--served-model-name ALIAS` | Replace the core's serving aliases with this nonblank alias | Core aliases |
| `--api-key-file PATH` | File containing the serving API key; an empty file disables authentication | `[server] api_key`, otherwise no authentication |
| `--enable-per-request-metrics` | Add a `metrics` timing object to OpenAI Chat and Completions responses | `[server] per_request_metrics`, otherwise off |
| `--max-concurrency N` | Reduce concurrency within captured batch capacities | Model/default configuration, otherwise core default |
| `--kv-cache-limit concurrency\|context\|memory` | Bound shared KV history by prepared context times selected concurrency, one prepared context, or available memory | `memory` |
| `--memory-limit LIMIT` | Per-GPU occupied size (`30G`), free-memory reserve (`-30G`, including `-0G`), or fraction of total memory (`0.8`) | `[memory] reserve`, otherwise core serving reserve |
Expand Down Expand Up @@ -1316,7 +1317,7 @@ An absent default file supplies no overrides; an explicitly selected missing
file or an invalid runtime setting is an error. Help does not read the file.

Native `flare run` applies `[server] host`, `port`, `api_key`, `thinking_token_budget`,
and `scheduler_checkpoint_extra_work_fraction`,
`per_request_metrics`, and `scheduler_checkpoint_extra_work_fraction`,
`[memory] reserve`, `[defaults] max_concurrency`, `[models.<name>] max_concurrency`, all `[prefix_cache]`
settings, and `[paths] prefix_cache`. Prepared-model acquisition and cache commands
use `[paths] core_cache`. Flags override these defaults, including explicit
Expand Down
20 changes: 20 additions & 0 deletions flare-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ impl OrbitPush {
host: "127.0.0.1".parse().unwrap(),
port: 8000,
served_model_name: None,
enable_per_request_metrics: false,
roce_ring: self.roce_ring,
roce_chain: self.roce_chain,
rendezvous: None,
Expand Down Expand Up @@ -620,6 +621,10 @@ pub struct OrbitRun {
#[arg(long, value_name = "ALIAS", value_parser = served_model_name, help_heading = "Serving options")]
pub served_model_name: Option<String>,

/// Include per-request timing metrics in OpenAI chat and completion responses.
#[arg(long, help_heading = "Serving options")]
pub enable_per_request_metrics: bool,

/// Favor throughput or output cadence [default: saved group or balanced].
#[arg(long, value_name = "MODE",
value_parser = ["balanced", "throughput"], help_heading = "Serving options")]
Expand Down Expand Up @@ -689,6 +694,9 @@ impl OrbitRun {
if let Some(path) = &self.api_key_file {
options.extend(["--api-key-file".into(), path.display().to_string()]);
}
if self.enable_per_request_metrics {
options.push("--enable-per-request-metrics".into());
}
options
}

Expand All @@ -699,6 +707,7 @@ impl OrbitRun {
host: self.host.unwrap_or_else(|| "127.0.0.1".parse().unwrap()),
port: self.port.unwrap_or(8000),
served_model_name: self.served_model_name.clone(),
enable_per_request_metrics: self.enable_per_request_metrics,
roce_ring: self.roce_ring,
roce_chain: self.roce_chain,
rendezvous: None,
Expand Down Expand Up @@ -764,6 +773,10 @@ pub struct Run {
#[arg(long, value_name = "ALIAS", value_parser = served_model_name, help_heading = "Serving options")]
pub served_model_name: Option<String>,

/// Include per-request timing metrics in OpenAI chat and completion responses.
#[arg(long, help_heading = "Serving options")]
pub enable_per_request_metrics: bool,

/// Experimental ring in rank order: only neighbor RoCE QPs connect;
/// native CPU relays forward non-neighbor traffic. Also emulates a ring on a switch.
#[arg(long, help_heading = "Multi-host options")]
Expand Down Expand Up @@ -1502,6 +1515,13 @@ mod tests {
}
}

#[test]
fn per_request_metrics_flag_is_off_by_default_and_forwards_to_rank_zero() {
assert!(!run(&["flare", "run", "model"]).enable_per_request_metrics);
assert!(run(&["flare", "run", "model", "--enable-per-request-metrics"])
.enable_per_request_metrics);
}

fn run(arguments: &[&str]) -> Run {
let Command::Run(args) = Cli::try_parse_from(arguments).unwrap().command else {
panic!("expected run")
Expand Down
2 changes: 2 additions & 0 deletions flare-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ fn run() -> Result<std::process::ExitCode, Box<dyn std::error::Error>> {
}
config["api_key"] = key.into();
config["thinking_token_budget"] = serde_json::json!(configuration.thinking_token_budget());
config["per_request_metrics"] =
(args.enable_per_request_metrics || configuration.per_request_metrics()).into();
phase.finish(config["model_id"].as_str().unwrap_or_default());
serve(owner, config, progress, cluster, routing)?;
#[cfg(unix)]
Expand Down
5 changes: 5 additions & 0 deletions flare/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Server {
pub api_key: Option<String>,
pub thinking_token_budget: Option<std::num::NonZeroU32>,
pub scheduler_checkpoint_extra_work_fraction: Option<f64>,
pub per_request_metrics: Option<bool>,
}

#[derive(Default, Deserialize)]
Expand Down Expand Up @@ -131,6 +132,10 @@ impl Configuration {
.thinking_token_budget
.map(std::num::NonZeroU32::get)
}

pub fn per_request_metrics(&self) -> bool {
self.server.per_request_metrics.unwrap_or(false)
}
}

pub fn nonempty(value: Option<&str>) -> Option<&str> {
Expand Down
1 change: 1 addition & 0 deletions flare/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,7 @@ impl Worker {
let phase = progress.phase("Load tokenizer", None);
let mut config = owner.server_config().clone();
config["thinking_token_budget"] = serde_json::json!(self.settings.thinking_token_budget);
config["per_request_metrics"] = self.settings.per_request_metrics.into();
if let Some(fraction) = self.settings.scheduler_checkpoint_extra_work_fraction {
config["scheduler_checkpoint_extra_work_fraction"] = fraction.into();
}
Expand Down
20 changes: 20 additions & 0 deletions flare/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Settings {
pub publisher_keys: Vec<PathBuf>,
pub thinking_token_budget: Option<u32>,
pub scheduler_checkpoint_extra_work_fraction: Option<f64>,
pub per_request_metrics: bool,
pub prefix_cache: PrefixCacheOffload,
pub model_concurrency: std::collections::HashMap<String, usize>,
}
Expand Down Expand Up @@ -155,6 +156,7 @@ impl Settings {
pool: None,
};
let thinking_token_budget = configuration.thinking_token_budget();
let per_request_metrics = configuration.per_request_metrics();
let model_concurrency = configuration
.models
.into_iter()
Expand Down Expand Up @@ -207,6 +209,7 @@ impl Settings {
publisher_keys: Vec::new(),
thinking_token_budget,
scheduler_checkpoint_extra_work_fraction: configuration.server.scheduler_checkpoint_extra_work_fraction,
per_request_metrics,
prefix_cache,
model_concurrency,
})
Expand Down Expand Up @@ -277,6 +280,23 @@ mod runtime_tests {
assert_eq!(desired.api_key.as_deref(),Some("unchanged-secret"));
assert!(!serde_json::to_string(&desired.runtime).unwrap().contains("secret"));
}
#[test]
fn per_request_metrics_default_to_off_and_follow_the_server_section() {
for (text, expected) in [
("", false),
("[server]\nper_request_metrics=true\n", true),
("[server]\nper_request_metrics=false\n", false),
] {
let settings = Settings::resolve(
Configuration::parse(text).unwrap(),
Path::new("user"),
Path::new("config.toml"),
)
.unwrap();
assert_eq!(settings.per_request_metrics, expected, "{text}");
}
}

#[test]
fn explicit_desktop_concurrency_wins_over_conflicting_model_aliases() {
let config=Configuration::parse("[models.first]\nmax_concurrency=2\n[models.second]\nmax_concurrency=3\n").unwrap();
Expand Down
6 changes: 6 additions & 0 deletions helios/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ pub struct ServerConfig {
pub context_hint: String,
/// Setting that raises request or page capacity, appended to capacity rejections.
pub capacity_hint: String,
/// Include vLLM-compatible per-request timing metrics in OpenAI chat and
/// completion responses.
pub per_request_metrics: bool,
pub scheduling_policy: crate::scheduler::PolicyConfig,
}
impl Default for ServerConfig {
Expand All @@ -144,6 +147,7 @@ impl Default for ServerConfig {
thinking_token_budget: None,
context_hint: String::new(),
capacity_hint: String::new(),
per_request_metrics: false,
scheduling_policy: crate::scheduler::PolicyConfig::default(),
}
}
Expand All @@ -169,6 +173,7 @@ struct HttpState {
thinking_token_budget: Option<u32>,
context_hint: String,
capacity_hint: String,
per_request_metrics: bool,
response_model: String,
started: Instant,
generated: Mutex<VecDeque<(Instant, u64)>>,
Expand Down Expand Up @@ -327,6 +332,7 @@ impl Server {
thinking_token_budget: config.thinking_token_budget,
context_hint: config.context_hint.clone(),
capacity_hint: config.capacity_hint.clone(),
per_request_metrics: config.per_request_metrics,
response_model: models::response_name(model.config(), &config.served_names).to_owned(),
started: Instant::now(),
generated: Mutex::new(VecDeque::new()),
Expand Down
5 changes: 5 additions & 0 deletions helios/src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ impl Bootstrap {
served_names,
context_hint: optional_text("context_hint")?,
capacity_hint: optional_text("capacity_hint")?,
per_request_metrics: match object.get("per_request_metrics") {
None => false,
Some(Value::Bool(value)) => *value,
_ => return Err("per_request_metrics must be a boolean".into()),
},
bind: object
.get("bind")
.and_then(Value::as_str)
Expand Down
Loading