Giới thiệu về MLflow Models

Giới thiệu về MLflow

Weston Bassler

Senior MLOps Engineer

MLflow Models

  • Đơn giản hóa tích hợp thư viện ML

  • Đơn giản hóa triển khai

  • Quy ước gọi là "Flavor"

flavors

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

Flavor tích hợp sẵn

HÌNH ẢNH VỀ FLAVOR

  • Viết công cụ tùy chỉnh từ thư viện ML

  • Flavor giúp đơn giản hóa việc thêm mã tùy chỉnh

# Import flavor từ module mlflow
import mlflow.FLAVOR
1 mlflow.org
Giới thiệu về MLflow

Autolog

# Tự động log mô hình và chỉ số
mlflow.FLAVOR.autolog()
# Flavor tích hợp cho scikit-learn
mlflow.sklearn.autolog()
Giới thiệu về MLflow

Flavor Scikit-learn

# Import scikit-learn
import mlflow
from sklearn.linear_model import \
    LinearRegression

# Dùng auto-logging mlflow.sklearn.autolog()
# Huấn luyện mô hình
lr = LinearRegression()
lr.fit(X, y)

Mô hình sẽ được ghi log tự động khi gọi model.fit()

Giới thiệu về MLflow

Chỉ số thường dùng

  • Hồi quy
    • mean squared error
    • root mean squared error
    • mean absolute error
    • r2 score
  • Phân loại
    • precision score
    • recall score
    • f1 score
    • accuracy score

Tham số thường dùng

MODEL.get_params()
Giới thiệu về MLflow

Tham số thường dùng

# Huấn luyện mô hình
lr = LinearRegression()
lr.fit(X, y)

# Lấy tham số params = lr.get_params(deep=True)
params
{'copy_X': True, 'fit_intercept': True, 'n_jobs': None, 
    'normalize': 'deprecated', 'positive': False}
Giới thiệu về MLflow

Tự động log tham số

tham số

# Mô hình
lr = LinearRegression()
lr.fit(X, y)
Giới thiệu về MLflow

Tự động log chỉ số

chỉ số

# Mô hình
lr = LinearRegression()
lr.fit(X, y)
Giới thiệu về MLflow

Định dạng lưu trữ

Cấu trúc thư mục của một mô hình:

model/
    MLmodel
    model.pkl
    python_env.yaml
    requirements.txt
# Autolog
mlflow.sklearn.autolog()

Artifacts

Giới thiệu về MLflow

Nội dung tệp MLmodel

artifact_path: model
flavors:
  python_function:
    env:
      virtualenv: python_env.yaml
    loader_module: mlflow.sklearn
    model_path: model.pkl
    predict_fn: predict
    python_version: 3.10.8
  sklearn:
    code: null
    pickled_model: model.pkl
    serialization_format: cloudpickle
    sklearn_version: 1.1.3
Giới thiệu về MLflow

MLmodel

MLmodel

Giới thiệu về MLflow

Ayo berlatih!

Giới thiệu về MLflow

Preparing Video For Download...