mixle.task.cascade module¶
Cascade serving with realized cost tracking and targeted retraining data.
Each request is answered locally when the
CalibratedTaskModel is confident and
in-distribution, and escalated to the teacher otherwise. The cascade tracks
actual spend against a CostModel, so
report() returns observed cost and savings relative to a teacher-only route.
Every escalated request marks a case where the local model deferred and the
teacher supplied a targeted label. harvested() returns those
(text, label) pairs for the next distillation run.
- class CascadeStats(n_requests=0, n_escalated=0, escalated_texts=<factory>, escalated_labels=<factory>)[source]
Bases:
objectRunning tally of how a cascade served traffic – the basis for realized cost and the harvest.
- Parameters:
- property realized_escalation_rate: float
Return the observed fraction of requests escalated to the teacher.
- class Cascade(model, teacher, *, cost=None, teacher_mode='batch')[source]
Bases:
objectServe
text -> labelthrough a confident local model, escalating to the teacher when needed.- Parameters:
model (CalibratedTaskModel)
teacher (Callable[..., Any])
cost (CostModel | None)
teacher_mode (str)
- serve(texts)[source]
Serve a batch of requests through the cascade.
- serve_with_teacher_labels(texts, teacher_labels)[source]
Serve a batch against one immutable snapshot of teacher outcomes.
This is the evaluation/replay counterpart to
serve(): the caller obtains exactly one teacher label per request up front, and this method uses those labels only for local deferrals while updating the same traffic and harvest accounting as live serving.
- harvested()[source]
Return escalated
(texts, teacher_labels)as targeted retraining data.
- realized_cost()[source]
Actual spend so far:
c_localper request plusc_frontierper escalation (requires a CostModel).- Return type:
- report()[source]
Realized economics: requests, escalation rate, spend, and savings vs serving everything on the frontier.
- plan(*, volume, n_label, max_escalation=None)[source]
Project the lowest-cost route at
volumeusing the realized escalation rate.This is a POINT projection, not a forecast with uncertainty: it prices every route at the escalation rate realized on the traffic served so far and assumes that rate persists at
volume. Distribution shift re-prices it silently – re-measure on drifted traffic before acting on a large-volume recommendation.