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
75 changes: 53 additions & 22 deletions docs/scheduling-runtime-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,16 @@ 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.
`scheduling-utility.md` for anchor-split preservation, readmission anchoring,
and inertness conditions. Under an active age-priced stream
(`decode_age_price > 0`), non-terminal `Prefill` chunks without a checkpoint
capture also preserve `first_output_wait_ns` across chunks whenever the
request's uncached prompt at admission fits in one eligible prefill graph
(`TerminalPrefill` on `TERMINAL_PREFILL` cores). When such a prompt holds
deferred prefill state and a `TerminalPrefill` chunk lands on an interior
checkpoint cut before `prompt_tokens`, `first_output_value` credits the
reconciled segment since `prefix_tokens` (`(end - prefix_tokens) / initial_prefill`)
while token-work credit stays proportional to that chunk's tokens.

All values in one decision share a positive scaling factor to keep large prices
representable. `ScheduledPlan::selection_value_rate()` exposes the scaled score;
Expand Down Expand Up @@ -318,17 +326,21 @@ prompt row. When no
quote fails, estimated and submitted work agree. Storage shortage can change
which cuts fit the work budget, so the estimate and quoted selection can differ
in either direction. If the quoted work differs from the winning estimate, an
ordinary prefill or mixed plan advances toward the quoted cut up to the catalog
maximum and uses the smallest catalog capacity covering that work, with duration
and value recomputed. Mixed plans resize only the prompt capacity among shapes
ordinary mixed plan—or a pure prefill plan with `age_price == 0` or required
terminal completion—advances toward the quoted cut up to the catalog maximum,
whereas an age-priced non-terminal prefill caps growth at the winning
candidate's capacity; both paths use the smallest eligible catalog capacity
covering that work (restricting `deferred_prefill` requests to
`TERMINAL_PREFILL` capacities), with duration and value recomputed. Mixed plans
resize only the prompt capacity among shapes
with the same batch capacity and decode width; decode lanes retain their token
counts. If a required lookup is unavailable, it retains the winning candidate
and clips work to that candidate's capacity. Refresh and discovery plans
retain their capacities and clip work to fit. Atomic image spans, feature windows,
and prompt length also restrict logical work. A graph with 64 useful prompt tokens
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,
Apart from the unmeasured pure prefill discovery and interpolated exploration
rules described below, candidate scoring has no smallest-fitting-shape filter,
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
Expand All @@ -343,9 +355,13 @@ penultimate chunk leaving at most the tail-protection window, while earlier
chunks run `PREFILL`. Committing a non-terminal `PREFILL` chunk at a capacity
present in the terminal catalog marks the request as holding deferred
continuation state until a `TERMINAL_PREFILL` chunk completes. While deferred
state is active, the scheduler excludes the request from `MIXED` graphs and
suppresses checkpoint and early-retirement snapshot capture so incomplete
continuation state is never published. Checkpoint cut budgeting prices
state is active, the scheduler excludes the request from `MIXED` graphs and from
prefill capacities absent from `TERMINAL_PREFILL`, and suppresses checkpoint and
early-retirement snapshot capture so incomplete continuation state is never
published. While active age-priced streams exist, requests whose remaining work
fits inside the largest terminal capacity still allow legal non-terminal
`PREFILL` chunks rather than requiring one monolithic `TERMINAL_PREFILL` step.
Checkpoint cut budgeting prices
non-terminal and terminal chunks using their separate measured durations with
sibling fallback when only one operation is measured.

Expand Down Expand Up @@ -478,12 +494,25 @@ Host dispatch, completion delivery, and polling time do not enter a graph's cost
Missing or zero device intervals neither change an estimate nor make it fresh.

