mixle.task.economics module¶
Cost comparisons for local distillation, cascades, and teacher-only serving.
Every routing choice has a cost model. This module combines a conformal
escalation rate (mixle.task.calibrate.CalibratedTaskModel.escalation_rate(),
the empirical p_escalate) with unit costs:
frontier-only – pay
c_frontierfor every request, forever.local-only – distill once (
n_labelteacher calls + training), then payc_localper request.cascade – run the low-cost local model first, escalate only the ambiguous fraction: per request
c_local + p_escalate * c_frontier, with the singletons covered at1 - alpha.
break_even_volume() is the request count at which a distilled route
recovers its one-time setup cost. recommend_route() picks the lowest-cost
route at a given volume, optionally constrained by a maximum tolerated
escalation rate, and reports the savings.
- class CostModel(c_frontier, c_local=0.0, c_label=0.0, train_cost=0.0)[source]
Bases:
objectUnit costs in any consistent currency.
- cascade_cost_per_request(cost, p_escalate)[source]
Expected per-request cost of the cascade: always run local, escalate the
p_escalatefraction.
- break_even_volume(cost, n_label, *, p_escalate=0.0)[source]
Requests after which a distilled route undercuts frontier-only (
infif it never does).Setup is amortized against the per-request saving
c_frontier - per_request(route). Withp_escalate=0this is the local-only break-even; pass the model’s escalation rate for the cascade break-even.
- class RoutePlan(route, volume, per_request, total, savings_vs_frontier, p_escalate, break_even, options)[source]
Bases:
objectCosted route comparison for a fixed request volume.
- recommend_route(cost, *, volume, n_label, p_escalate, max_escalation=None)[source]
Pick the lowest-cost route over
volumerequests.local_onlyis offered only when the caller explicitly disallows escalation by settingmax_escalation == 0. Otherwise the cascade route keeps local answers for calibrated inputs and escalates the remaining traffic to the teacher.
- select_alpha_for_cost(model, cal_texts, cal_labels, probe_texts, cost, *, volume, n_label, alphas=(0.01, 0.05, 0.1, 0.15, 0.2, 0.3))[source]
Select
alphafrom aCostModeltarget.The sweep connects
recommend_route()to the calibration step so threshold selection reflects both model behavior and the caller’s cost assumptions.modelis anything with theCalibratedTaskModelshape: a mutablealphaattribute,calibrate(texts, labels), andescalation_rate(texts). For each candidate inalphas, this recalibratesmodeland measures its realized escalation rate onprobe_texts(a held-out slice disjoint fromcal_texts), then scores that escalation rate withrecommend_route()overvolumerequests. The winner is the alpha whose recommended route is lowest-cost overall;modelis left calibrated at that winning alpha. Returns(best_alpha, best_plan, plan_by_alpha)so the full sweep remains auditable.