모델 서빙

MLflow 소개

Weston Bassler

Senior MLOps Engineer

MLflow 모델

  • 모델 패키징 표준화

  • 모델 로깅

  • 모델 평가

MLflow 소개

모델 배포

ML 라이프사이클

1 datacamp.com
MLflow 소개

REST API

  • /ping - 상태 확인용

  • /health - 상태 확인용

  • /version - MLflow 버전 조회

  • /invocations - 모델 예측 요청

  • 포트 5000

MLflow 소개

Invocations 엔드포인트

/invocations

No,Name,Subject
1,Bill Johnson,English
2,Gary Valentine,Mathematics

Content-Type:application/json 또는 application/csv

{
    "1": {
        "No": "1",
        "Name": "Bill Johnson",
        "Subject": "English"
    },
    "2": {
        "No": "2",
        "Name": "Gary Valentine",
        "Subject": "Mathematics"
    }
}
MLflow 소개

CSV 형식

  • Pandas DataFrame

  • pandas_df.to_csv()

JSON 형식

  • dataframe_split - split 방향의 pandas DataFrame

  • dataframe_records - records 방향의 pandas DataFrame

MLflow 소개

DataFrame split

# Dataframe split orientation
{
  "dataframe_split": {
      "columns": ["sex", "age", "weight"],
      "data": [["male", 23, 160], ["female", 33, 120]]
  }
}
MLflow 소개

모델 서빙

# MLflow serve 명령
mlflow models serve --help
Usage: mlflow models serve [OPTIONS]
MLflow 소개

Serve URI

# 로컬 파일시스템
mlflow models serve -m relative/path/to/local/model
# Run ID
mlflow models serve -m runs:/<mlflow_run_id>/artifacts/model
# AWS S3
mlflow models serve -m s3://my_bucket/path/to/model
MLflow 소개

서빙 예시

# Run에서 모델 서빙
mlflow models serve -m runs:/e84a122920de4bdeaedb54146deeb429/artifacts/model
2023/03/12 16:28:28 INFO mlflow.models.flavor_backend_registry: 
Selected backend for flavor 'python_function'
2023/03/12 16:28:28 INFO mlflow.pyfunc.backend: === Running command 
'exec gunicorn --timeout=60 -b 127.0.0.1:5000 -w 1 ${GUNICORN_CMD_ARGS} -- 
mlflow.pyfunc.scoring_server.wsgi:app'
[2023-03-12 16:28:29 -0400] [48431] [INFO] Starting gunicorn 20.1.0
[2023-03-12 16:28:29 -0400] [48431] [INFO] Listening at: http://127.0.0.1:5000 
(48431)
[2023-03-12 16:28:29 -0400] [48431] [INFO] Using worker: sync
[2023-03-12 16:28:29 -0400] [48432] [INFO] Booting worker with pid: 48432
MLflow 소개

Invocations 요청

# dataframe_split 형식 payload를 MLflow에 전송
curl http://127.0.0.1:5000/invocations -H 'Content-Type: application/json' -d '{
  "dataframe_split": {
      "columns": ["sex", "age", "weight"],
      "data": [["male", 23, 160], ["female", 33, 120]]
  }
}'
{"predictions": [1, 0]}
MLflow 소개

Ayo berlatih!

MLflow 소개

Preparing Video For Download...