Sub topic 1
Why releasing a new model is different from releasing code
Prerequisites
This chapter assumes you can serve a model behind an HTTP or RPC endpoint, read common metrics such as precision, recall, and latency, and work with proportions and averages.
Why model releases are risky
A code release usually works or fails visibly, often with an error. A model release can run without errors and still make worse predictions. Users see no crash, but fraud scores may drift or recommendations may get worse. You need evidence from real traffic, not only a successful deploy.
What offline evaluation tells you and what it cannot
Offline evaluation scores a model on a fixed historical dataset. It shows how the model performs on past data. It cannot show how users respond, how the model handles today's inputs, or how it behaves under production latency. Use offline results to decide whether a model deserves live testing, not whether it is safe to ship.
Splitting traffic between model versions
Traffic splitting sends a share of requests to the candidate model and the rest to the stable model. Assignment must be sticky, so the same user gets the same version on every request. Otherwise a user sees the model switch between versions, and your comparisons mix populations. Hashing the user ID with a salt gives a stable bucket.
Worked example
import hashlib
def assign(user_id: str, salt: str, candidate_percent: float) -> str:
digest = hashlib.sha256(f"{salt}:{user_id}".encode()).hexdigest()
bucket = int(digest, 16) % 10000
return "candidate" if bucket < candidate_percent * 100 else "stable"
print(assign("user-123", "ranker-v2", 5))Logging predictions so versions can be compared
Log each prediction with its request ID, model version, timestamp, and prediction. When you shadow or canary a model, log paired predictions from both models for the same request so you can compare them directly. Labels often arrive later, so store the request ID to join them afterward.
Choosing metrics and guardrails
Pick three kinds of metric. System metrics include error rate and p95 latency. Model metrics include precision and recall on labeled outcomes. Business metrics include conversion rate or loss rate. A guardrail is a metric with a limit the candidate must not cross, such as an error rate no more than 0.5 percentage points above stable. A guardrail breach should block promotion or trigger rollback, even when the main metric improves.
Exercise
A candidate has higher precision than stable, but its p95 latency is 25% above stable, and the guardrail allows at most 10%. Should it be promoted?
Show answer
No. The latency guardrail is breached, so the candidate should be blocked or rolled back, even though precision improved.