Google Professional Machine Learning Engineer Question 307
Select 3Google Cloud PlatformYou are working on deploying a machine learning model on Google Cloud. Your team has trained the model using PyTorch, but the serving platform your organization uses requires TensorFlow SavedModel format for deployment. Which of the following steps would allow you to successfully deploy your PyTorch model on the serving platform?
- A
Convert the PyTorch model to ONNX format and then convert it to TensorFlow SavedModel format.
- B
Deploy the PyTorch model directly using AI Platform Prediction without any conversion.
- C
Export the PyTorch model as TorchScript and use a custom prediction routine to serve it.
- D
Use TensorFlow's
tf.keras.models.load_model()to directly load the PyTorch model. - E
Convert the PyTorch model to TensorFlow SavedModel format using an appropriate library like ONNX or a custom script.
Show answer and explanation
Correct answers: A, C, E
Explanation
When serving models trained in PyTorch on a platform that requires TensorFlow SavedModel format, you can either convert the PyTorch model to TensorFlow SavedModel format (e.g., via ONNX or a custom script) or use an alternative like exporting the model as TorchScript and serving it with a custom routine. Direct deployment without conversion or loading a PyTorch model in TensorFlow's API is not possible due to incompatibilities between the frameworks.
- A. Correct.
Correct. Converting the PyTorch model to ONNX format and then to TensorFlow SavedModel format is a valid approach because ONNX serves as an intermediate representation that is interoperable with various frameworks.
- B. Incorrect.
Incorrect. While AI Platform Prediction allows deployment of models, it does not natively support PyTorch models without a custom container or conversion.
- C. Correct.
Correct. Exporting the model as TorchScript and using a custom prediction routine is an alternative approach to serving PyTorch models on AI Platform Prediction.
- D. Incorrect.
Incorrect. TensorFlow's
tf.keras.models.load_model()cannot load PyTorch models directly as they are fundamentally different frameworks. - E. Correct.
Correct. Using appropriate tools or libraries like ONNX or a custom script to convert a PyTorch model to TensorFlow SavedModel format ensures compatibility with TensorFlow-based serving platforms.