How to Ensure Consistent Preprocessing Between Training and Serving?

You have trained a model by using data that was preprocessed in a batch Dataflow pipeline. Your use case requires real-time inference. You want to ensure that the data preprocessing logic is applied consistently between training and serving. What should you do?

  1. Perform data validation to ensure that the input data to the pipeline is the same format as the input data to the endpoint.
  2. Refactor the transformation code in the batch data pipeline so that it can be used outside of the pipeline. Use the same code in the endpoint. Source Reference Answer
  3. Refactor the transformation code in the batch data pipeline so that it can be used outside of the pipeline. Share this code with the end users of the endpoint.
  4. Batch the real-time requests by using a time window and then use the Dataflow pipeline to preprocess the batched requests. Send the preprocessed requests to the endpoint.

Community Votes

B
100%

100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

This question tests the mitigation of training-serving skew by reusing transformation code, trapping candidates who choose data validation or batching strategies that fail to maintain logical consistency.

To prevent training-serving skew, the preprocessing logic used during training must be identically applied during inference. The community consensus is that refactoring batch pipeline code into a reusable module for the endpoint is the correct approach.

Choosing Option A is a common mistake because while data validation is good practice, it only checks data format and does not ensure the preprocessing logic itself is consistent across environments.

Community Discussion (5 comments)

fitri001 👍 1 Selected: B
Refactored Transformation Code: By refactoring the transformation code from the batch pipeline, you can create a reusable module that performs the same preprocessing steps. Same Code in Endpoint: Utilize the refactored code within your real-time inference endpoint. This ensures the data is preprocessed identically to how it was preprocessed during training.
pinimichele01 👍 1 Selected: B
agree with guilhermebutzke
guilhermebutzke 👍 3 Selected: B
My Answer B: B. This option ensures that the preprocessing logic used during training, which has already been validated and tested, is applied consistently during real-time inference. By making the transformation code reusable outside of the batch pipeline and utilizing it in the endpoint, you ensure that the same preprocessing steps are applied to incoming data during inference, thus maintaining consistency between training and serving. A: While data validation is essential, it only ensures the format. It doesn't guarantee consistent preprocessing logic between training and serving. C: Sharing code with end-users might not be desirable for security or maintainability reasons. D: Batching introduces latency and might not be suitable for real-time needs. Additionally, using the entire Dataflow pipeline might be inefficient for individual requests.
shadz10 👍 3 Selected: B
The transformation logic code in the serving_fn function defines the serving interface of your SavedModel for online prediction. If you implement the same transformations that were used for preparing training data in the transformation logic code of the serving_fn function, it ensures that the same transformations are applied to new prediction data points when they're served. https://www.tensorflow.org/tfx/guide/tft_bestpractices
pikachu007 👍 1 Selected: B
A. Data validation: While essential, it doesn't guarantee consistency if the preprocessing logic itself differs between pipeline and endpoint. C. Sharing code with end users: This shifts the preprocessing burden to end users, potentially leading to inconsistencies and errors, and isn't feasible for real-time inference. D. Batching real-time requests: This introduces latency and might not align with real-time requirements, as users expect immediate responses.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Refactoring the transformation code into a standalone module allows it to be imported and executed directly within the inference endpoint. By embedding this logic into the serving environment (e.g., within a serving_fn), you guarantee that the exact same mathematical operations applied to training data are applied to real-time requests. This approach satisfies the real-time requirement without the latency introduced by batch processing methods.

Why the Other Options Are Wrong

Option A focuses on data validation, which confirms schema compatibility but fails to enforce that the actual preprocessing logic is identical. Option C is incorrect because it offloads preprocessing to end users, creating a poor user experience and high potential for error. Option D introduces latency through batching, which violates the real-time inference constraint and adds unnecessary architectural complexity.

Community Comment Notes

Commenters highlighted that implementing identical transformations in the serving_fn function is the standard method to define the serving interface for a SavedModel. There was unanimous agreement (100% of votes) that code reuse is the only effective way to ensure consistency, with specific references made to TensorFlow's documentation on serving functions.

Official Reference

Exam Strategy

When facing questions about training-serving skew, always look for the option that promotes code reuse between the training pipeline and the serving application. Avoid options that suggest batching for real-time needs or delegate data processing tasks to the client.

Related Analysis

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide