Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7c58f22
Add request latency histograms and process metrics
WynnD Nov 26, 2026
3b4cf0c
Exclude cancelled responses and reuse host helpers
WynnD Nov 27, 2026
4ed9c43
Hoist completion values and tighten stat parsing
WynnD Nov 27, 2026
de6d989
Remove process metrics from the request latency change
WynnD Nov 27, 2026
5898e15
Add per-request histograms that match vLLM's request metrics
WynnD Nov 27, 2026
1a29417
Count lookup tokens, output-limit stops, parked requests, and queue r…
WynnD Nov 27, 2026
63437af
Document how Flare's metrics correspond to vLLM's
WynnD Nov 27, 2026
151207f
State request-histogram populations from the code and drop duplicate …
WynnD Nov 27, 2026
a85cb5c
Place request-histogram docs and test rows apart from the KV-page gauges
WynnD Nov 28, 2026
be487aa
Reuse GraphKind::samples for model-step metrics and stamp scheduled t…
WynnD Nov 28, 2026
5687ebb
Render every observed histogram through Histogram
WynnD Nov 28, 2026
6452595
Exclude only tool-limit-cancelled choices from HTTP response histograms
WynnD Nov 28, 2026
ed66300
Skip idle model steps, bind admission labels to their enum, and trim …
WynnD Nov 28, 2026
4fbb9d2
Keep requeued waits in queue time and drop synthetic histogram samples
WynnD Nov 29, 2026
58f4090
Report the first scheduled model step in Chat performance
WynnD Nov 27, 2026
eb075f4
Report vLLM per-request metrics from runtime instants
WynnD Nov 27, 2026
8745999
Report the content-token instant of per-request metrics as null
WynnD Nov 28, 2026
b883f49
Export RequestTimes and report the earliest first scheduled step
WynnD Nov 28, 2026
1842946
Read per-request metrics from the [server] configuration
WynnD Nov 28, 2026
d48fa8d
State the per-request metrics boundaries and the include_usage gap
WynnD Nov 28, 2026
b1389b7
Accept [server] per_request_metrics in the Ignition configuration
WynnD Nov 28, 2026
6cf5528
Document where Orbit reads per_request_metrics and that the flag only…
WynnD Nov 28, 2026
f5af016
Define the per-request metrics null cases and token timestamps in the…
WynnD Nov 28, 2026
645ad3e
Share the step-generates test predicate and trim encoder metrics comm…
WynnD Nov 28, 2026
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
139 changes: 135 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@ requires the serving key: both report aggregate state without request content.
`GET /metrics` returns Prometheus text exposition format 0.0.4 by default.
Counter and gauge names start with `flare_`, such as
`flare_generated_tokens_total`, `flare_active_requests`, and
`flare_free_kv_pages`. The only histograms describe host prefix-store lookups:
`flare_host_cache_missing_tokens`, `flare_host_cache_estimated_transfer_ns`, and
`flare_host_cache_estimated_prefill_ns`. Beyond the JSON fields below, the
`flare_free_kv_pages`. Beyond the JSON fields below, the
text includes speculative and proposal counters by batch, width, or depth, graph
launches by kind, embedding row-cache counters, HTTP admission gauges, and
uptime.
Expand All @@ -304,6 +302,88 @@ selects text regardless of `Accept`, and any other `format` value returns HTTP
as zero, and `flare_helios::server::view` holds the rate history and plots of
the serving terminal dashboard.

Histograms appear in the Prometheus format only, accumulate since server start,
and define each interval or count in their `# HELP` text. Host prefix-store
histograms report lookup cost and retirement:
`flare_host_cache_missing_tokens`, `flare_host_cache_estimated_transfer_ns`,
`flare_host_cache_estimated_prefill_ns`, and
`flare_host_cache_retirement_seconds`.

The HTTP histograms measure response delivery time and exclude
`/v1/messages/count_tokens`. `flare_request_e2e_seconds` observes once each
successful generation response that delivers at least one choice. A stream is
observed when the client drains its body, so a stream the client abandons adds
none; a non-streaming response is observed when its body is ready, before the
client reads it. Flare runs each choice as its own model request and counts one
completion per choice, so a multi-choice response adds fewer e2e observations
than completions. Only `/v1/completions` accepts `n` above one or a list of
prompts. Per prompt, `flare_request_choices` observes the number of delivered
choices and `flare_request_max_choice_generated_tokens` the largest
generated-token count among them. A choice stopped at the
`parallel_tool_calls: false` tool limit is not delivered, including a choice
whose generation completed naturally before the limit stopped delivery: the
encoder counts it as cancelled, and it enters neither choice histogram.
`flare_time_to_first_response_seconds` observes each response that offers answer
or reasoning text once the client reads that text, including a stream that fails
after offering it.

