Module spec_cost

Module spec_cost 

Source
Expand description

2026-10-04: The measured speculative-cost table (--spec-cost-model measured): what a verify step and a draft step cost, in wall time and GPU-rail energy, at each batch width and draft depth, on one box class for one recipe; and the drafter’s confidence→acceptance calibration. met bench spec-cost measures both and writes them; the serve loads them and plans draft depth from them. Pure: parsing and arithmetic only, no I/O.

Owner: speculative. Invariants:

  • A table is used only under the key it was measured under (TableKey::check): the box class, the recipe, and the plan digest of every mode it measured. A calibration is used only for the drafter it was fitted on (DrafterKey). A mismatch is refused, never approximated.
  • A parsed table has, for every width it lists, a cell at every draft depth 0..=its maximum, all with finite positive costs (CostTable::parse).
  • Costs between measured widths are interpolated linearly in width; a width outside the measured range takes the nearest measured width (CostTable::cell).

Modules§

plan
2026-10-04: The measured planner of --spec-cost-model measured: draft depth by expected accepted tokens per joule, with tok/s as a constraint. Pure and deterministic: its output depends only on the table, the calibration, the batch width and the drafter’s confidences; no clock is read. It chooses how many drafts are proposed and verified, never which token is emitted, so greedy output is unchanged on row-invariant tiers.

Structs§

AcceptanceCalibration
2026-10-04: How likely a draft is to be accepted, from the drafter’s top-1 log-probability for it, fitted on one drafter (DrafterKey); and per-position priors for drafts whose confidence was not measured. A draft is accepted only if every draft before it was, so a chain’s expected accepted length is the sum of the running products.
Cell
2026-10-04: One measured cell: n sequences, k drafts each (k = 0 is a plain decode step, no draft and no verify rows beyond the one token).
CostTable
2026-10-04: A parsed, validated cost table.
DrafterKey
2026-10-04: The drafter a confidence calibration was fitted on.
SpecCostState
2026-10-04: --spec-cost-model measured’s resolved state, as the serve loaded and checked it at boot (TableKey::check and a DrafterKey comparison both empty/equal): the table, the drafter’s acceptance calibration, and --spec-cost-slack.
TableKey
2026-10-04: What a table was measured under. Equal keys are the only licence to use it.

Enums§

KeyMismatch
2026-10-04: One reason a table key does not match the serve’s.

Constants§

MIN_OUTCOMES
2026-10-04: The fewest observations behind one fitted probability: a binomial standard error of at most 0.05 at any rate.
SCHEMA
2026-10-04: Schema version of the table files; bumped when a field changes meaning.