แนะนำ MLflow Models

MLflow เบื้องต้น

Weston Bassler

Senior MLOps Engineer

MLflow Models

  • รองรับการใช้งานไลบรารี ML ได้ง่ายขึ้น

  • ทำให้การ Deploy ง่ายขึ้น

  • ใช้แนวทางที่เรียกว่า "Flavors"

flavors

1 unsplash.com
MLflow เบื้องต้น

Built-In Flavors

ภาพ Flavors ต่าง ๆ

  • เขียนเครื่องมือเองจากไลบรารี ML

  • Flavors ช่วยลดความจำเป็นในการเขียนโค้ดเอง

# Import flavor from mlflow module
import mlflow.FLAVOR
1 mlflow.org
MLflow เบื้องต้น

Autolog

# Automatically log model and metrics
mlflow.FLAVOR.autolog()
# Scikit-learn built-in flavor
mlflow.sklearn.autolog()
MLflow เบื้องต้น

Scikit-learn Flavor

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

# Using auto-logging mlflow.sklearn.autolog()
# Train the model
lr = LinearRegression()
lr.fit(X, y)

โมเดลจะถูกบันทึกอัตโนมัติเมื่อเรียก model.fit()

MLflow เบื้องต้น

เมตริกที่ใช้บ่อย

  • Regression
    • mean squared error
    • root mean squared error
    • mean absolute error
    • r2 score
  • Classification
    • precision score
    • recall score
    • f1 score
    • accuracy score

พารามิเตอร์ที่ใช้บ่อย

MODEL.get_params()
MLflow เบื้องต้น

พารามิเตอร์ที่ใช้บ่อย

# Train the model
lr = LinearRegression()
lr.fit(X, y)

# Get params params = lr.get_params(deep=True)
params
{'copy_X': True, 'fit_intercept': True, 'n_jobs': None, 
    'normalize': 'deprecated', 'positive': False}
MLflow เบื้องต้น

Autolog พารามิเตอร์

พารามิเตอร์

# Model
lr = LinearRegression()
lr.fit(X, y)
MLflow เบื้องต้น

Autolog เมตริก

เมตริก

# Model
lr = LinearRegression()
lr.fit(X, y)
MLflow เบื้องต้น

รูปแบบการจัดเก็บ

โครงสร้างไดเรกทอรีของโมเดล:

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

Artifacts

MLflow เบื้องต้น

เนื้อหาของ 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
MLflow เบื้องต้น

MLmodel

MLmodel

MLflow เบื้องต้น

มาฝึกกันเถอะ!

MLflow เบื้องต้น

Preparing Video For Download...