Skip to content
Merged
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
22 changes: 18 additions & 4 deletions docs/scheduling-runtime-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ active decoder waiting age. The surplus is valued at intrinsic
vanishes when active decode capacity is already saturated or when a queued
prefiller cannot enter decode (`max_new_tokens == 1`).

Only decoding requests have a delivery coordinate or output-age cost. Normalized
Only decoding requests have a delivery coordinate or join the common
`-T/2 * sum c_j` output-age penalty; waiting prompts with remaining output budget
participate through the first-output waiting-age credit below. Normalized
service prices follow the entropy-dual update in `scheduling-utility.md`. When a
prefilling request's maximum feasible token rate changes between chunks (for
example from a faster intermediate `PREFILL` chunk to a slower
Expand Down Expand Up @@ -264,10 +266,20 @@ For a ready inference graph, selection maximizes

```text
(sum of expected priced token and delivery service
+ sum over served decoders of c_i*sigma_i*(A_i+T)) / T
+ sum over served decoders of c_i*sigma_i*(A_i+T)
+ sum over served waiting prompts of decode_age_price*(b_served*T_dec)*A_first*frac) / T
- T/2 * sum over active decoders of c_i.
```

Here `b_served * T_dec` is the fastest pure incumbent `Decode` or `Speculative`
round's work-time in stream-milliseconds (excluding `Mixed` graphs, and zero when
no measured decoder is active); `A_first` is elapsed milliseconds from
`first_output_wait_ns` and `frac` is `1` on prompt completion or
`work / initial_prefill` on partial chunks, carried through prerequisite and
two-stage continuation scoring (`Init`, `Restore`, `Vision`, `Snapshot`). See
`scheduling-utility.md` for wait-clock preservation across anchor splits,
readmission anchoring, and inertness conditions.

All values in one decision share a positive scaling factor to keep large prices
representable. `ScheduledPlan::selection_value_rate()` exposes the scaled score;
`selection_log_scale()` exposes the logarithm of that factor. An unknown duration
Expand Down Expand Up @@ -315,8 +327,10 @@ and prompt length also restrict logical work. A graph with 64 useful prompt toke
earns 64 prompt units and at most one output token, regardless of physical capacity.
Apart from the natural-fit restriction on unmeasured pure prefill graphs
described below, candidate scoring has no smallest-fitting-shape filter,
duration ceiling, forced oldest-request filter, or per-chunk prefill lateness
cost.
duration ceiling, forced oldest-request filter, or per-chunk prefill deadline
or lateness penalty in the common `-T/2 * sum c_j` waiting sum (waiting prompts
with remaining output budget participate only through the positive first-output
waiting-age credit above).

When a prepared model registers `TERMINAL_PREFILL` graphs for a subset of
aligned prefill capacities, Helios infers the tail-protection window as the
Expand Down
7 changes: 5 additions & 2 deletions docs/scheduling-theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,11 @@ or authorize retuning on heldout seeds.
The ongoing policy uses separate intrinsic output value, token fairness,
delivery fairness, and decode-age coefficients. Their concrete defaults and
units are specified in the [native design](scheduling-runtime-design.md).
First-token waiting has no independent age penalty: prompt work competes by
its useful progress and token-service price. A burst earns its accepted token
Waiting prompts with remaining output budget do not carry a delivery coordinate
or join the common `-T/2 * sum c_j` waiting penalty; when `decode_age_price > 0`
and active decoders are present, they instead receive a first-output waiting-age
credit scaled by the incumbent decode round work-time `b_served * T_dec` (see
[scheduling-utility.md](scheduling-utility.md)). A burst earns its accepted token
volume and one delivery. The delivery reference accounts for feasible batching;
changing a rate normalizer preserves marginal service prices across phases.
Helios adds a value and an age price for terminal retirement, which the
Expand Down
37 changes: 37 additions & 0 deletions docs/scheduling-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,43 @@ oversubscribed decode batch (`K > b`) trades round duration against the waiting
cost of its excluded peers. No duration filter, preferred chunk size, or
request-count branch is involved.

### First-output waiting age against active decoders

When `decode_age_price > 0` and at least one measured active decoder exists,
prompts waiting to produce their first output (`consumed_tokens < prompt_tokens`
and `max_new_tokens > 0`) receive a first-output waiting-age credit scaled by
the incumbent decode cohort's fastest round work-time `b_served * T_dec`
(where `b_served = min(batch_capacity, K_dec)` and `T_dec` is the measured
duration in milliseconds of the decode or speculative graph minimizing
`T_dec / b_served`):

```text
first_output_credit = decode_age_price * (b_served * T_dec) * A_first * frac.
```

