Course contentsShow
← Machine Learning and Deep Learning
Lesson 2898 of 3,53863. Model Serving and Inference InfrastructureFree lesson

Preprocessing in Serving Pipelines

Ensuring feature transformations match training exactly by versioning preprocessing code alongside model weights.

Preprocessing in Serving Pipelines

What you'll learn: How to guarantee that feature transformations applied during inference exactly match those used during training by versioning preprocessing code alongside model weights.

The Preprocessing Consistency Problem

When your model was trained, raw input data went through specific transformations: scaling numerical features, encoding categorical variables, tokenizing text, or normalizing images. If these exact same transformations aren't applied during serving, your model receives subtly different inputs than it expects—leading to degraded predictions or outright failures.

This is the training-serving skew problem. Your model learned patterns from transformed data, but now receives differently transformed data.

Versioning Preprocessing Code with Models

The solution is treating preprocessing logic as an inseparable part of your model artifact. When you save model weights, you must also save:

  • The preprocessing code itself
  • Library versions used (scikit-learn==1.2.0, etc.)
  • Any fitted parameters (mean/std from training data, vocabulary mappings, etc.)

Think of it like a recipe: the cooking instructions (preprocessing) are just as important as the ingredients list (model weights). Forgetting to preheat the oven changes the final dish entirely.

Implementation Patterns

Package your preprocessor and model together. Save fitted sklearn transformers alongside your neural network. Use the same container image for training and serving to lock library versions. Store preprocessing configurations in your model registry with clear version tags.

When loading a model for serving, load its specific preprocessing pipeline first. Never assume "the current preprocessing code" matches what the model needs.

Key Takeaway: Training-serving skew breaks production models—always version and deploy preprocessing transformations as an atomic unit with model weights to ensure identical feature engineering at inference time.