Bitzu

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_param for hyperparameters, log_metric for numbers (optionally with a step), log_artifact for files such as plots, and mlflow.<flavor>.log_model for 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

Single choice

Which call records a numeric result such as validation RMSE in the current run?

  1. mlflow.log_param("rmse", 0.82)
  2. mlflow.log_metric("rmse", 0.82)
  3. mlflow.log_artifact("rmse")
  4. 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.

Select all that apply

Which of these are things you can record manually in an MLflow run?

  1. A hyperparameter such as max_depth
  2. A loss value at each epoch using the step argument
  3. The cluster's autoscaling worker range
  4. A fitted model via mlflow.sklearn.log_model
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Machine Learning Associate topics in this module