MLOps Observer
← All labs

Training and serving consistency / Intermediate / 25–40 min

The model serving unscaled features

A trained regression model loads successfully but serves wrong predictions because inference skips the training-time scaler.

LAB IDmlops-02-training-serving-skewTRACK / mlops.observer
Engineer monitoring model training beside GPU servers

The scenario

A synthetic capacity predictor passes its load check yet returns unreasonable CPU predictions. Trace the model's training pipeline and inference configuration without retraining or modifying the saved model.

Mission objectives

  • Compare inference results with the training pipeline.
  • Restore the saved training-time transformation at inference.
  • Check predictions for multiple unseen inputs without replacing the model.

Lab README

The model serving unscaled features

A trained capacity prediction model loads correctly, but its predictions are wrong. Compare the training and inference paths, then restore the fitted training-time transformation without retraining or altering the model.

Before you begin

Use Bash and Python 3.11 or later in a private local environment. Install the pinned model library into a virtual environment:

LAB_VENV="$(mktemp -d)"
python3 -m venv "$LAB_VENV"
. "$LAB_VENV/bin/activate"
python -m pip install -r requirements.txt

Installing packages needs internet access. The lab trains a real scikit-learn StandardScaler and LinearRegression pipeline on synthetic data. It does not deploy a service or use a cloud account or real workload measurements.

The generated .lab-state contains a serialized model. Python model artifacts can execute code during loading: only use files created by your own lab run, never load an untrusted artifact. Setup refuses to overwrite an existing state directory.

Investigate

./setup.sh
cat training.csv
cat inference.json
./lab.sh inspect
./lab.sh predict 150 3

The arguments are synthetic requests per second and error percentage. The printed reference prediction is produced through the trained pipeline; the served prediction follows the inference configuration. Diagnose the difference and update inference.json, without changing the data, model or predictor.

./verify.sh
./teardown.sh

Verification checks the original dataset and generated model, and compares served predictions with the trained pipeline on several unseen inputs. Teardown removes only the lab-generated model and state marker; it refuses unexpected files. The fitted example does not validate production model quality, monitoring, real-world causality or deployment behavior. Deactivate and remove the temporary virtual environment separately when done.

View Markdown source ↗

Get the lab

Download and inspect the installer before running it. It checks the archive's SHA-256 digest and refuses to overwrite an existing lab directory.

curl -fsSLO https://devops.download/labs/mlops-02-training-serving-skew.sh
less mlops-02-training-serving-skew.sh
bash mlops-02-training-serving-skew.sh
cd labs/mlops-02-training-serving-skew
./setup.sh

When you've made your changes, run ./verify.sh. Remove lab resources with ./teardown.sh.

Download the archive instead ↗

Need a nudge?

Hint #1

The regression estimator was trained on transformed features, not raw request values.

Hint #2

Inspect inference.json and the saved pipeline; keep the trained artifact and inputs unchanged.

Hint #3 · Learning paths on opsbreakfix.com

Explore learning paths ↗

Solved it?

Continue learning with the paths on opsbreakfix.com.

Continue to opsbreakfix.com ↗