MLflow 모델 소개

MLflow 소개

Weston Bassler

Senior MLOps Engineer

MLflow 모델

  • ML 라이브러리 통합 단순화

  • 배포 간소화

  • "플레이버"라는 규칙

플레이버

1 unsplash.com
MLflow 소개

내장 플레이버

플레이버 이미지

  • ML 라이브러리용 커스텀 도구 작성

  • 플레이버로 커스텀 코드 도입이 쉬워짐

# mlflow 모듈에서 플레이버 임포트
import mlflow.FLAVOR
1 mlflow.org
MLflow 소개

자동 로깅

# 모델과 지표를 자동 로깅
mlflow.FLAVOR.autolog()
# scikit-learn 내장 플레이버
mlflow.sklearn.autolog()
MLflow 소개

Scikit-learn 플레이버

# scikit-learn 임포트
import mlflow
from sklearn.linear_model import \
    LinearRegression

# 자동 로깅 사용 mlflow.sklearn.autolog()
# 모델 학습
lr = LinearRegression()
lr.fit(X, y)

model.fit() 시 모델이 자동으로 로깅됩니다.

MLflow 소개

공통 지표

  • 회귀
    • 평균제곱오차(MSE)
    • 제곱근평균제곱오차(RMSE)
    • 평균절대오차(MAE)
    • R² 점수
  • 분류
    • 정밀도(precision)
    • 재현율(recall)
    • F1 점수
    • 정확도(accuracy)

공통 파라미터

MODEL.get_params()
MLflow 소개

공통 파라미터

# 모델 학습
lr = LinearRegression()
lr.fit(X, y)

# 파라미터 조회 params = lr.get_params(deep=True)
params
{'copy_X': True, 'fit_intercept': True, 'n_jobs': None, 
    'normalize': 'deprecated', 'positive': False}
MLflow 소개

자동 로깅: 파라미터

parameters

# 모델
lr = LinearRegression()
lr.fit(X, y)
MLflow 소개

자동 로깅: 지표

지표

# 모델
lr = LinearRegression()
lr.fit(X, y)
MLflow 소개

저장 형식

모델 디렉터리 구조:

model/
    MLmodel
    model.pkl
    python_env.yaml
    requirements.txt
# 자동 로깅
mlflow.sklearn.autolog()

아티팩트

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...