Sub topic 16
Orchestrating the Pipeline
Assume you know the basic machine learning workflow, Python, batch or online serving, and CI/CD. Orchestration is the system that starts pipeline tasks, orders them, passes artifacts between them, retries safe failures, and records each run.
A retraining pipeline should make dependencies explicit:
- A schedule or trigger starts a run.
- Data validation checks schema, freshness, missing values, ranges, and suspicious volume changes.
- Training creates a challenger model.
- Evaluation compares the challenger with the current champion.
- A promotion step registers the model only when the evaluation gate passes.
- Deployment rolls out the approved model.
- Monitoring records the result and supports rollback.
Each task should have a clear input and output. For example, validation produces a data report, training produces a model and metrics, and evaluation produces a pass or fail decision.
Dependencies, retries, and artifacts
An orchestrator such as GitHub Actions, Airflow, Dagster, or Kubeflow stores task status and applies dependency rules. A failed validation task should stop training. A temporary network failure while uploading an artifact may be retried. A failed data-quality check should not be retried repeatedly because the same bad input will produce the same failure.
Use immutable artifacts. Give each run an identifier such as a timestamp plus a commit hash. Store the model, metrics, validation report, configuration, source-code revision, and input-data version under that identifier. This creates lineage: you can explain which data and code produced a deployed model.
Tasks should be idempotent. An idempotent task can run twice without producing conflicting results. Write outputs to a run-specific location, then promote a completed artifact by reference. Do not overwrite the champion during training.
A workflow definition
This GitHub Actions workflow runs weekly or manually. The needs fields create the dependency graph.
name: retrain
on:
schedule:
- cron: "0 3 * * 1"
workflow_dispatch:
concurrency:
group: retraining
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install -r requirements.txt
- run: python validate_data.py
train:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install -r requirements.txt
- run: python train_pipeline.py --output model.joblib
- uses: actions/upload-artifact@v4
with:
name: challenger-model
path: model.joblib
evaluate:
needs: train
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: challenger-model
- run: python evaluate.py --model model.joblib --champion champion.joblib
deploy:
needs: evaluate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: challenger-model
- run: python deploy.py --model model.joblib --strategy canaryThe evaluation command must exit with a nonzero status when the challenger fails the gate. That status prevents the deploy job from running. In production, add approval for promotion, secrets through the platform's secret store, and notifications for every failure or deployment.
Exercise
Why should a failed validation task block the training task?
Show answer
Training on invalid or poisoned data can create a bad challenger and waste compute. Blocking the dependency keeps that model out of evaluation and promotion.