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
58 changes: 36 additions & 22 deletions docs/scheduling-runtime-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,43 @@ When pricing candidate shapes on a GPU-confidence model, the stored per-request
confidence forecast is adjusted by two online corrections derived solely from
completed rounds:

1. **Hierarchical per-request, per-depth drafter calibration (`RequestCalibration`
+ `DepthCalibration`):** A slow round-level global prior `DepthCalibration`
(`clamp(realized / predicted, 0.0, 2.0)`, defaulting to `1.0` when
`predicted <= 1e-6`, initialized at `realized == predicted == 0.5^d` with
prior weight `4.0`, updated **once per completed round** from the mean
realized and predicted survival across contributing lanes with EWMA cap
`64.0`) provides instant model-wide protection for brand-new requests (e.g.,
if a drafter breaks globally) while preventing a single correlated
1. **Hierarchical per-request, per-step drafter calibration (`RequestCalibration`
+ `DepthCalibration`):** Calibration models the per-step conditional ratio
`clamp(realized / predicted, 0.0, 4.0)` (`CALIBRATION_FACTOR_MAX = 4.0`,
defaulting to `1.0` when `predicted <= 1e-6`) from offered, determined prefix
outcomes computed once in `complete_inner` (Rao-Blackwellized with
`completion_speculative_survival` when reported, else binary
acceptance/rejection). For each lane at depth `d`, let `w_d` be the preceding
depth's realized prefix survival clamped to `[0, 1]` (with `w_0 = 1.0`). When
`w_d > 1e-6`, the conditional realized step probability
`clamp(realized_d / w_d, 0.0, 1.0)` and raw per-step GPU confidence
`clamp(step_c_d, 0.0, 1.0)` supply an observation of weight `w_d`. A slow
round-level global prior `DepthCalibration` (initialized at
`realized == predicted == 0.5` with prior weight `4.0` and marked unobserved,
updated **once per completed round** from the contributing lanes'
survival-weighted conditional means with round weight
`clamp(sum(w_d) / count, 0.0, 1.0)` and EWMA cap `64.0`) provides immediate
model-wide protection for new requests while preventing a single correlated
large-batch dip from overwriting the prior in one step. Each live request
maintains its own aged per-depth `RequestCalibration` (seeded
scale-invariantly at `anchor = max(predicted, 0.05)` with prior weight `2.0`
from the live global factor on its first observation at that depth, EWMA cap
`32.0`, 128-token half-life aging matching `PrefixEstimate`) so sequential
workloads, context lengths, and heterogeneous concurrent lanes do not bleed
calibration across requests, and censored unobserved depths decay their prior
weight so a single funded acceptance probe can escape stale priors. Updates
use the exact offered, determined prefix outcomes computed once in
`complete_inner` (Rao-Blackwellized with `completion_speculative_survival`
when reported, else binary acceptance/rejection). Pricing multiplies each
depth's stored mean by the request's calibration factor, adds the Hoeffding
optimistic margin using the minimum aged weight of the confidence forecast
and verification calibration during funded acceptance learning, clamps to
`[0, 1]`, and enforces nonincreasing prefix survival across depths.
maintains its own aged per-step `RequestCalibration` (seeded
scale-invariantly at `anchor = max(cond_pred, 0.05)` and
`realized = clamp(anchor * prior_factor, 0.0, 1.0)` with decayed prior weight
`2.0` on its first observation at that depth, updated with sample weight
`w_d`, EWMA cap `32.0`, and 128-token half-life aging matching
`PrefixEstimate`) so sequential workloads, context lengths, and heterogeneous
concurrent lanes do not bleed calibration across requests, and unobserved
depths decay their prior weight so a single funded acceptance probe can
escape stale priors. When a depth has no request-local observation, its
per-step factor (and first-observation seed `prior_factor`) uses the global
`DepthCalibration` at that depth if observed; otherwise it inherits the
deepest observed shallower depth (`prev` from `depth - 1` down to `0`,
preferring the request's local factor over the global factor at each depth),
defaulting to `1.0` when no shallower depth has been observed. Pricing
multiplies each depth's stored cumulative prefix mean by the cumulative
product of per-step calibration factors across `0..=depth`, adds the
Hoeffding optimistic margin using the minimum aged weight of the confidence
forecast and verification calibration during funded acceptance learning,
clamps to `[0, 1]`, and enforces nonincreasing prefix survival across depths.
2. **Cross-lane order-statistic allocation surplus (`SurplusHistory`):** Inside
a packed GPU-allocated round (`B >= 2`, `P < B * W`, `depth >= 1`), the
device allocator observes fresh per-step confidences across all active lanes
Expand Down
156 changes: 93 additions & 63 deletions docs/scheduling-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,50 @@ allocation results below assume a frozen set of backlogged requests.
## Progress and delivery are different services

Let `x_i` be request `i`'s useful-token rate, counting consumed prompt tokens and
emitted output tokens. Let `z_i` be its output-delivery rate while decoding.
A burst of eight accepted tokens earns eight output units and one delivery.
Rejected drafts, padding, and inactive rows earn neither service. An unfinished
prefill chunk earns prompt progress and no delivery.
emitted output tokens. Let `s_i in (0, 1]` be its served delivery-time share
while decoding: the fraction of wall time spent in rounds that deliver visible
output to stream `i`. A served decode round of duration `T` that emits eight
tokens earns eight output units and `T` milliseconds of served delivery time
(rate `1`); an excluded round of duration `T` earns zero delivery time
(rate `0`). Rejected drafts, padding, and inactive rows earn neither service.
An unfinished prefill chunk earns prompt progress and no delivery share.

The stationary rate utility is

```text
F = intrinsic useful work per millisecond
+ sum_i f_i log(x_i / m_i)
+ sum_{i in decode} g_i log(z_i / d_i).
+ sum_{i in decode} g_i log(s_i).
```

Intrinsic work is `sum_i w_i(P_i + beta D_i)`. The constants `m_i` and `d_i`
are maximum individually feasible token and delivery rates from the catalog.
They normalize the logarithms; they do not set intrinsic token values. Holding
the catalog fixed, these normalizations only add constants to `F`.
Intrinsic work is `sum_i w_i(P_i + beta D_i)`. The constant `m_i` is the
maximum individually feasible token rate from the catalog; it normalizes the
token logarithm without setting intrinsic token values. Delivery share `s_i` is
dimensionless with maximum rate `1`. Holding the catalog fixed, normalizations
only add constants to `F`.

`beta` prices an output token relative to a prompt token. `f_i` and `g_i` price
token-rate fairness and delivery-rate fairness in value units per millisecond.
The experiment uses `f_i = w_i * token_fairness` and
token-rate fairness and served delivery-share fairness in value units per
millisecond. The experiment uses `f_i = w_i * token_fairness` and
`g_i = w_i * delivery_fairness`. A zero coefficient disables its utility term.

The gradient prices are

```text
prompt price_i = w_i + f_i / x_i
output price_i = w_i * beta + f_i / x_i
delivery price_i = g_i / z_i.
delivery price_i = g_i / s_i.
```

Summing these prices times expected service and dividing by expected graph time
gives the supporting-direction calculation for `F`. Decode value remains in
the calculation; it does not cancel as it does in a finite episode where every
request must finish and collect a fixed total reward.
In candidate scoring over a round of duration `T`, a served decoder earns
`delivery price_i * T`, which divides by `T` to a constant `+g_i / s_i`
independent of `T`, while an excluded decoder earns zero. Delivery fairness
therefore prioritizes skipped or underserved decoders against competing work
without penalizing longer, higher-throughput speculative rounds when no stream
is excluded. Summing these prices times expected service and dividing by
expected graph time gives the supporting-direction calculation for `F`. Decode
value remains in the calculation; it does not cancel as it does in a finite
episode where every request must finish and collect a fixed total reward.

Gradient scheduling with averaged rates has an asymptotic foundation for fixed
service slots and sufficiently slow adaptation. See
Expand All @@ -78,9 +87,10 @@ r_i <- exp(-T/tau) * r_i
+ (1 - exp(-T/tau)) * Y_i / (m_i * T).
```

Delivery history uses the same update with `Y_i` equal to zero or one and
normalizer `d_i`. This estimator spreads service over the occupied interval
for rate accounting. Output-age accounting still places delivery at completion.
Delivery history uses the same update with `Y_i` equal to `T` when stream `i`
publishes visible output during the interval and `0` otherwise, with normalizer
`1`. This estimator tracks served-time share across the occupied interval;
output-age accounting still places delivery at completion.
Equal-rate intervals compose consistently when split into different launch
durations. A launch-count EMA would not have that property.

Expand All @@ -90,9 +100,9 @@ service rate and its marginal price. This includes the prefill-to-decode
transition, changes in speculative acceptance, and timing updates. Changing a
normalization constant inside a logarithm must not itself reprice a token.

The first visible output initializes delivery history to one delivery over its
measured execution interval. A request already decoding without an observed
delivery starts from the batch-feasible delivery reference defined below.
The first visible output initializes delivery history to served share `1`. A
request already decoding without an observed delivery starts from the
batch-feasible served share defined below.
Token and delivery histories then persist until the request departs.

The implementation stores logarithms of rate fractions. An unserved interval
Expand Down Expand Up @@ -179,66 +189,79 @@ optimum; neither changes the supplied utility coefficients or graph timings.

## Pricing the delay caused by a graph

Rate utility distinguishes token volume from delivery frequency, but an average
delivery rate alone does not specify individual gaps. Let `A_i` be elapsed time
since request `i`'s last output and `c_i` a price per millisecond squared. Its
linear age cost during a nonpreemptible graph is
Rate utility distinguishes token volume from served delivery share, but an
average service share alone does not specify individual gaps. Let `A_i` be
elapsed time since request `i`'s last output and `c_i` a price per millisecond
squared. A stream incurs waiting cost only while excluded from execution.
During a nonpreemptible graph of duration `T`, an excluded stream `j` pays the
linear age cost

```text
c_i * (A_i*T + T*T/2).
c_j * (A_j*T + T*T/2)
```

Selected and excluded streams both wait through the graph. A selected stream's
age resets once at completion. Prefill has no decode-age clock.
and advances to `A_j' = A_j + T`. A selected stream makes active progress during
the graph, incurs zero waiting cost, and resets `A_i' = 0` at completion.
Prefill has no decode-age clock.

Consider a reference that independently chooses an action each round from a
fixed distribution. Let `p_i` be its probability of serving stream `i`, and
`mu` its mean round duration. Then
fixed distribution with duration `T` and served subset `S`. Let
`p_i = P(i in S)` be its probability of serving stream `i`. Then

```text
sigma_i = mu / p_i
sigma_i = E[T * 1_{i not in S}] / p_i
h(A) = -sum_i c_i * sigma_i * A_i
```

is the age-dependent part of its average-reward continuation value. To verify
it, substitute the transition `A_i' = 0` on service and `A_i' = A_i + T`
otherwise. The coefficient of each `A_i` in
it, substitute the excluded-only waiting cost and the transition `A_i' = 0` on
service and `A_i' = A_i + T` otherwise. The coefficient of each `A_i` in
`E[reward + h(A') - h(A)]` is
`c_i * (-mu + sigma_i*p_i) = 0`.
`c_i * (-E[T * 1_{i not in S}] + sigma_i*p_i) = 0`.
The remaining constant is the reference's net value per time multiplied by
`mu`. This identity holds when graph durations and service indicators are
`E[T]`. This identity holds when graph durations and service indicators are
correlated; the derivation does not replace their joint moments with independent
means.
means. When `T` and `1_{i in S}` are independent with mean duration `mu`,
`sigma_i = ((1 - p_i) / p_i) * mu`.

For `K` decoding requests sharing a graph family, the reference chooses the
graph minimizing `T/min(batch_capacity,K)`. Each round independently selects a
uniform cohort of that many requests. Every stream then has
`sigma = K*T/min(batch_capacity,K)`. Partially occupied graphs use their actual
occupied row count. Speculation yields one delivery per served stream, so
accepted token count does not multiply this reference rate.
graph minimizing `T/min(batch_capacity,K)` (breaking ties toward larger served
batch `b = min(batch_capacity,K)`). Each round independently selects a uniform
cohort of `b` requests, giving served share `s_i = b/K` and excluded-wait
reference `sigma_i = (K - b) * T / b`. Partially occupied graphs use their
actual occupied row count. When every active decoder fits in one batch (`b = K`),
`s_i = 1` and `sigma_i = 0`. Speculation yields one delivery interval per served
stream, so accepted token count does not multiply this reference.

The native selector also has resume and terminal-snapshot families. It assigns
each family's wall-time fraction in proportion to its stream count. Within a
family of `k` streams, uniformly sampled cohorts of `b=min(capacity,k)` give
`sigma_i = K*T_family/b`, where `K` counts all delivery-bearing streams.
family of `k` streams, uniformly sampled cohorts of `b = min(capacity,k)` give
`s_i = b/K` and `sigma_i = (K - b) * T_family / b`, where `K` counts all
delivery-bearing streams.
The action probabilities are the wall-time fractions divided by their durations,
then normalized. This defines a realizable independent reference on frozen
ready families. Prefilling requests do not acquire a delivery clock or enlarge
`K`; their token service retains its own fairness price. Streams blocked by
additional prerequisite stages use an individual future-delivery reference.
That multistage extension is a scheduling approximation.
additional prerequisite stages use an individual future-delivery reference
(`b = 1`). That multistage extension is a scheduling approximation.

Using `h` for one-step policy improvement gives

```text
score(a) = [expected priced token and delivery service
+ sum_{served decode i} c_i*sigma_i*(A_i+T)] / T
- T/2 * sum_{active decode i} c_i.
score(a) = [expected priced token service
+ sum_{served decode i} (delivery_price_i*T + c_i*sigma_i*A_i)] / T
+ sum_{served decode i} c_i*(A_i + sigma_i)
- T/2 * sum_{excluded decode j} c_j.
```

Terms independent of the chosen action have been removed. The stall-clearing
term is paid once per stream, irrespective of speculative yield. Expected work
and waiting are expressed in the same value units before division by time.
Equivalently, moving `c_i*(A_i*T + sigma_i*T + T*T/2)` into each served lane's
additive numerator leaves the common `-T/2 * sum_{active decode k} c_k` term
outside cohort selection. For a two-stage sequence with prerequisite duration
`t` and total horizon `H = t + d`, an already-ready decoder waits during `[0, t]`
and is served during `[t, H]`, contributing `delivery_price_i * d` and saving
`c_i * d * (A_i + (H + t)/2)` of waiting relative to exclusion over `[0, H]`.
Terms independent of the chosen action have been removed. Expected work and
waiting are expressed in the same value units before division by time.

For frozen prices, phases, and a fixed reference, this is an average-reward
policy-improvement calculation. A long-run improvement statement additionally
Expand All @@ -249,9 +272,17 @@ Variable-duration reward and continuation comparisons are instances of the
[renewal optimization framework](https://ee.usc.edu/stochastic-nets/docs/renewal-optimization.pdf).

With no active decoder, the age terms vanish. Full prefills compete by useful
value per time. With active decoders, a smaller prefill can win when the loss in
prompt throughput is smaller than the reduction in priced waiting. No duration
filter or preferred chunk size is involved.
value per time. Whenever every active decoder is served by a candidate and
`sigma_i = 0` — whether a single solo decoder, an uncontended full decode batch,
or a decoder taking its turn alongside a waiting prefiller — both delivery
fairness (`+delivery_price_i`) and age continuation (`+c_i*A_i`) are independent
of round duration `T`, so candidate selection maximizes priced token throughput
without underutilizing hardware to protect unarrived requests. Duration
trade-offs arise strictly in proportion to active decoders excluded by the
candidate: a prefill shrinks its chunk size when decoders wait, and an
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.

For a fixed physical graph, the excluded-stream cost depends on its duration,
not cohort membership. Its best cohort therefore contains the largest additive
Expand All @@ -263,16 +294,15 @@ enumerate joint speculative outcomes or every subset.
Native terminal retirement uses an intrinsic value `v` and linear age-cost
coefficient `c`, independently of streaming-delivery fairness and decode age.
Its clock `A` starts when termination is observed, including preemption of a
resident request. The snapshot family supplies the batch-feasible reference
interval `sigma`. A terminal row contributes `v + c*sigma*(A+T)` to a snapshot
of duration `T`, and `c` joins the common waiting-cost sum for every candidate.
This is the same age-continuation arithmetic as output delivery, with the
resident request. The snapshot family supplies the batch-feasible excluded-wait
reference `sigma`. Under excluded-only waiting, a terminal row selected for
retirement in a snapshot of duration `T` (or retired during stage one of a
lookahead horizon `H`) incurs zero waiting cost over the horizon, contributing
`v + c*sigma*(A+H) + c*H*(A + H/2)` against the common `-c*H/2` denominator
term. This is the same age-continuation arithmetic as output delivery, with the
terminal event's own value and clock. It supplies no token or streaming-delivery
credit. There is no additional terminal rate-history coordinate.

If the row retires at time `t` within a lookahead horizon `H`, its contribution
is `v + c*sigma*(A+H) + c*(H-t)*(A+(H+t)/2)`. The last term removes waiting after
retirement. All contributions use the decision's common positive scale.
All contributions use the decision's common positive scale.
The two-stage cohort solver therefore compares terminal retirement and enabled
inference without separate priority rules. These terminal terms remain active
under throughput policy; the stationary backlogged-stream analysis above does
Expand Down
Loading
Loading