mixle.task.economics module

The cost arithmetic that decides whether to spend the GPU: distill-and-serve-local vs. cascade vs. frontier.

GPU time is not free, so every routing choice is an economic one. This module turns the conformal escalation rate (mixle.task.calibrate.CalibratedTaskModel.escalation_rate(), the empirical p_escalate) and a few unit costs into dollars:

  • frontier-only – pay c_frontier for every request, forever.

  • local-only – distill once (n_label teacher calls + training), then pay c_local per request.

  • cascade – run the cheap local model first, escalate only the ambiguous fraction: per request c_local + p_escalate * c_frontier, with the singletons covered at 1 - alpha.

break_even_volume() is the request count at which a distilled route pays back its one-time setup; recommend_route() picks the cheapest route at a given volume (optionally constrained to a maximum tolerated escalation rate) and reports the savings. This is the “is it worth it?” question answered with a number.

class CostModel(c_frontier, c_local=0.0, c_label=0.0, train_cost=0.0)[source]

Bases: object

Unit costs (any consistent currency). c_local is the amortized local per-request cost (~0 on CPU).

Parameters:
c_frontier: float
c_local: float = 0.0
c_label: float = 0.0
train_cost: float = 0.0
setup_cost(n_label)[source]

One-time cost to stand up a local model: label n_label examples + train.

Parameters:

n_label (int)

Return type:

float

cascade_cost_per_request(cost, p_escalate)[source]

Expected per-request cost of the cascade: always run local, escalate the p_escalate fraction.

Parameters:
  • cost (CostModel)

  • p_escalate (float)

Return type:

float

break_even_volume(cost, n_label, *, p_escalate=0.0)[source]

Requests after which a distilled route undercuts frontier-only (inf if it never does).

Setup is amortized against the per-request saving c_frontier - per_request(route). With p_escalate=0 this is the local-only break-even; pass the model’s escalation rate for the cascade break-even.

Parameters:
  • cost (CostModel)

  • n_label (int)

  • p_escalate (float)

Return type:

float

class RoutePlan(route, volume, per_request, total, savings_vs_frontier, p_escalate, break_even, options)[source]

Bases: object

The costed comparison of routes at a given volume, with the recommended choice and its savings.

Parameters:
route: str
volume: int
per_request: float
total: float
savings_vs_frontier: float
p_escalate: float
break_even: float
options: dict[str, float]
recommend_route(cost, *, volume, n_label, p_escalate, max_escalation=None)[source]

Pick the cheapest route over volume requests; honor an optional cap on tolerated escalation.

local_only is treated as a cascade with no escalation only when its quality is acceptable to the caller – here it is offered whenever max_escalation is not exceeded by p_escalate (the cascade already answers the easy cases locally and escalates the rest, so it dominates pure local-only on accuracy; local-only is kept as the floor cost when escalation is disallowed entirely, max_escalation == 0).

Parameters:
  • cost (CostModel)

  • volume (int)

  • n_label (int)

  • p_escalate (float)

  • max_escalation (float | None)

Return type:

RoutePlan