How to Ensure Consistent Preprocessing for Online TF Predictions?

PMLE By islever Editorial Last updated

Short answer

D Create an Apache Beam pipeline to read the data from BigQuery and preprocess it by using TensorFlow Transform and Dataflow.

Question

You need to develop a custom TensorFlow model that will be used for online predictions. The training data is stored in BigQuery You need to apply instance-level data transformations to the data for model training and serving. You want to use the same preprocessing routine during model training and serving. How should you configure the preprocessing routine?
  1. Create a BigQuery script to preprocess the data, and write the result to another BigQuery table.
  2. Create a pipeline in Vertex AI Pipelines to read the data from BigQuery and preprocess it using a custom preprocessing component.
  3. Create a preprocessing function that reads and transforms the data from BigQuery. Create a Vertex AI custom prediction routine that calls the preprocessing function at serving time.
  4. Create an Apache Beam pipeline to read the data from BigQuery and preprocess it by using TensorFlow Transform and Dataflow. Correct Answer

Key Takeaways

Tests the implementation of reproducible instance-level feature engineering; the common trap is selecting BigQuery or Vertex AI Pipelines, which cannot reliably enforce code parity during low-latency online serving.

This question evaluates best practices for unifying training and serving data transformations in Google Cloud ML workflows. Candidates should recognize that Apache Beam paired with TensorFlow Transform via Dataflow guarantees identical preprocessing logic for both phases.

Common mistake: Option C is often selected due to its focus on custom prediction routines, but it incorrectly shifts preprocessing responsibility to the client, risking inconsistency and unacceptable latency for real-time inference.

Expert Analysis

Why the Answer Is Correct

Combining Apache Beam with TensorFlow Transform (TFT) and running it on Dataflow creates a standardized preprocessing pipeline that outputs a serialized graph. This graph is automatically bundled with the trained TensorFlow model, ensuring that every instance-level transformation applied during training is executed identically during online serving. Google’s official ML architecture guidelines explicitly recommend this pattern to eliminate training-serving skew.

Why the Other Options Are Wrong

Option A relies on BigQuery scripts, which are optimized for batch analytics rather than low-latency online inference and do not share executable code with the serving environment. Option B uses Vertex AI Pipelines for orchestration, but it does not inherently solve the problem of baking preprocessing logic into the serving runtime for individual requests. Option C suggests a custom prediction routine, but requiring clients or end-users to replicate the preprocessing logic introduces version drift, increases network overhead, and violates the principle of server-side consistency.

Community Comment Notes

The community overwhelmingly supports Option D, citing official TensorFlow best practices that prioritize Dataflow and TFT for consistent instance-level transformations [1][2]. Multiple candidates reference the TFX documentation table recommending this exact stack to prevent training-serving skew [4]. Comments also highlight that shifting preprocessing to clients or relying on external SQL scripts breaks the unified code requirement emphasized in the prompt [3][5].

Official Reference

Exam Strategy

When exam scenarios stress identical preprocessing for training and online serving, prioritize architectures that serialize the transformation graph alongside the model. Always rule out client-side preprocessing or external database queries for real-time inference, as they inherently introduce latency and version mismatch risks.

Community Votes

D
100%

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

Discussion 6 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 6

  1. guilhermebutzke 👍 7 Answered D
    My answer: D According to this documentation, it is very clear that using BigQuery is not a good approach for online prediction at the instance level. That's because we won't use the same code for both training and prediction serving. In the same documentation, the final table on the page recommends using Dataflow with TensorFlow Transform for instance-level data transformation. https://www.tensorflow.org/tfx/guide/tft_bestpractices
  2. pikachu007 👍 2 Answered C
    Addressing limitations of other options: 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.
  3. Yan_X 👍 2 Answered D
    D - Apache Beam + tf.transform or Dataflow. https://notebook.community/GoogleCloudPlatform/training-data-analyst/courses/machine_learning/deepdive/04_advanced_preprocessing/a_dataflow
  4. pinimichele01 👍 1 Answered D
    https://www.tensorflow.org/tfx/guide/tft_bestpractices#preprocessing_options_summary
  5. shadz10 👍 1 Answered D
    D- Vertex AI isn't designed for instance-level data transformations
Show 1 more comment
  1. BlehMaks 👍 1 Answered A
    the simplest way

Reader comments & corrections

No reader corrections 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.

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide