Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 6Name in the course: Model monitoring

Monitor models in production

A model API can be "up" and still give bad answers. Monitor two layers: the service (latency, errors, cost — like any API) and the model (input drift, prediction drift, quality when the true answers arrive).

  • 4 Lessons
  • 0 Commands

$ run as a normal user# run as root (or with sudo)

6.1

Watch the service

Export metrics in Prometheus format and alert like for any API.

metrics.py
from prometheus_client import Counter, Histogram, make_asgi_app
 
PREDICTIONS = Counter("predictions_total", "Predictions served", ["model_version", "result"])
LATENCY = Histogram("prediction_seconds", "Time per prediction")
# in the /predict handler:  with LATENCY.time(): ...   PREDICTIONS.labels("v3", "ok").inc()
metrics_app = make_asgi_app()
MetricAlert when
Error rateAbove 1 % for 5 minutes
p95 latencyAbove the agreed limit
Requests per secondSudden drop (clients broken) or spike (abuse)
GPU / CPU use, costOver budget

6.2

Detect data drift

Drift = the live inputs (or outputs) no longer look like the training data. The model may still answer, but worse.

DriftExample
Data driftAverage order value doubled after a price change
Concept driftFraud patterns changed; old rules learned by the model no longer hold
Prediction driftThe model suddenly says "fraud" twice as often
drift_report.py
import pandas as pd
from evidently import Report
from evidently.presets import DataDriftPreset
 
reference = pd.read_parquet("training_sample.parquet")
current = pd.read_parquet("last_24h_inputs.parquet")
report = Report([DataDriftPreset()])
result = report.run(current_data=current, reference_data=reference)
result.save_html("drift.html")

6.3

Measure real quality

When the true answers arrive later (was it really fraud?), join them with the logged predictions and compute the real metrics.

  • Log every prediction with an ID, the model version and the inputs (without sensitive data where possible).
  • Store the true labels when they come in.
  • A daily job computes precision/recall per model version and alerts on a drop.

6.4

Close the loop

Monitoring triggers action.

SignalAction
Drift above the limitStart the training pipeline with fresh data
Quality dropRoll back to the previous champion
Latency / cost problemScale, use a smaller model, batch requests

Remember

Monitoring without an owner and an action is just a dashboard. Decide who reacts to every alert.