Pure prefill exploration restricts unmeasured graphs (`PREFILL`,
`TERMINAL_PREFILL`, and `SCORED_PREFILL`) to the natural-fit capacity: the
smallest registered catalog capacity that achieves the maximum single-step
token work through the next checkpoint cut, atomic span, or prompt endpoint
(respecting terminal-completion requirements). Smaller unmeasured prefill
shapes do not preempt larger fitting graphs during cold discovery, and larger
padded unmeasured shapes that consume no additional tokens are excluded.
`TERMINAL_PREFILL`, and `SCORED_PREFILL`) to the natural-fit capacity when no
active age-priced streams exist: the smallest registered catalog capacity that
achieves the maximum single-step token work through the next checkpoint cut,
atomic span, or prompt endpoint (respecting terminal-completion requirements).
Smaller unmeasured prefill shapes do not preempt larger fitting graphs during
cold discovery, and larger padded unmeasured shapes that consume no additional
tokens are excluded. When active age-priced streams (decoding, resume, or
terminal cleanup) exist and a measured sibling (`PREFILL` or `TERMINAL_PREFILL`)
or strictly larger measured peer plus a positive lower floor (a smaller measured
prefill peer or the fastest measured decode step) is available, unmeasured
pure-prefill capacities up to the natural fit compete by `ValueRate` using that
positive interpolated GPU estimate instead of zero-duration discovery priority.
Their first execution still drains the queue (`!is_fresh`), commits as
`TimingOrigin::Discovery` without earning refresh credit, and records the actual
GPU replay duration in `ActionCosts`. On `TERMINAL_PREFILL` catalogs, requests
whose remaining work fits inside the largest terminal capacity still allow
legal non-terminal `PREFILL` chunks leaving more than the tail-protection window
while active age-priced streams exist, while keeping non-terminal-catalog shapes
excluded whenever `deferred_prefill` is active.
Measured prefill graphs of every capacity remain eligible according to their
observed costs and funded timing refresh.

