MLflow-tracking

Introductie tot MLflow

Weston Bassler

Senior MLOps Engineer

Data over modellen tracken

data

1 istock.com
Introductie tot MLflow

Wat is MLflow Tracking?

  • Model-metrics
    • F1, recall, accuracy, MSE, enz.
  • Parameters
    • libraryspecifiek
  • code
    • train.py
  • overige artifacts
    • tokenizers, pickle, enz.
Introductie tot MLflow

Trainingsruns

  • Hoe MLflow is opgebouwd
  • Nieuwe run = nieuwe modeltraining
  • Een run hoort bij een experiment
  • Aangeroepen via mlflow.start_run()

Traning Runs

1 unsplash.com
Introductie tot MLflow

Een trainingsrun starten

import mlflow

# Start een run
mlflow.start_run()
<ActiveRun: >
# Beëindig een run
mlflow.end_run()
Introductie tot MLflow

Een variabele voor de run instellen

import mlflow
# Stel experiment in
mlflow.set_experiment("My Experiment")
# Start een run
run = mlflow.start_run()

# Print run-info run.info
<RunInfo: artifact_uri='./mlruns/0/9de5df4d19994546b03dce09aefb58af/artifacts', 
  end_time=None, experiment_id='31', lifecycle_stage='active', 
  run_id='9de5df4d19994546b03dce09aefb58af', run_name='big-owl-145', 
  run_uuid='9de5df4d19994546b03dce09aefb58af', start_time=1676838126924, 
  status='RUNNING', user_id='user'>
Introductie tot MLflow

Loggen naar MLflow Tracking

  • Metrics

    • log_metric("accuracy", 0.90)
    • log_metrics({"accuracy": 0.90, "loss": 0.50})
  • Parameters

    • log_param("n_jobs", 1)
    • log_params({"n_jobs": 1, "fit_intercept": False})
  • Artifacts

    • log_artifact("file.py")
    • log_artifacts("./directory/")
Introductie tot MLflow

Een run loggen

import mlflow
# Stel experiment in
mlflow.set_experiment("LR Experiment")

# Start een run mlflow.start_run()
# Modeltraining hier lr = LogisticRegression(n_jobs=1) # Modellevaluatie hier lr.fit(X, y) score = lr.score(X, y)
# Log een metric
mlflow.log_metric("score", score)

# Log een parameter
mlflow.log_param("n_jobs", 1)

# Log een artifact
mlflow.log_artifact("train_code.py")
Introductie tot MLflow

MLflow-UI openen

# Open MLflow Tracking-UI
mlflow ui

Ga naar: http://localhost:5000

Introductie tot MLflow

Tracking-UI: experimentweergave

tracking-ui

Introductie tot MLflow

Tracking-UI: runweergave

run-ui

Introductie tot MLflow

Laten we oefenen!

Introductie tot MLflow

Preparing Video For Download...