Skip to content
Open
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
88 changes: 84 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
4 changes: 4 additions & 0 deletions helios/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub struct SchedulerCapabilities {
pub struct SchedulerStats {
pub cache_lookups: u64,
pub cache_hits: u64,
/// Prompt tokens of admitted requests offered to GPU prefix lookups.
pub cache_lookup_tokens: u64,
pub reused_tokens: u64,
pub snapshot_publications: u64,
pub snapshot_evictions: u64,
Expand Down Expand Up @@ -1555,6 +1557,7 @@ impl RequestScheduler {
} = plan;
// Lookups count once per admitted request, not per attempt of a waiting one.
let (hit, reused) = (lookup.checkpoint.is_some(), lookup.consumed_tokens);
let looked_up = if spec.prompt_logprobs { 0 } else { spec.prompt.len() as u64 };
let page_tokens = self.capabilities.page_tokens as u64;
if let Some(inbound) = &inbound {
let consumed = inbound.consumed_tokens;
Expand Down Expand Up @@ -1761,6 +1764,7 @@ impl RequestScheduler {
ticket.role = ticket.role.max(role);
}
self.stats.cache_lookups += u64::from(!spec.prompt_logprobs);
self.stats.cache_lookup_tokens += looked_up;
self.stats.cache_hits += u64::from(hit);
self.stats.reused_tokens += reused;
if inbound.is_none()
Expand Down
7 changes: 7 additions & 0 deletions helios/src/scheduler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ fn terminal_checkpoint_full_prompt_hit_restores_and_resumes_without_prefill() {
(stats.cache_lookups, stats.cache_hits, stats.reused_tokens),
(3, 2, 128)
);
// Three admitted 64-token prompts were looked up, whether or not they hit.
assert_eq!(stats.cache_lookup_tokens, 192);
assert_eq!(
(
stats.active_requests,
Expand Down Expand Up @@ -3238,11 +3240,16 @@ fn invalid_inbound_requests_reserve_nothing_and_planned_admission_matches_admit(
assert_eq!(plan.resident_tokens(), 0);
// Lookups count once per admitted request; the failed attempts above count none.
assert_eq!(scheduler.stats().cache_lookups, 0);
assert_eq!(scheduler.stats().cache_lookup_tokens, 0);
let admitted = scheduler
.admit_planned(request.clone(), plan, None)
.unwrap();
assert!(admitted.ticket.is_none());
assert_eq!(scheduler.stats().cache_lookups, 1);
assert_eq!(
scheduler.stats().cache_lookup_tokens,
request.prompt.len() as u64
);
let live = scheduler.request(admitted.handle).unwrap();
assert_eq!(live.phase, RequestPhase::Initialize);
assert_eq!(live.consumed_tokens, 0);
Expand Down
1 change: 1 addition & 0 deletions helios/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ async fn admit_http(
Err(IngressRejection::Paused) => return http::error(protocol, StatusCode::SERVICE_UNAVAILABLE, "HTTP admission is paused"),
Ok(permit) => Arc::new(permit),
Err(IngressRejection::Full) => {
state.model.metrics().admission_rejected(metrics::AdmissionLimit::HttpSlots);
let mut message = format!(
"native HTTP admission is full: {} requests are active or queued",
state.ingress_capacity
Expand Down
14 changes: 13 additions & 1 deletion helios/src/server/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(super) async fn generate(
request: Request,
) -> Response {
let admitted_at = request.extensions().get::<super::AdmittedAt>().map(|at| at.0).unwrap_or_else(Instant::now);
let mut first_response = state.first_response.observe(admitted_at);
let mut first_response = state.first_response.observe(admitted_at, state.model.metrics_handle());
let ingress_ns = observation::monotonic_ns();
let protocol = Protocol::from_path(request.uri().path());
let count = request.uri().path() == "/v1/messages/count_tokens";
Expand Down Expand Up @@ -234,6 +234,10 @@ pub(super) async fn generate(
.clone()
.try_acquire_many_owned((size - 1) as u32)
.map_err(|_| {
prepare_state
.model
.metrics()
.admission_rejected(super::metrics::AdmissionLimit::HttpSlots);
(
StatusCode::TOO_MANY_REQUESTS,
"native generation admission is full".into(),
Expand Down Expand Up @@ -595,6 +599,14 @@ pub(super) async fn generate(
false,
);
}
// Choices the runtime cancelled after another choice reached the
// parallel-tool-call limit are counted as cancelled there, so they enter no
// response histogram.
state.model.metrics().response_completed(
admitted_at.elapsed().as_nanos() as u64,
decoded.request.choices,
&encoder.choice_generated_tokens(),
);
yield Delivery::Complete(response);
};
if streaming {
Expand Down
39 changes: 28 additions & 11 deletions helios/src/server/latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ struct Samples {
dropped_at: Option<Instant>,
}
#[derive(Default)]
pub(super) struct FirstResponseSamples(Mutex<Samples>);
pub(super) struct FirstResponseSamples {
window: Mutex<Samples>,
}
impl Samples {
fn expire(&mut self, now: Instant) {
while self
Expand All @@ -58,16 +60,23 @@ impl Samples {
}
}
impl FirstResponseSamples {
pub(super) fn observe(self: &Arc<Self>, started: Instant) -> FirstResponse {
/// Starts one response's observation, which records into this window and the
/// all-time `flare_time_to_first_response_seconds` histogram of `metrics`.
pub(super) fn observe(
self: &Arc<Self>,
started: Instant,
metrics: Arc<super::metrics::Metrics>,
) -> FirstResponse {
FirstResponse {
samples: self.clone(),
metrics,
started,
recorded: false,
}
}
pub(super) fn snapshot(&self) -> FirstResponseSnapshot {
let (mut seconds, truncated) = {
let mut samples = self.0.lock().unwrap_or_else(|e| e.into_inner());
let mut samples = self.window.lock().unwrap_or_else(|e| e.into_inner());
samples.expire(Instant::now());
(
samples
Expand Down Expand Up @@ -98,14 +107,18 @@ impl FirstResponseSamples {
}
pub(super) struct FirstResponse {
samples: Arc<FirstResponseSamples>,
metrics: Arc<super::metrics::Metrics>,
started: Instant,
recorded: bool,
}
impl FirstResponse {
pub(super) fn output(&mut self) {
if !self.recorded {
let mut samples = self.samples.0.lock().unwrap_or_else(|e| e.into_inner());
samples.record(self.started, Instant::now());
let now = Instant::now();
let mut samples = self.samples.window.lock().unwrap_or_else(|e| e.into_inner());
samples.record(self.started, now);
self.metrics
.first_response(now.saturating_duration_since(self.started).as_nanos() as u64);
self.recorded = true;
}
}
Expand Down Expand Up @@ -176,13 +189,13 @@ mod tests {
assert_eq!(empty.samples, 0);
let now = Instant::now();
{
let mut values = samples.0.lock().unwrap();
let mut values = samples.window.lock().unwrap();
for seconds in [4, 1, 2, 3] {
values.values.push_back((now, Duration::from_secs(seconds)));
}
}
assert_eq!(samples.snapshot().median_seconds, Some(2.5));
samples.0.lock().unwrap().expire(now + WINDOW);
samples.window.lock().unwrap().expire(now + WINDOW);
assert_eq!(samples.snapshot().median_seconds, None);
}

Expand All @@ -191,7 +204,7 @@ mod tests {
let samples = FirstResponseSamples::default();
let now = Instant::now();
{
let mut values = samples.0.lock().unwrap();
let mut values = samples.window.lock().unwrap();
for _ in 0..=CAPACITY {
values.record(now, now);
}
Expand All @@ -200,7 +213,7 @@ mod tests {
assert_eq!(snapshot.samples, CAPACITY as u64);
assert_eq!(snapshot.window_seconds, 60);
assert!(snapshot.truncated);
samples.0.lock().unwrap().expire(now + WINDOW);
samples.window.lock().unwrap().expire(now + WINDOW);
let expired = samples.snapshot();
assert_eq!(expired.samples, 0);
assert!(!expired.truncated);
Expand All @@ -209,13 +222,17 @@ mod tests {
#[test]
fn first_response_records_once_and_excludes_unoffered_output() {
let samples = Arc::new(FirstResponseSamples::default());
drop(samples.observe(Instant::now()));
let metrics = Arc::new(super::super::metrics::Metrics::default());
drop(samples.observe(Instant::now(), metrics.clone()));
assert_eq!(samples.snapshot().samples, 0);
let mut response = samples.observe(Instant::now());
let mut response = samples.observe(Instant::now(), metrics.clone());
response.output();
response.output();
assert_eq!(samples.snapshot().samples, 1);
assert!(samples.snapshot().median_seconds.is_some());
assert!(metrics
.render()
.contains("\nflare_time_to_first_response_seconds_count 1\n"));
}

#[test]
Expand Down
Loading