mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
Ports the efficiency-reward piece of the Elastic Unified Router (EURo) design into the adaptive router's bandit, giving it a second Beta posterior keyed on latency and completion-token throughput, independent of quality signals. ## What changed - BanditCell now tracks (alpha_eff, beta_eff) alongside (alpha, beta), both fed independently. Efficiency defaults to Beta(1, 1) prior (uninformative). - AdaptiveRouter.record_efficiency() updates the efficiency posterior from observed latency and token count; independent of record_turn()'s quality signals. - Efficiency reward = gamma * exp(-latency/target) + (1-gamma) * min(tokens/sec/max, 1), clamped to [0, 1]. On failure (non-2xx), reward = 0. - Selection now blends three terms: quality_weight * TS(quality) + efficiency_weight * TS(efficiency) + cost_weight * cost. Efficiency weight defaults to 0.0 (opt-in). - DB: schema.prisma + migration add alpha_eff/beta_eff columns to LiteLLM_AdaptiveRouterState; read/write plumbing in update_queue and adaptive_router. - Snapshot endpoint reports efficiency_mean alongside quality_mean. ## Tests New tests for apply_efficiency_delta, efficiency_mean property, and flush behavior with efficiency deltas. All existing bandit and router tests pass. ## Design decisions baked in (as per PHASE1_PLAN.md) 1. Efficiency weight defaults to 0.0 — no silent behavior change for existing deployments. Opt-in only. 2. target_latency is static (1.0s default, overridable in config). Auto-calibration deferred to Phase 2. 3. Failure handling reuses existing response_status detection — one source of truth. 4. Schema extended in place (not a sibling table) — (router, request_type, model) is already the right key for both quality and efficiency. Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| migrations | ||
| __init__.py | ||
| _logging.py | ||
| prisma_toolchain.py | ||
| py.typed | ||
| replica_identity.py | ||
| schema.prisma | ||
| utils.py | ||