Sub topic 10
Stages of an Automated Retraining Pipeline
Assume you know the basic machine learning workflow: training, validation, testing, and deployment. You should also be comfortable with Python, NumPy, batch or online serving, version control, and CI/CD. This chapter follows what happens after a retraining trigger fires.
A retraining pipeline is a repeatable workflow that turns newly collected data into a candidate model. Each stage produces an artifact, such as a validated dataset, a model file, or an evaluation report.
The pipeline stages
1. Create a reproducible data snapshot
The pipeline records exactly which rows and time range it uses. It should capture the data location, extraction query, feature definitions, and label-generation time. This snapshot prevents a later rerun from silently using different data.
2. Validate the data
Validation checks schema, missing values, value ranges, duplicate records, label availability, and unexpected category values. A failed check stops the pipeline before training. The output is a validation report, not just a success flag.
3. Build features
The pipeline transforms raw records into the model's input columns. Training and serving must use compatible transformations. Store the feature code version and the resulting dataset identifier with the run.
4. Train the challenger
The challenger is the newly trained candidate model. The training stage records its code version, dependency versions, hyperparameters, random seed, and training-data identifier. It outputs a model artifact and training metrics.
5. Evaluate against the champion
The champion is the model currently serving predictions. Evaluate both models on a fixed, representative test set. Check the main metric, important slices, latency, and resource use. An evaluation report should explain why promotion passed or failed.
6. Register and roll out
A model registry stores approved model artifacts and their metadata. Promotion changes the model's lifecycle state; it should not immediately send all traffic to the candidate. Use shadow traffic or a small canary release first, then keep a tested rollback target.
| Stage | Main output | Stop when |
|---|---|---|
| Snapshot | Data manifest | The source is unavailable |
| Validation | Validation report | Schema or quality checks fail |
| Training | Challenger model | Training or reproducibility fails |
| Evaluation | Comparison report | The challenger regresses |
| Rollout | Deployment record | Canary signals breach limits |
A simple runner can make stage boundaries explicit:
from dataclasses import dataclass
@dataclass
class Run:
data_id: str
code_version: str
model_id: str | None = None
def validate(run: Run) -> None:
if not run.data_id or not run.code_version:
raise ValueError("Missing lineage information")
def train(run: Run) -> None:
run.model_id = f"challenger-{run.data_id}-{run.code_version}"
run = Run(data_id="orders-2026-11-30", code_version="git:a13f9c2")
validate(run)
train(run)
print(run.model_id)Exercise
Why should evaluation happen before registry promotion and rollout?
Show answer
Evaluation prevents an invalid or weaker challenger from becoming the new production model.