The runtime histograms observe only requests whose model generation completes
successfully. Cancelled and failed requests enter none of them; apart from
counters, the only series that can observe such a request is
`flare_time_to_first_response_seconds`, and only when text was offered before
the failure. The first model step that includes a request ends the queue interval
and starts the prefill and inference intervals; it can be an initialization,
restore, or vision step, so `flare_request_prefill_seconds` includes
cache-initialization and host-restore time. A request that reached no such step
records no queue observation. A request requeued before it generated a token
clears that instant: the wait through its park and readmission counts as queue
time, and the next executing step stamps the intervals again. A late host-cache
answer that requeues a request before its initialization or restore step
therefore counts the wait for the restore as queue time rather than prefill
time. A completion that committed no generated token increments
`flare_requests_completed_total` and enters only the token-count and preemption
histograms.
`flare_request_decode_seconds` and `flare_time_per_output_token_seconds` require
a committing step after the first token; a token that only a forced reasoning
close added, without such a step, records neither.
The decode time and time per output token of a preempted request, and its
inter-token interval that spans the preemption, include the wait for readmission.
A speculative round committing several tokens is one inter-token observation,
and a request's intervals enter the histogram when it completes.
`flare_request_prefill_computed_tokens` excludes recomputation after a
preemption, and `flare_request_generated_tokens` includes a forced reasoning
close. `flare_request_max_tokens` includes tokens a reasoning budget defers and
omits prompt-scoring requests with a zero limit. `flare_request_preemptions` uses
vLLM's preemption bounds with an added zero bound.

`flare_requests_output_limited_total` counts completed requests that stopped at
their output token limit; the rest of `flare_requests_completed_total` stopped at
EOS, a stop sequence, or a stop string. `flare_cache_lookup_tokens_total` counts
the prompt tokens of admitted requests offered to GPU prefix lookups, including
readmissions, and `flare_cache_reused_tokens_total` counts the tokens found, so
their ratio is the token hit rate; prompt-scoring requests skip the lookup and
enter neither. `flare_pending_requests` counts requests waiting in the model
scheduler for their first admission, and `flare_parked_requests` counts requests
waiting there for readmission after a preemption, a reasoning budget cut, or a
host-store restore that failed or was retried; neither includes admitted
requests waiting for a host restore, which `flare_host_cache_inbound_waiting`
counts among `flare_active_requests`. `flare_admission_rejections_total{reason}`
counts HTTP requests refused because a queue limit was full. `http_slots`
counts requests refused with HTTP 429 because the HTTP admission slots, one per
generated choice, are all reserved; the admission middleware wraps
`/v1/chat/completions`, `/v1/completions`, `/v1/messages`,
`/v1/messages/count_tokens`, `/v1/responses`, `/v1/systemone`, and
`/v1/decisions`, so a 429 from any of those routes counts.
`generation_capacity` and `request_queue` count generation requests when the
runtime's generation capacity or the channel into the model worker is full.
Paused admission and an unavailable runtime return HTTP 503 and are not counted.
`flare_model_step_tokens` observes, for every completed prefill, resume, decode,
speculative, or mixed graph, the prompt tokens it computed plus the generated
tokens it committed; rejected draft positions and padding are excluded,
initialization, restore, vision, and snapshot graphs are not observed, and a step
in which no lane made progress, such as one whose every lane failed, is not
observed.

The fields in the table are integers except `learned_drafter`. Totals count from
server start; `active`, `pending`, the page fields, and the host record fields are
instantaneous gauges. The object also contains `first_response`, an object with
Expand All @@ -325,7 +405,7 @@ without the `flare_` prefix, such as `input_decoded_images_total`.
| `accepted_drafts` | Accepted draft tokens, excluding the bonus token | `flare_accepted_draft_tokens_total` |
| `draft_rounds` | Request rounds that offered at least one draft | `flare_draft_request_rounds_total` |
| `active` | Model slots with a live request | `flare_active_requests` |
| `pending` | Requests waiting in the model scheduler | `flare_pending_requests` |
| `pending` | Requests waiting in the model scheduler for their first admission | `flare_pending_requests` |
| `completed` | Requests whose generation completed successfully | `flare_requests_completed_total` |
| `reasoning_budget_cuts` | Requests whose reasoning was closed by their hard token budget | `flare_reasoning_budget_cuts_total` |
| `failed` | Requests failed by admission, execution, grammar, or output processing | `flare_requests_failed_total` |
Expand Down Expand Up @@ -937,6 +1017,57 @@ 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