Expand Down Expand Up @@ -620,7 +649,9 @@ owned through their last submitted fence.
The transport has two frame slots. Ordinary decode, complete speculative
generation, and consecutive nonterminal `PREFILL` chunks may occupy both when
they neither reach prompt completion or a conditioned-window limit nor arm or
land on a checkpoint cut. Terminal prefill (`TERMINAL_PREFILL`), scored prefill,
land on a checkpoint cut, and only when no active age-priced decoding, resume,
or terminal-cleanup stream exists so active decoders re-compete with actual
completion feedback after every prefill chunk. Terminal prefill (`TERMINAL_PREFILL`), scored prefill,
mixed execution, resume, vision, and state operations drain the window. Unknown
or stale costs, grammar, copy-only proposals, host-fed pending tokens or
committed cursors, history inputs, and phase transitions also require completion
Expand All @@ -640,11 +671,11 @@ estimates retained for dispatch ranking. Pricing skips unmeasured capacities
that consume no additional tokens over a smaller capacity, and unmeasured
capacities other than the chunk's pricing capacity: the smallest catalog
capacity covering the tokens remaining before the chunk's limit, falling back
to the largest catalog capacity when none does. Pure prefill dispatch discovers
only the natural-fit capacity, and an atomic span can make the natural fit
smaller than the pricing capacity. An unmeasured pricing capacity that consumes
additional tokens leaves the prefill cost unknown, applying the unknown-cost
anchor and extra-cut rules in
to the largest catalog capacity when none does. Pure prefill dispatch follows
the natural-fit exploration limits in [Duration estimates](#duration-estimates),
and an atomic span can make the natural fit smaller than the pricing capacity.
An unmeasured pricing capacity that consumes additional tokens leaves the
prefill cost unknown, applying the unknown-cost anchor and extra-cut rules in
[exact endpoint capture](core-design.md#exact-endpoint-capture). Productive
completed decode earns the same fraction of measured time for a distinct
terminal capture. There is no fixed capture count or concurrency-based snapshot
Expand Down
21 changes: 18 additions & 3 deletions docs/scheduling-theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ preference from hardware cost or select a production default.

All pure prefill, pure decode, and available mixed graphs compete on this score.
No duration ceiling, prefill size preference, or breadth-before-depth rule
precedes it. A graph consuming 64 useful prompt tokens earns 64 prefill units
whether its capacity is 64 or 4096. Inactive rows and rejected drafts earn zero.
Completing prefill emits one first token, counted once in `D_i`.
precedes it (cold discovery of unmeasured pure-prefill shapes follows
[scheduling-runtime-design.md](scheduling-runtime-design.md#duration-estimates)).
A graph consuming 64 useful prompt tokens earns 64 prefill units whether its
capacity is 64 or 4096. Inactive rows and rejected drafts earn zero. Completing
prefill emits one first token, counted once in `D_i`.

If conditional acceptance at draft position `j` is `q_ij`, a verification width
`k` has expected output, before EOS truncation,
Expand Down Expand Up @@ -557,6 +559,19 @@ earn or spend neither exploration allowance. Measured costs remain available aft
This option varies initial discovery independently of the operational mean and
subsequent remeasurement policy.

The `initial_discovery = "interpolated"` alternative preserves `native` discovery
whenever `age_price == 0` or no active decoding stream is resident. When
`age_price > 0` with active decoding streams, it estimates unmeasured pure-prefill
capacities at or below natural fit by linear interpolation between the nearest
measured smaller pure-prefill peer (or the fastest measured decode duration as a
zero-token floor) and the nearest strictly larger measured pure-prefill peer,
clamping non-monotonic timings to the larger peer. Interpolated unmeasured prefill
candidates compete on value rate without polluting measured service-price
normalizers, execute as bootstrap when selected (never displaced by funded stale
refresh and neither earning nor spending exploration allowance), and match the
Helios interpolated prefill-discovery rule in
[the scheduling runtime design](scheduling-runtime-design.md).

Funded policies start with zero credit. A valid ordinary completion earns
`alpha / (1 - alpha)` times its elapsed duration, capped at 5 ms by default,
with `alpha = 0.02`. A probe requires the full cap of credit, then pays its
Expand Down
13 changes: 9 additions & 4 deletions helios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ subranges into a free host frame, enqueues asynchronous uploads and graph
execution, records a production event, and queues the completion transfer on
the copy stream behind that event. Omitted input ranges preserve device state.
`poll` returns ordered `FrameCompletion` records after transfer completion and
then permits frame reuse. Only ordinary decode and complete speculative
generation can share the two-frame window; other operations drain it. A third
then permits frame reuse. Only ordinary decode, complete speculative generation, and non-terminal
`PREFILL` without active age-priced streams (or checkpoint and completion
barriers) can share the two-frame window; other operations drain it. A third
submission receives backpressure; a grammar submission requires an empty window and blocks further submissions until its
completion is consumed. The direct executor has no Python calls or per-step
CUDA allocation.
Expand Down Expand Up @@ -422,8 +423,12 @@ the cost becomes stale but remains available for selection. The next valid
observation replaces the stale estimate. Tensor-parallel observations use the
maximum positive rank interval, with measured embedding-readiness waits subtracted
when available. Host delays and queue wait do not enter graph estimates. An
unmeasured candidate ranks ahead of every measured candidate; unmeasured
candidates compete among themselves by expected useful value. Both
unmeasured candidate with no duration estimate ranks ahead of every measured
candidate and competes with other indeterminate candidates by expected useful
value; when active age-priced streams exist and measured GPU timings provide a
sibling or bracketing estimate, unmeasured pure-prefill capacities up to the
natural fit instead compete by interpolated `ValueRate` while still draining on
their first execution. Both
unmeasured and stale physical dispatches require an empty queue and completion
before another submission. When multiple packed speculative shapes cover a
`(batch, width)` duration lookup, Helios uses the minimum positive measured
Expand Down
96 changes: 86 additions & 10 deletions helios/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ pub struct RequestScheduler {
speculative_catalog: Vec<(usize, Vec<usize>)>,
prefill_catalog: Vec<usize>,
terminal_prefill_catalog: Vec<usize>,
terminal_prefill_window: usize,
scored_prefill_catalog: Vec<usize>,
mixed_catalog: Vec<(usize, usize, usize)>,
forecasts: rounds::Forecasts,
Expand Down Expand Up @@ -753,6 +754,7 @@ impl RequestScheduler {
speculative_catalog: Default::default(),
prefill_catalog: prefill_capacities(limits.prefill_chunk_size).collect(),
terminal_prefill_catalog: Vec::new(),
terminal_prefill_window: 0,
scored_prefill_catalog: Vec::new(),
mixed_catalog: Vec::new(),
forecasts,
Expand Down Expand Up @@ -803,6 +805,7 @@ impl RequestScheduler {
);
}
self.prefill_catalog = catalog;
self.recompute_terminal_prefill_window();
Ok(())
}

Expand Down Expand Up @@ -837,23 +840,29 @@ impl RequestScheduler {
);
}
self.terminal_prefill_catalog = catalog;
self.recompute_terminal_prefill_window();
Ok(())
}

fn recompute_terminal_prefill_window(&mut self) {
self.terminal_prefill_window = if self.terminal_prefill_catalog.is_empty() {
0
} else {
self.prefill_catalog
.iter()
.copied()
.filter(|capacity| self.terminal_prefill_catalog.binary_search(capacity).is_err())
.max()
.unwrap_or(0)
};
}

pub(super) fn is_non_terminal_prefill(&self, kind: GraphKind, capacity: usize) -> bool {
kind == GraphKind::Prefill && self.terminal_prefill_catalog.binary_search(&capacity).is_ok()
}

pub(super) fn terminal_prefill_window(&self) -> usize {
if self.terminal_prefill_catalog.is_empty() {
return 0;
}
self.prefill_catalog
.iter()
.copied()
.filter(|capacity| self.terminal_prefill_catalog.binary_search(capacity).is_err())
.max()
.unwrap_or(0)
self.terminal_prefill_window
}

pub(super) fn prefill_cursor(request: &LiveRequest) -> usize {
Expand Down Expand Up @@ -890,7 +899,7 @@ impl RequestScheduler {
let needs_terminal =
end >= next_stop || (window > 0 && next_stop.saturating_sub(end) <= window);
if self.terminal_prefill_catalog.binary_search(&capacity).is_err() {
return if request.deferred_prefill && needs_terminal {
return if request.deferred_prefill {
GraphKind::TerminalPrefill
} else {
GraphKind::Prefill
Expand Down Expand Up @@ -948,6 +957,70 @@ impl RequestScheduler {
.is_ok()
}

/// Whether no legal non-terminal `Prefill` capacity can advance `request` from `start`.
/// Terminal-capable `Prefill` shapes absent from `terminal_prefill_catalog` remain legal
/// when `!request.deferred_prefill`, alongside terminal-catalog chunks that stop before
/// the tail-protection window and `next_stop`.
pub(super) fn prefill_must_complete_terminally_from(
&self,
request: &LiveRequest,
start: usize,
cut: Option<usize>,
) -> bool {
if !self.prefill_requires_terminal_completion_from(request, start, cut) {
return false;
}
let catalog = if request.deferred_prefill {
&self.terminal_prefill_catalog
} else {
&self.prefill_catalog
};
let limit = if request.deferred_prefill { 0 } else { self.terminal_prefill_window };
for &capacity in catalog {
let work = self.prefill_work_from(request, start, capacity, cut);
if work == 0 {
continue;
}
if self.resolve_prefill_kind_from(request, start, capacity, work, cut)
== GraphKind::Prefill
{
return false;
}
if capacity >= limit {
return true;
}
}
true
}

pub(super) fn has_active_age_priced_stream(&self) -> bool {
self.slots.iter().filter_map(|s| s.request.as_ref()).any(|r| {
if policy::terminal_cleanup(r) {
self.policy.terminal_age_price > 0.0
} else {
self.policy.decode_age_price > 0.0
&& matches!(r.phase, RequestPhase::Decode | RequestPhase::Resume)
}
})
}

pub(super) fn prefill_requires_terminal_completion_for_age(
&self,
request: &LiveRequest,
cut: Option<usize>,
age_price: f64,
) -> bool {
if age_price > 0.0 {
self.prefill_must_complete_terminally_from(
request,
Self::prefill_cursor(request),
cut,
)
} else {
self.prefill_requires_terminal_completion(request, cut)
}
}

pub fn snapshot_slot(&self, snapshot: SnapshotId) -> StateSlotId {
StateSlotId((1 + self.limits.max_active * self.execution_rows()) as u32 + snapshot.0)
}
Expand Down Expand Up @@ -1112,6 +1185,9 @@ impl RequestScheduler {
}

fn prefill_step_requires_feedback(&self, plan: &ScheduledPlan) -> bool {
if self.has_active_age_priced_stream() {
return true;
}
if plan
.checkpoint_plans
.iter()
Expand Down
Loading