Theo dõi với MLflow

Giới thiệu về MLflow

Weston Bassler

Senior MLOps Engineer

Theo dõi dữ liệu về mô hình

dữ liệu

1 istock.com
Giới thiệu về MLflow

MLflow Tracking là gì?

  • Chỉ số mô hình
    • F1, Recall, Accuracy, MSE, v.v.
  • Tham số
    • theo thư viện
  • mã nguồn
    • train.py
  • tạo kiện khác
    • tokenizer, pickle, v.v.
Giới thiệu về MLflow

Lượt huấn luyện

  • Cách MLflow được tổ chức
  • Mỗi lượt chạy là một lần huấn luyện mới
  • Lượt chạy nằm trong một thí nghiệm
  • Gọi bằng mlflow.start_run()

Lượt huấn luyện

1 unsplash.com
Giới thiệu về MLflow

Bắt đầu một lượt huấn luyện

import mlflow

# Start a run
mlflow.start_run()
<ActiveRun: >
# End a run
mlflow.end_run()
Giới thiệu về MLflow

Đặt biến cho lượt huấn luyện

import mlflow
# Set experiment
mlflow.set_experiment("My Experiment")
# Start a 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'>
Giới thiệu về MLflow

Ghi log vào MLflow Tracking

  • Chỉ số (Metrics)

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

    • log_param("n_jobs", 1)
    • log_params({"n_jobs": 1, "fit_intercept": False})
  • Tạo kiện (Artifacts)

    • log_artifact("file.py")
    • log_artifacts("./directory/")
Giới thiệu về MLflow

Ghi log một lượt chạy

import mlflow
# Set Experiment
mlflow.set_experiment("LR Experiment")

# Start a run mlflow.start_run()
# Mã huấn luyện mô hình lr = LogisticRegression(n_jobs=1) # Mã đánh giá mô hình lr.fit(X, y) score = lr.score(X, y)
# Ghi một chỉ số
mlflow.log_metric("score", score)

# Ghi một tham số
mlflow.log_param("n_jobs", 1)

# Ghi một tạo kiện
mlflow.log_artifact("train_code.py")
Giới thiệu về MLflow

Mở giao diện MLflow

# Mở giao diện MLflow Tracking
mlflow ui

Truy cập: http://localhost:5000

Giới thiệu về MLflow

Giao diện thí nghiệm trong Tracking UI

giao diện theo dõi

Giới thiệu về MLflow

Giao diện lượt chạy trong Tracking UI

giao diện lượt chạy

Giới thiệu về MLflow

Hãy luyện tập!

Giới thiệu về MLflow

Preparing Video For Download...