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)[source]
Bases:
objectServe
text -> labelthrough a confident local model, escalating to the teacher when needed.- Parameters:
model (CalibratedTaskModel)
teacher (Callable[..., Any])
cost (CostModel | None)
- serve(texts)[source]
Serve a batch of requests through the cascade.
- 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.