Databricks Machine Learning Professional Question 150
Select 4You are tasked with deploying a trained single-node machine learning model in a Databricks environment to perform batch inference on a large distributed dataset. You decide to wrap the model inference logic in a Spark UDF (User-Defined Function). Which of the following steps are necessary to successfully deploy and run the model in parallel using Spark UDF?
- A
Serialize the trained model and ensure it is accessible to all worker nodes.
- B
Define a Python function encapsulating the model inference logic and register it as a Spark UDF.
- C
Use
spark.readto load the model directly into each worker node without serialization. - D
Broadcast the serialized model to minimize redundant data transfer to worker nodes.
- E
Apply the Spark UDF to the DataFrame column(s) containing the input data.
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To deploy a single-node machine learning model in parallel using Spark UDF in a distributed Databricks environment, the model must be serialized and made accessible to all worker nodes. A Python function encapsulating the inference logic must be defined and registered as a Spark UDF. Broadcasting the serialized model reduces data transfer overhead, and the UDF should be applied to the relevant DataFrame column(s) containing the input data for inference. This ensures efficient distributed batch inference in a Spark environment.
- A. Correct.
Correct: The trained model must be serialized (e.g., using libraries like joblib or pickle) so it can be distributed to all worker nodes.
- B. Correct.
Correct: A Python function encapsulating the model inference logic needs to be defined and then registered as a Spark UDF to enable parallel execution.
- C. Incorrect.
Incorrect: Directly loading the model using
spark.readinto each worker node is not a feasible or efficient approach for distributed environments. - D. Correct.
Correct: Broadcasting the serialized model ensures that each worker node receives the model efficiently, reducing redundant transfers.
- E. Correct.
Correct: The Spark UDF must be applied to the appropriate DataFrame column(s) containing the input data for batch inference.