Machine Learning Associate ยท MLflow tracking and the model registry
Manual logging in an MLflow run
Using mlflow.start_run with log_param, log_metric, log_artifact and log_model to log parameters, metrics, artifacts and models manually, and how this differs from autologging.
Key points
- Inside
with mlflow.start_run():you record things yourself:log_paramfor hyperparameters,log_metricfor numbers (optionally with a step),log_artifactfor files such as plots, andmlflow.<flavor>.log_modelfor the model. - Autologging does this for you for supported libraries, but manual calls let you add custom values or log things autolog skips.
Source: https://mlflow.org/docs/latest/python_api/mlflow.html
Practice questions
Which call records a numeric result such as validation RMSE in the current run?
- mlflow.log_param("rmse", 0.82)
- mlflow.log_metric("rmse", 0.82)
- mlflow.log_artifact("rmse")
- mlflow.set_tag("rmse", 0.82)
Show answer
Answer: B. mlflow.log_metric("rmse", 0.82)
log_metric stores numeric values and supports a step. log_param is for configuration values, log_artifact for files, set_tag for labels.
Which of these are things you can record manually in an MLflow run?
- A hyperparameter such as max_depth
- A loss value at each epoch using the step argument
- The cluster's autoscaling worker range
- A fitted model via mlflow.sklearn.log_model
- A Unity Catalog alias via log_param
Show answer
Answer: A. A hyperparameter such as max_depth, B. A loss value at each epoch using the step argument, D. A fitted model via mlflow.sklearn.log_model
Params, metrics (with steps) and models are all logged manually. Spark cluster autoscaling settings and the registry alias are not run-logging calls.
Calling mlflow.log_param without an active run always raises an error.
Show answer
Answer: False
False. With no active run, the fluent API starts one automatically and logs into it. Using start_run explicitly is still clearer because it also ends the run.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