Here `A_first` is elapsed milliseconds since the prompt's first-output wait
clock (`first_output_wait_ns`, initialized at arrival, advanced on committed
progress, projected across any queued in-flight prefill submission, and
anchored to the most recent output publication across preemption/readmission,
including host-published forced reasoning closure).
On a step that completes the prompt (`scheduled_consumed + work == prompt_tokens`),
`frac = 1`. On a non-finishing prefill chunk, `frac = work / initial_prefill`,
matching coalescing's fixed-denominator amortization so partial chunks remain
linear in `work` and never favor smaller inefficient capacities. Because the
credit uses pure waiting age `A_first`, omits waiting prompts from the common
`-T/2 * sum c_j` waiting-penalty sum, and excludes `Mixed` graphs from the
incumbent pure-decode reference `(b_served, T_dec)`, it vanishes at `A_first = 0`
and stays bounded under oversubscribed (`K > B`) and small-batch (`B = 1`) bursts
because `b_served` counts only incumbent decoders.
When a prefill stops at an armed interior `RetentionRole::Anchor` cut on a
prompt that otherwise fit in a single eligible prefill graph, `first_output_wait_ns`
is preserved across the forced split and boundary snapshot (even when the anchor
endpoint coincides with the chosen graph capacity, since the anchor caps larger
buckets to the same work) while `ServicePrice`
continues to charge all measured token service truthfully. Under
`decode_age_price = 0`, zero active decoders, or score-only `prompt_logprobs`
(`max_new_tokens = 0`), the term evaluates to zero.

For a fixed physical graph, the excluded-stream cost depends on its duration,
not cohort membership. Its best cohort therefore contains the largest additive
lane values. Rust uses a bounded array to select these lanes; it does not
Expand Down
52 changes: 36 additions & 16 deletions helios/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ impl LiveRequest {
pub fn reused_prompt_tokens(&self) -> u64 {
self.admission_reused_tokens
}
pub(super) fn initial_prefill_tokens(&self) -> usize {
self.prompt_tokens
.saturating_sub(self.admission_reused_tokens as usize)
.max(1)
}
pub fn snapshot_destination(&self) -> SnapshotId {
self.boundary_capture
.map(|c| c.snapshot)
Expand Down Expand Up @@ -2669,18 +2674,18 @@ impl RequestScheduler {
let mut window_snapshots = Vec::new();
for (row, lane) in step.lanes.iter().enumerate() {
let kind = step.lane_kind(row);
let Ok(request) = self.request_mut(lane.request) else {
continue;
};
request.pending -= 1;
let record = &records[lane.request.slot as usize];
if matches!(
kind,
GraphKind::Init
| GraphKind::Restore
| GraphKind::Snapshot
| GraphKind::Vision
) {
let record = &records[lane.request.slot as usize];
let Ok(request) = self.request_mut(lane.request) else {
continue;
};
request.pending -= 1;
if record.status == 3 {
request.error_code = Some(record.error_code);
request.terminal_snapshot_ready = false;
Expand Down Expand Up @@ -2708,10 +2713,29 @@ impl RequestScheduler {
}
continue;
}
let record = &records[lane.request.slot as usize];
let finished =
record.status == 3 || ((record.status >= 2 || record.generated_tokens == request.max_new_tokens as i64)
&& record.consumed_tokens >= request.prompt_tokens as i64);
let (finished, prefill, output, preserve_first_output_wait) =
match self.request(lane.request) {
Ok(request) => {
let finished = record.status == 3
|| ((record.status >= 2
|| record.generated_tokens == request.max_new_tokens as i64)
&& record.consumed_tokens >= request.prompt_tokens as i64);
let prefill = if kind.is_prefill() {
record.consumed_tokens as u64 - request.consumed_tokens
} else {
0
};
let output =
(record.generated_tokens - request.generated_tokens as i64) as u32;
let preserve = self.preserves_first_output_wait(
kind, request, record, finished, prefill, output,
);
(finished, prefill, output, preserve)
}
Err(_) => continue,
};
let request = self.request_mut(lane.request).unwrap();
request.pending -= 1;
if matches!(kind, GraphKind::Speculative)
&& record.status != 3
{
Expand Down Expand Up @@ -2750,14 +2774,10 @@ impl RequestScheduler {
if record.status == 3 {
request.error_code = Some(record.error_code);
}
let prefill = if kind.is_prefill() {
record.consumed_tokens as u64 - request.consumed_tokens
} else {
0
};
let output = (record.generated_tokens - request.generated_tokens as i64) as u32;
if record.status != 3 {
request.accounting.credit(prefill, output, now_ns);
request
.accounting
.credit(prefill, output, now_ns, preserve_first_output_wait);
useful_tokens[lane.request.slot as usize] = prefill + u64::from(output);
}
if kind == GraphKind::TerminalPrefill && record.status != 3 {
Expand Down
Loading
Loading