ML deployment testing
Why This Matters
The model that passed every test lives in a notebook. The model your users meet is a converted, packaged version of it, running on other hardware, behind an API, next to the version it replaces. Every one of those steps can change its behaviour. Deployment testing checks that the model still works where it is going to work.
What you will learn
- The forms of ML deployment testing: installability, rollback, canary, shadow, model conversion, cross-device and API testing
- When to use each, and what each catches
- A checklist for taking a model to production
Syllabus: AI-7.1.2.
The forms of deployment testing
MLS deployment testing verifies that the system works correctly and reliably in the target environment: cloud, edge or mobile.
| Form | What it checks |
|---|---|
| Installability testing | Installation, configuration and uninstallation work in every supported environment, including dependencies such as GPU drivers and the installation scripts |
| Rollback testing | The system can return to a stable state after a failed deployment: the model only, or the full system including the data pipeline. It must be tested before the deployment, to be sure the way back works when it is needed. |
| Canary testing | The new model gets a small share of production traffic (say 5% of users). Latency, accuracy and error rates are monitored, so a regression is caught before everyone is affected. |
| Shadow testing | The new model runs in parallel with production, on the same live requests, but its answers are not used. Outputs are compared safely, revealing regressions and data drift without any risk for users. |
| Model conversion testing | After converting the model to a deployment format (for mobile, edge or a faster runtime): accuracy, consistent behaviour and efficiency (inference speed, memory) are verified again |
| Cross-device testing | Correct behaviour on the whole intended range of targets, from mobile and edge devices to cloud servers |
| API testing | The interface is standards-compliant, handles input and output correctly, gives clear error messages, and integrates with data feeds, clients and the pipeline |
Canary or shadow? Both use live traffic. Canary exposes some real users to the new model, so it measures real outcomes but carries some risk. Shadow exposes nobody, so it is safe, but it can only compare outputs, not real outcomes such as whether the user clicked or repaid.
The practice API as an example
The ML practice API you have used throughout the course is an example of what API testing covers. Your setup tests check that it is reachable; a real API test suite would also check, for example:
- invalid input gets a
400with a clear error message that names the field (tryPOST /api/ml/predictwith an age of 150) - the response always has the documented fields and types
- an unknown model version (
?model=v3) is rejected, not silently replaced by a default - the batch endpoint rejects more than 100 applicants
- the documented OpenAPI description matches the real behaviour
A deployment checklist
Before a new model version goes to production:
- Installability: the package installs cleanly in a fresh copy of the production environment, with the pinned dependency versions.
- Smoke test: the deployed model answers a few known requests correctly.
- Conversion: accuracy and latency of the converted model, on the target hardware, are within agreed limits of the original.
- Cross-device: the same on every supported target.
- API: contract, errors and limits as documented.
- Rollback: tested; the previous version can be restored, with its pipeline, within the agreed time.
- Shadow run on live traffic: differences from the current model analysed (back-to-back, lesson 49).
- Canary release to a small share of users, with monitoring and alarm thresholds; then gradually more.
- Monitoring in place for drift and performance (lesson 47).
Exercise
A bank wants to replace its fraud model. A wrong model could block thousands of legitimate payments within minutes. Which deployment tests would you plan, in which order, and why?
Show suggested answer
- Installability and model conversion testing in a production-like environment: the converted model must match the original’s accuracy and meet the latency limit (payments wait for the answer).
- API testing: contract, error handling, behaviour under load.
- Rollback testing, before anything goes live: the old model and its pipeline can be restored within minutes.
- Shadow testing for a week or more: the new model scores every live transaction without blocking any. Compare its flags with the current model’s (back-to-back) and with confirmed fraud cases as they come in.
- Canary release to a small share (1 to 5%) of transactions, with tight alarm thresholds on the block rate and on customer complaints; roll back automatically if exceeded.
- Gradual increase, with monitoring for drift.
Shadow comes before canary because a wrong fraud model harms customers immediately; shadow lets you see its behaviour on real traffic with no one affected.
Exam-style questions
1. A new model processes the same live requests as the production model, but its outputs are not returned to users. What is this?
- A. Canary testing
- B. Shadow testing
- C. Rollback testing
- D. Installability testing
Show answer
2. When should rollback testing be performed?
- A. Only after a failed deployment
- B. Before deployment, to confirm that the system can return to a stable state if needed
- C. Never, because models cannot be rolled back
- D. Only for mobile apps
Show answer
3. A model is converted to a format for mobile phones. What does model conversion testing verify?
- A. The training data is still available
- B. Accuracy, consistent behaviour and efficiency (inference speed, memory) after conversion
- C. The labels of the training data
- D. The user interface of the app