`flare run --enable-per-request-metrics`, or `[server] per_request_metrics = true`
in the host configuration, adds vLLM's per-request `metrics` object to OpenAI
Chat Completions, Completions, and Responses output. The option
is off by default, and no response carries the key without it. Anthropic Messages
output never carries the object. The fields are milliseconds, except
`tokens_per_second`, and come from the instants the model worker records for the
runtime histograms under [Health and metrics](#health-and-metrics), so a stop
string, which the worker matches, does not change how they are measured:

| Field | Definition |
| --- | --- |
| `queue_time_ms` | Model-queue arrival to the first model step that includes the request |
| `time_to_first_token_ms` | That first scheduled step to the completion of the step that committed the first generated token |
| `time_to_first_content_token_ms` | Always null: Flare does not report when answer text first appeared, as vLLM permits for a value it cannot provide |
| `generation_time_ms` | First to last committed generated token |
| `mean_itl_ms` | `generation_time_ms` divided by the generated tokens after the first; tokens one speculative step commits share a completion instant, so each extra token counts as a zero-length interval |
| `tokens_per_second` | Generated tokens, as `usage` counts them, over the first scheduled step to the last committed generated token |

A step's completion instant is read once when the worker processes that step's
results, so tokens committed by one speculative step share it. The worker reads
the first scheduled step's instant after packing that step's inputs, including
an image's vision inputs, and before submitting the step. The runtime reads
model-queue arrival when it builds the request group, before publishing the group
to the worker channel, so `queue_time_ms` includes the channel send and worker
pickup and starts later than vLLM's engine-core scheduler queue.

A JSON body carries `metrics` at the top level, and a Responses stream carries it
in the `response` object of `response.completed` or `response.incomplete`. A Chat
or Completions stream carries it only on the final usage chunk, so a client that
does not send `"stream_options": {"include_usage": true}` receives none, and
gateways that read rates from the response body, such as llama-swap, show none
for those streams. Flare has no equivalent of vLLM's
`--enable-force-include-usage` server option, which forces the usage chunk and
would close this gap.

`time_to_first_content_token_ms` is always null; the key is present so the object
has vLLM's six keys. Another field is null when the request did not reach the
instants it spans: `mean_itl_ms` for a single generated token, and, for a response
with no generated token, every field except `queue_time_ms`, which is also null
when no model step included the request. In Completions, `n` greater than one
makes `metrics` null, and several prompts omit it.

A Chat request that sets `return_token_timestamps: true`, which requires
`return_token_ids: true`, receives the host instant of each generated token in
`choices[0].token_timestamps_ns`, aligned with `choices[0].token_ids`, and a
top-level `performance` object of request instants on the same process-local
origin; the [prepared model contract](../helios/model-contract.md#token-and-timing-observation)
defines both.

## Raw completions

`prompt` accepts a string, an array of strings, a token-ID array, or an array of
Expand Down
14 changes: 9 additions & 5 deletions docs/cli-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defaulting to `~/.config/flare/orbit.toml` and
`~/.config/flare/orbit/controller.key`. `flare orbit run` takes the serving
flags of `flare run` and applies them to every rank; `--host`, `--port`,
`--served-model-name`, `--scheduler-policy`, `--scheduler-terminal-value`,
`--scheduler-terminal-age-price`, and `--api-key-file` apply to rank zero. `--api-key-file` names a file rank zero must be able to read; Orbit does
`--scheduler-terminal-age-price`, `--api-key-file`, and `--enable-per-request-metrics` apply to rank zero. `--api-key-file` names a file rank zero must be able to read; Orbit does
not upload it. Core inputs are Hugging Face repositories
`ORG/NAME[@REVISION]`, controller-local files, or `NODE:/absolute/path` on a
paired node. Orbit downloads repository cores on a candidate node and
Expand Down Expand Up @@ -737,6 +737,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 vLLM's per-request `metrics` timing object to OpenAI Chat, Completions, and Responses output; see [per-request metrics](api.md#per-request-metrics). The flag can only enable the option; `[server] per_request_metrics` sets it per host | `[server] per_request_metrics`, read on rank zero's node under `flare orbit run`, 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 @@ -1333,7 +1334,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`,
`scheduler_checkpoint_extra_work_fraction`, and `per_request_metrics`,
`[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 Expand Up @@ -1364,6 +1365,7 @@ port = 8000
api_key = "" # Empty: no authentication.
# thinking_token_budget = 1536 # Optional default reasoning-token cap.
# scheduler_checkpoint_extra_work_fraction = 0.05 # Fraction of productive work for extra captures.
# per_request_metrics = false # Add vLLM's per-request `metrics` to OpenAI output.

[defaults]
model = "qwen3.8-flash"
Expand Down Expand Up @@ -1403,9 +1405,11 @@ accepts `compile_workers`, `autotune_effort`, and `checkpoint_token_file`.
Recipe preparation options—including image concurrency, speculation method,
token capacity, graph budget, quantization, and layout flags—are controlled by
the recipe's `RecipeParameters` defaults and explicit command-line flags rather
than configuration-file keys. Native Flare ignores keys it does not use, except
in `[prefix_cache]`, where it accepts only `memory`, `disk_limit`,
`drain_on_shutdown`, `max_age`, and `compression`.
than configuration-file keys. `ignition debug-serve` applies
`[server] thinking_token_budget`, `scheduler_checkpoint_extra_work_fraction`,
and `per_request_metrics` as native `flare run` does. Native Flare ignores keys
it does not use, except in `[prefix_cache]`, where it accepts only `memory`,
`disk_limit`, `drain_on_shutdown`, `max_age`, and `compression`.

`[models.<alias>]` overrides `[defaults]`; flags override both.

Expand Down
41 changes: 41 additions & 0 deletions flare-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ impl OrbitPush {
scheduler_terminal_age_price: None,
scheduler_checkpoint_extra_work_fraction: None,
bypass_performance_check: false,
enable_per_request_metrics: false,
serving: self.serving.clone(),
}
}
Expand Down Expand Up @@ -650,6 +651,11 @@ pub struct OrbitRun {
#[arg(long, value_name = "PATH", help_heading = "Serving options")]
pub api_key_file: Option<PathBuf>,

/// Add vLLM's per-request `metrics` timing object to OpenAI Chat, Completions,
/// and Responses output; rank zero's [server].per_request_metrics also enables it.
#[arg(long, help_heading = "Serving options")]
pub enable_per_request_metrics: bool,

#[command(flatten)]
pub serving: ServingOptions,
}
Expand Down Expand Up @@ -697,6 +703,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 Down Expand Up @@ -725,6 +734,7 @@ impl OrbitRun {
scheduler_terminal_age_price: self.scheduler_terminal_age_price,
scheduler_checkpoint_extra_work_fraction: self.scheduler_checkpoint_extra_work_fraction,
bypass_performance_check: false,
enable_per_request_metrics: self.enable_per_request_metrics,
serving: self.serving.clone(),
}
}
Expand Down Expand Up @@ -855,6 +865,11 @@ pub struct Run {
#[arg(long, help_heading = "Serving options")]
pub bypass_performance_check: bool,

/// Add vLLM's per-request `metrics` timing object to OpenAI Chat, Completions,
/// and Responses output; [server].per_request_metrics also enables it.
#[arg(long, help_heading = "Serving options")]
pub enable_per_request_metrics: bool,

#[command(flatten)]
pub serving: ServingOptions,
}
Expand Down Expand Up @@ -1348,6 +1363,32 @@ mod tests {
}
}

