engine.solvers.deliberation
engine.solvers.deliberation
Test-time deliberation solvers: spending more work on one decision with the weights fixed.
Domain implementations behind mlsysim.solvers (added 2026-10-20). Each model is arithmetic on stated token counts, pass rates, check error rates, and the per-token decode floor of a DecodeScenario: how one output ceiling turns into different latencies and bills as depth, breadth, or feedback; what a pool of independent candidates holds and what a fallible check lets through; how argmax selection concentrates scoring error; how a step check bounds a search tree; and what flat sampling, beam search, and feedback policies spend under one deadline. None models queueing, batching, prefill, or serving overhead unless a scenario states it.
Classes
| Name | Description |
|---|---|
| AllocationAxesModel | One output ceiling spent three ways: depth, breadth, and feedback. |
| ArgmaxNoiseModel | Argmax over N equally good candidates whose scores carry independent noise. |
| BestOfNPoolModel | A parallel pool of N independent candidates against sequential retry. |
| DeadlinePolicyModel | Three deliberation policies for one task under one deadline. |
| ProbeVsAnswerModel | A generated explanation of K tokens against a prepared test of T_probe. |
| PrunedSearchTreeModel | Size of a search tree whose step check rejects each child with probability r. |
| ScopedRevisionModel | Output of regenerating a whole candidate plan against only its affected nodes. |
| SearchAccountsModel | Flat best-of-N against beam search, kept as separate accounts. |
| VerifiedPoolModel | First-passing selection from a fixed pool of n under a fallible check. |
AllocationAxesModel
engine.solvers.deliberation.AllocationAxesModel()One output ceiling spent three ways: depth, breadth, and feedback.
Depth generates the whole ceiling in one chain. Breadth runs N concurrent candidates, each billed its own copy of the S-token prompt, so it re-reads (N - 1) S tokens. Feedback runs H rounds of a candidate plus a check; each later request appends the earlier candidates and reports, so input is H S + (K + R) H (H - 1) / 2. Times are generation at the decode floor plus checks; bills count model tokens only.
Methods
| Name | Description |
|---|---|
| solve | One output ceiling spent three ways: depth, breadth, and feedback. |
solve
engine.solvers.deliberation.AllocationAxesModel.solve(
decode_per_token,
prompt,
ceiling,
candidates,
candidate_tokens,
rounds,
report_tokens,
check_time,
input_price,
output_price,
context_growth=None,
)One output ceiling spent three ways: depth, breadth, and feedback.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decode_per_token | Quantity | Duration of one generated token, convertible to seconds; positive. | required |
| prompt | int | Initial prompt length, in tokens; nonnegative. | required |
| ceiling | int | Depth-policy output length, in tokens; positive. | required |
| candidates | int | Positive count of concurrently generated candidates. | required |
| candidate_tokens | int | Positive generated token count per candidate. | required |
| rounds | int | Positive count of feedback rounds. | required |
| report_tokens | int | Nonnegative tokens appended by each check report. | required |
| check_time | Quantity | Duration of one check, convertible to seconds; nonnegative. | required |
| input_price | Quantity | Positive input-token price, convertible to USD/token. | required |
| output_price | Quantity | Positive output-token price, convertible to USD/token. | required |
| context_growth | Optional[int] | Optional positive multiplier for the extra breadth prompt charge; None omits it. | None |
Returns
| Name | Type | Description |
|---|---|---|
| AllocationAxesResult | Per-policy input/output token counts, duration in seconds, USD bills, and dimensionless latency/cost ratios. |
Notes
Equation: Depth output = ceiling; breadth output = N K; feedback input = H S + (K + R) H (H - 1) / 2.
Assumptions: Breadth executes concurrently; feedback executes serially; each request pays its full prompt.
Excludes: Prefill, queueing, resource contention, and effectiveness of reasoning.
References
Derivation: Parallel candidates each pay for a separate prompt. Feedback round j resends j earlier increments, so repeated context is an arithmetic series. Adding the generated tokens and check durations gives the serial feedback time; breadth instead charges concurrent candidates separately.
Examples
>>> from mlsysim.core.units import Q_
>>> AllocationAxesModel().solve(Q_("1 ms"), 10, 20, 2, 10, 2, 2, Q_("1 ms"), Q_("1 USD/token"), Q_("1 USD/token")).breadth_output == 20
TrueArgmaxNoiseModel
engine.solvers.deliberation.ArgmaxNoiseModel()Argmax over N equally good candidates whose scores carry independent noise.
The winner’s expected scoring error is the expected maximum of N standard normals (in units of the noise’s spread), below the large-N asymptote sqrt(2 ln N). A loophole present in a fraction g of single samples appears in a pool of N with 1 - (1 - g)^N.
Methods
| Name | Description |
|---|---|
| solve | Argmax over N equally good candidates whose scores carry independent noise. |
solve
engine.solvers.deliberation.ArgmaxNoiseModel.solve(
pool_sizes,
large_pool,
exploit_rate,
)Argmax over N equally good candidates whose scores carry independent noise.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pool_sizes | Sequence[int] | Nonempty positive candidate counts; the final entry is the comparison pool. | required |
| large_pool | int | Positive candidate count for the exploit-presence calculation. | required |
| exploit_rate | float | Independent per-candidate exploit probability, in [0, 1]. | required |
Returns
| Name | Type | Description |
|---|---|---|
| ArgmaxNoiseResult | Expected winner noise in standard-deviation units and dimensionless exploit-presence probabilities. |
Notes
Equation: Expected winner noise = E[max(Z_1,…,Z_n)]; exploit presence = 1 - (1 - g)^N.
Assumptions: Candidates have equal underlying quality and independent standard-normal score noise.
Excludes: Systematic scoring bias, dependent errors, and unequal candidate quality.
References
Derivation: The maximum of n independent normal scores has cumulative probability Phi(x)^n, which the expected-maximum helper integrates. The loophole calculation instead complements the event that no candidate contains a loophole; it does not assume normal loophole probabilities.
Examples
>>> ArgmaxNoiseModel().solve([1], 2, 0.5).exploit_presence == 0.75
TrueBestOfNPoolModel
engine.solvers.deliberation.BestOfNPoolModel()A parallel pool of N independent candidates against sequential retry.
pass@N is 1 - (1 - p)^N. A parallel pool always generates N candidates; retrying one at a time and stopping at the first pass (capped at N) generates [1 - (1 - p)^N] / p on average, 1 / p per success. A mixed workload whose tasks pass at different rates must apply pass@N per task before averaging; averaging p first overstates it. The selector is assumed to return a passing member whenever one exists.
Methods
| Name | Description |
|---|---|
| solve | A parallel pool of N independent candidates against sequential retry. |
solve
engine.solvers.deliberation.BestOfNPoolModel.solve(
pass_rate,
pool_sizes,
easy_pass_rate,
hard_pass_rate,
)A parallel pool of N independent candidates against sequential retry.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pass_rate | float | Independent candidate success probability, in (0, 1]. | required |
| pool_sizes | Sequence[int] | Nonempty positive candidate counts; the final entry is the comparison pool. | required |
| easy_pass_rate | float | Success probability for the equally weighted easy-task population, in [0, 1]. | required |
| hard_pass_rate | float | Success probability for the equally weighted hard-task population, in [0, 1]. | required |
Returns
| Name | Type | Description |
|---|---|---|
| BestOfNPoolResult | Pass probabilities by pool size, candidate counts per success, and equally weighted mixture comparisons. |
Notes
Equation: pass@n = 1 - (1 - p)^n; capped retry work = pass@n / p.
Assumptions: Independent trials and a selector that recognizes any passing member; equal easy/hard mixture.
Excludes: Correlated candidates, selector errors, and generation latency.
References
Derivation: Complement the event that every independent candidate fails to obtain pool availability. Capped sequential work sums the geometric probabilities of reaching each candidate. Dividing work by availability charges failed attempts to successful tasks. For heterogeneous tasks, compute each task type’s availability before averaging.
Examples
>>> BestOfNPoolModel().solve(0.5, [1, 2], 0.75, 0.25).pass_at[2] == 0.75
TrueDeadlinePolicyModel
engine.solvers.deliberation.DeadlinePolicyModel()Three deliberation policies for one task under one deadline.
A: one candidate and one check. B: N independent candidates generated and checked in parallel, pass@N. C: feedback; a failed first candidate plus its failure report feeds one revision that passes with the conditional rate. The model admits at most two rounds, and only starts a round if it can finish by the deadline. A round is a candidate at the decode floor plus a check. Bills count model tokens; per-pass figures divide by the pass probability.
Methods
| Name | Description |
|---|---|
| solve | Three deliberation policies for one task under one deadline. |
solve
engine.solvers.deliberation.DeadlinePolicyModel.solve(
decode_per_token,
prompt,
output,
diagnostic,
breadth,
max_rounds,
deadline,
check_time,
initial_pass,
revision_pass,
input_price,
output_price,
)Three deliberation policies for one task under one deadline.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decode_per_token | Quantity | Duration of one generated token, convertible to seconds; positive. | required |
| prompt | int | Initial prompt length, in tokens; nonnegative. | required |
| output | int | Positive generated tokens per candidate or revision. | required |
| diagnostic | int | Nonnegative tokens in the failure report. | required |
| breadth | int | Positive parallel candidate count. | required |
| max_rounds | int | Positive requested feedback-round cap. This model supports at most one revision, so the admitted count is additionally capped at two. | required |
| deadline | Quantity | Available duration, convertible to seconds; nonnegative. | required |
| check_time | Quantity | Duration of one check, convertible to seconds; nonnegative. | required |
| initial_pass | float | First-candidate success probability, in [0, 1]. | required |
| revision_pass | float | Conditional success probability after first failure, in [0, 1]. | required |
| input_price | Quantity | Nonnegative input-token price, convertible to USD/token. | required |
| output_price | Quantity | Nonnegative output-token price, convertible to USD/token. | required |
Returns
| Name | Type | Description |
|---|---|---|
| DeadlinePolicyResult | Policy success probabilities, expected input/output tokens, durations in seconds, USD bills, and cost per pass. |
Notes
Equation: admitted rounds = min(2, cap, floor(deadline / round_time)). Feedback success is zero, p, or p + (1-p)*p_revision for zero, one, or two admitted rounds. Expected rounds are zero, one, or 1+(1-p).
Assumptions: Parallel breadth and a single conditional revision. Requests are admitted only when one complete generation/check round fits. No partial-round work is launched or billed. A failed first attempt triggers a revision only when a second complete round fits. Admission interprets original time magnitudes and unit scales as decimal values; it adds them before conversion to floating-point output durations, so binary rounding cannot turn 3 * 100 ms into more than a 300 ms budget.
Excludes: Queueing, prefill, and arbitrary multi-round feedback. Per-pass costs and output counts are infinite when success probability is zero; the B/A cost-per-pass ratio is NaN when its denominator is zero or either per-pass cost is infinite.
References
Derivation: Divide the deadline by the fixed generation-plus-check duration to admit whole rounds, capped at the model’s one revision. A second round is reached only after first-round failure, so its probability weights both success and billed tokens. Parallel breadth uses the complement of all independent candidates failing; unaffordable rounds contribute no work.
Examples
>>> from mlsysim.core.units import Q_
>>> DeadlinePolicyModel().solve(Q_("1 ms"), 10, 10, 2, 2, 2, Q_("1 s"), Q_("1 ms"), 0.5, 1.0, Q_("1 USD/token"), Q_("1 USD/token")).c_pass == 1.0
TrueProbeVsAnswerModel
engine.solvers.deliberation.ProbeVsAnswerModel()A generated explanation of K tokens against a prepared test of T_probe.
Generation time is K * tau_decode at the weight-transfer floor; the charge is K output tokens at the output price. Prefill, queueing, and test preparation are excluded.
Methods
| Name | Description |
|---|---|
| solve | A generated explanation of K tokens against a prepared test of T_probe. |
solve
engine.solvers.deliberation.ProbeVsAnswerModel.solve(
decode_per_token,
answer_tokens,
probe_time,
output_price,
)A generated explanation of K tokens against a prepared test of T_probe.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decode_per_token | Quantity | Duration of one generated token, convertible to seconds; positive. | required |
| answer_tokens | int | Positive generated explanation length, in tokens. | required |
| probe_time | Quantity | Positive duration of the prepared test, convertible to seconds. | required |
| output_price | Quantity | Positive output-token price, convertible to USD/token. | required |
Returns
| Name | Type | Description |
|---|---|---|
| ProbeVsAnswerResult | Answer and token duration in seconds, output charge in USD, and dimensionless answer/probe time ratio. |
Notes
Equation: T = K tau; cost = K p_out; time ratio = T / T_probe.
Assumptions: Fixed decode duration and token price; probe preparation already complete.
Excludes: Prefill, queueing, test preparation, and answer quality.
References
Derivation: Fixed-duration token generation adds one decode interval per output token. The corresponding output bill multiplies the same token count by the tariff; dividing duration by probe time compares the two operations without assigning either a quality advantage.
Examples
>>> from mlsysim.core.units import Q_
>>> ProbeVsAnswerModel().solve(Q_("1 ms"), 10, Q_("1 s"), Q_("1 USD/token")).answer_time.m_as("ms") == 10
TruePrunedSearchTreeModel
engine.solvers.deliberation.PrunedSearchTreeModel()Size of a search tree whose step check rejects each child with probability r.
The effective branching factor is b (1 - r); above r = 1 - 1/b the expected frontier shrinks and the tree dies out on its own. Rejecting a parent removes its whole subtree, so the node saving exceeds r.
Methods
| Name | Description |
|---|---|
| solve | Size of a search tree whose step check rejects each child with probability r. |
solve
engine.solvers.deliberation.PrunedSearchTreeModel.solve(
branching,
rejection_rate,
depth,
wide_branching=None,
wide_depth=None,
)Size of a search tree whose step check rejects each child with probability r.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| branching | int | Positive children per expanded search node. | required |
| rejection_rate | float | Independent rejection probability per child, in [0, 1]. | required |
| depth | int | Nonnegative count of tree expansion levels. | required |
| wide_branching | Optional[int] | Optional positive branching factor for an unpruned comparison tree. | None |
| wide_depth | Optional[int] | Optional positive depth for the comparison tree. | None |
Returns
| Name | Type | Description |
|---|---|---|
| PrunedSearchTreeResult | Expected frontier and node counts, critical rejection probability, and node-saving fraction. |
Notes
Equation: Effective branching = b (1 - r); frontier at depth d = [b (1 - r)]^d.
Assumptions: Independent child rejection and uniform branching; expected counts may be fractional.
Excludes: Checker cost, mistaken rejection, and correctness of surviving nodes.
References
Derivation: A parent contributes b children, each retained with probability 1-r, giving expected branching b(1-r). Summing expected level sizes yields explored nodes; comparing with the unpruned geometric series also counts descendants removed with each rejected parent.
Examples
>>> PrunedSearchTreeModel().solve(2, 0.5, 2).effective_branching == 1.0
TrueScopedRevisionModel
engine.solvers.deliberation.ScopedRevisionModel()Output of regenerating a whole candidate plan against only its affected nodes.
Equal-sized nodes; only replaced nodes are generated. Input processing, checks, and physical effects are excluded.
Methods
| Name | Description |
|---|---|
| solve | Output of regenerating a whole candidate plan against only its affected nodes. |
solve
engine.solvers.deliberation.ScopedRevisionModel.solve(
total_nodes,
replaced_nodes,
tokens_per_node,
)Output of regenerating a whole candidate plan against only its affected nodes.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| total_nodes | int | Positive count of equal-sized plan nodes. | required |
| replaced_nodes | int | Count of regenerated nodes, between zero and total_nodes. | required |
| tokens_per_node | int | Positive generated tokens per node. | required |
Returns
| Name | Type | Description |
|---|---|---|
| ScopedRevisionResult | Full and revised output token counts, with dimensionless regenerated and avoided shares. |
Notes
Equation: Full output = total_nodes times tokens_per_node; scoped output = replaced_nodes times tokens_per_node.
Assumptions: Nodes have equal generation length and unchanged nodes need no regeneration.
Excludes: Input processing, checks, and physical effects of plan execution.
References
Derivation: Multiplying equal tokens per node by the affected-node count gives the scoped output. Comparing that count with the full node count isolates generation savings without assuming a saving in input processing.
Examples
>>> from mlsysim.core.units import Q_
>>> ScopedRevisionModel().solve(4, 1, 10).output_share == 0.25
TrueSearchAccountsModel
engine.solvers.deliberation.SearchAccountsModel()Flat best-of-N against beam search, kept as separate accounts.
Flat: N complete candidates of L segments of s tokens, each request billed the task prompt. Beam: each retained prefix proposes e extensions per stage and the best w survive; every extension request resends the prompt plus its prefix, and the scorer reads each full prefix. Generation runs in waves of the stated concurrency at the decode floor; scoring and final tests add fixed allowances. No prefix-reuse discount. The break-even input share is the input price fraction at which the beam’s output saving, net of scoring, pays for its repeated input.
Methods
| Name | Description |
|---|---|
| solve | Flat best-of-N against beam search, kept as separate accounts. |
solve
engine.solvers.deliberation.SearchAccountsModel.solve(
decode_per_token,
segments,
segment_tokens,
prompt_tokens,
flat_candidates,
beam_width,
extensions,
generation_slots,
test_slots,
score_time,
test_time,
input_price,
output_price,
scorer_price,
)Flat best-of-N against beam search, kept as separate accounts.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decode_per_token | Quantity | Duration of one generated token, convertible to seconds; positive. | required |
| segments | int | Positive segment count in a complete candidate. | required |
| segment_tokens | int | Positive generated tokens per segment. | required |
| prompt_tokens | int | Nonnegative task-prompt tokens resent by each request. | required |
| flat_candidates | int | Positive complete-candidate count for flat sampling. | required |
| beam_width | int | Positive maximum retained prefixes at each search depth. | required |
| extensions | int | Positive proposed children per retained prefix. | required |
| generation_slots | int | Positive number of concurrent generation requests. | required |
| test_slots | int | Positive number of concurrent final tests. | required |
| score_time | Quantity | Duration to score each extension, convertible to seconds; nonnegative. | required |
| test_time | Quantity | Duration of each final test, convertible to seconds; nonnegative. | required |
| input_price | Quantity | Positive input-token price, convertible to USD/token. | required |
| output_price | Quantity | Positive output-token price, convertible to USD/token. | required |
| scorer_price | Quantity | Scorer token price, convertible to USD/token; nonnegative. | required |
Returns
| Name | Type | Description |
|---|---|---|
| SearchAccountsResult | Frontier counts, generated/scored token totals, elapsed seconds, USD charges, and the input-price break-even ratio. |
Notes
Equation: Each beam frontier is retained times extensions; generation waves = ceil(frontier / slots); bills sum input, output, and scorer tokens.
Assumptions: Fixed-length segments and fixed concurrency; scoring is serially additive and all prefixes are resent.
Excludes: Prefix reuse, queueing, prefill, candidate quality, and contention; input-premium denominator must be nonzero.
References
Derivation: Count complete outputs for flat sampling and retained-prefix extensions at each beam stage. Each extension resends its prompt and prefix, and the scorer reads that prefix again. Convert concurrent generation to waves before adding scorer and final-test durations. The input-price break-even equates extra prompt charges to net output savings.
Examples
>>> from mlsysim.core.units import Q_
>>> SearchAccountsModel().solve(Q_("1 ms"), 2, 10, 5, 2, 2, 2, 2, 2, Q_("1 ms"), Q_("1 ms"), Q_("1 USD/token"), Q_("1 USD/token"), Q_("1 USD/token")).beam_segments == 6
TrueVerifiedPoolModel
engine.solvers.deliberation.VerifiedPoolModel()First-passing selection from a fixed pool of n under a fallible check.
Each candidate is valid with rate v; the check rejects valid ones with eps_FR and passes invalid ones with eps_FA, so a candidate passes with q = v (1 - eps_FR) + (1 - v) eps_FA. Passing-set precision is v (1 - eps_FR) / q, one minus the Bayes posterior of a defect given a pass (CheckerPosteriorModel with defect_rate = 1 - v). The pool selects with 1 - (1 - q)^n and otherwise abstains; a selection is defective with 1 - precision. An incident loss prices each defective selection; the output bill prices the whole pool.
Methods
| Name | Description |
|---|---|
| solve | First-passing selection from a fixed pool of n under a fallible check. |
solve
engine.solvers.deliberation.VerifiedPoolModel.solve(
pool_size,
valid_rate,
false_reject_rate,
false_accept_rate,
tokens_per_candidate,
output_price,
incident_loss,
)First-passing selection from a fixed pool of n under a fallible check.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pool_size | int | Positive number of generated candidates. | required |
| valid_rate | float | Prior probability that a candidate is valid, in [0, 1]. | required |
| false_reject_rate | float | Probability of rejecting a valid candidate, in [0, 1]. | required |
| false_accept_rate | float | Probability of passing an invalid candidate, in [0, 1]. | required |
| tokens_per_candidate | Quantity | Positive token quantity per candidate, convertible to token. | required |
| output_price | Quantity | Positive output-token price, convertible to USD/token. | required |
| incident_loss | Quantity | Loss per defective selection, convertible to USD; nonnegative. | required |
Returns
| Name | Type | Description |
|---|---|---|
| VerifiedPoolResult | Selection/defect probabilities, expected passing counts, USD incident loss and output bill, and their ratio. |
Notes
Equation: q = v (1 - false_reject_rate) + (1 - v) false_accept_rate; precision = v (1 - false_reject_rate) / q.
Assumptions: Independent candidates, constant checker error rates, and q > 0; the entire pool is billed.
Excludes: Checker runtime, correlated failures, and adaptive stopping charges.
References
Derivation: Partition checker passes into valid-pass and invalid-pass joint events. Bayes conditioning gives their shares among passes. The complement of an all-rejected pool gives selection probability; multiply it by the invalid share and incident loss to price wrong selections.
Examples
>>> from mlsysim.core.units import Q_
>>> VerifiedPoolModel().solve(2, 0.5, 0.0, 0.0, Q_("10 token"), Q_("1 USD/token"), Q_("10 USD")).precision == 1.0
True