ML Testing Infrastructure

Building a complete ML test pyramid covering data validation, behavioral model tests, pipeline determinism, and serving contracts.

Overview

Why ML systems need specialized testing

Unit, integration and end-to-end tests apply to ML systems but are not enough on their own. A mature ML testing setup extends the standard test pyramid with layers for data and model behavior.

Three failure modes traditional tests miss

  • Silent data quality degradation: bad data trains a bad model without any error.
  • Unexpected behavior on edge inputs: inputs at the edge of the distribution.
  • Training non-determinism: the pipeline produces different results run to run.

To catch them, the suite has six layers. Each one checks something different and runs at a different moment, and together they follow a model from the first commit to the staging endpoint.

  • Unit tests check transformations, feature logic, pre- and post-processing, and forward-pass shapes. They run with pytest on every commit.
  • Integration tests check that the pipeline stages compose correctly. They run on a small synthetic dataset whenever the pipeline changes.
  • Data validation tests check schema, nulls, ranges, cardinality and drift. They run on every new data batch, with Great Expectations, Soda or TFDV.
  • Training pipeline tests check determinism, convergence and overfitting. They run on CPU in CI on every training code commit.
  • Behavioral tests check invariance, direction and minimum functionality. They run with pytest parametrize after training and before the model is registered.
  • Serving tests check the schema contract, the latency SLO and throughput. They run as load and contract tests against the staging endpoint.

The sections below take the layers one at a time.

Interview questions

  • Design an ML test suite for a text classification model that catches data quality issues, behavioral regressions, and serving contract violations.
  • How would you implement and maintain a behavioral test suite for an ML model that evolves over time?
  • Describe a complete CI/CD pipeline for an ML project that integrates all testing layers and production deployment gates.

Sign up free to read the full topic

More MLOps & LLMOps topics

Start free on Cariara · Coding problems · System design studio