#[test]
fn per_request_metrics_flag_is_off_by_default_and_reaches_rank_zero() {
assert!(!run(&["flare", "run", "model"]).enable_per_request_metrics);
assert!(run(&["flare", "run", "model", "--enable-per-request-metrics"]).enable_per_request_metrics);
for enabled in [false, true] {
let mut arguments = vec!["flare", "orbit", "run", "model"];
if enabled {
arguments.push("--enable-per-request-metrics");
}
let Command::Orbit(orbit) = Cli::try_parse_from(arguments).unwrap().command else {
panic!()
};
let OrbitCommand::Run(orbit) = orbit.command else {
panic!()
};
assert_eq!(orbit.run_args().enable_per_request_metrics, enabled);
// Rank zero parses the forwarded options as `flare run` options.
let mut forwarded = vec!["flare".to_string(), "run".into(), "model".into()];
forwarded.extend(orbit.rank_zero_options());
let Command::Run(rank_zero) = Cli::try_parse_from(forwarded).unwrap().command else {
panic!()
};
assert_eq!(rank_zero.enable_per_request_metrics, enabled);
}
}

#[test]
fn persistent_orbit_options_preserve_saved_values_and_allow_explicit_defaults() {
use clap::{CommandFactory, FromArgMatches};
Expand Down
Loading