Databricks Machine Learning Associate Question 485
Single answerA data scientist is using Databricks to manage machine learning models. They want to add metadata to a registered model in the MLflow Model Registry to indicate the environment it is intended for (e.g., 'staging' or 'production'). Which of the following code snippets correctly sets a tag for this purpose?
- A
mlflow.set_tag('environment', 'staging')
- B
mlflow.log_param('environment', 'staging')
- C
from mlflow.tracking import MlflowClient; MlflowClient().set_registered_model_tag('model_name', 'environment', 'staging')
- D
from mlflow.tracking import MlflowClient; MlflowClient().set_tag('run_id', 'environment', 'staging')
Show answer and explanation
Correct answer: C
Explanation
In Databricks and MLflow, tags can be used to add metadata to different entities. To set a tag for a registered model in the MLflow Model Registry, you must use the set_registered_model_tag method from the MlflowClient class. This method allows you to associate metadata with a registered model, such as its intended environment ('staging', 'production', etc.). The other options are either for logging run-specific metadata or use incorrect methods for setting tags.
- A. Incorrect.
This option is incorrect because
mlflow.set_tagis used to set tags for a specific run, not for a registered model in the Model Registry. - B. Incorrect.
This option is incorrect because
mlflow.log_paramlogs a parameter for a run, which is unrelated to setting tags on a registered model. - C. Correct.
This option is correct because
MlflowClient().set_registered_model_tagis the appropriate method for adding a tag to a registered model in the MLflow Model Registry. The method requires the model name, the tag key, and the tag value. - D. Incorrect.
This option is incorrect because
MlflowClient().set_tagis used to set tags for runs and requires a run ID, not for registered models in the Model Registry.