Autologging

MLflow · Essentials · 8 min

Autolog gives complete runs with one line, so nothing important is forgotten.

mlflow.autolog() patches supported libraries so that training calls log themselves. For scikit-learn, calling fit creates (or uses) a run and records:

  • all estimator parameters from get_params(),
  • training metrics such as accuracy, F1, ROC AUC for classifiers or MSE and R2 for regressors,
  • the fitted model with an inferred signature,
  • for searches like GridSearchCV, the best parameters and child runs for candidates.

Library-specific versions offer more options, e.g. mlflow.sklearn.autolog(log_models=False, max_tuning_runs=10). Supported integrations include scikit-learn, XGBoost, LightGBM, Keras/TensorFlow, PyTorch Lightning, Spark, statsmodels, and GenAI libraries such as OpenAI and LangChain, where autolog produces traces instead.

Autolog composes with manual logging: inside a with mlflow.start_run(): block, your own log_metric calls join the same run. Evaluation metrics on a test set are not logged automatically for sklearn unless you call a scoring function (MLflow records post-training metrics for calls like model.score or sklearn.metrics functions after fit).

Call autolog() before you import and train, and turn it off with mlflow.autolog(disable=True). It is ideal for exploration; for production pipelines many teams log explicitly so the contents of a run are deliberate.

Example

import mlflow
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

mlflow.sklearn.autolog()
X, y = load_iris(return_X_y=True)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, random_state=0)

with mlflow.start_run() as run:
    model = RandomForestClassifier(n_estimators=50, max_depth=3, random_state=0)
    model.fit(X_tr, y_tr)                 # params, train metrics, model logged
    model.score(X_te, y_te)               # post-training metric logged too

r = mlflow.get_run(run.info.run_id)
print(r.data.params["max_depth"])         # 3
print(sorted(k for k in r.data.metrics if k.startswith("training_"))[:3])
# ['training_accuracy_score', 'training_f1_score', 'training_log_loss']

Remember

  • mlflow.autolog() logs params, metrics and the model for supported libraries
  • Manual logging inside the same run adds to autologged data
  • GenAI library autolog produces traces rather than training metrics

Watch out for

  • Enabling autolog after the model was already trained, so nothing gets captured.

Check yourself

  1. Where do autologged sklearn metrics come from by default?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: mlflow.org/docs/latest/ml/tracking/autolog/

Builds on

Unlocks

Nothing builds on this yet.