How to Ensure Consistent Preprocessing Between Training and Serving?
Short answer
B 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.
Question
Key Takeaways
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.
Common mistake: 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.
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
https://www.tensorflow.org/guide/saved_model
This link opens the official vendor documentation in a new tab.
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.
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 5 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 5
-
guilhermebutzke 👍 3 Answered BMy 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 Answered BThe 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 Answered BA. 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.
-
fitri001 👍 1 Answered BRefactored 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 Answered Bagree with guilhermebutzke
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All PMLE Questions
Access 65 questions with complete answers and detailed explanations.
View Full PMLE Practice Test →