Phục vụ mô hình

Giới thiệu về MLflow

Weston Bassler

Senior MLOps Engineer

MLflow Models

  • Chuẩn hóa đóng gói mô hình

  • Ghi log mô hình

  • Đánh giá mô hình

Giới thiệu về MLflow

Triển khai mô hình

vòng đời ML

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

REST API

  • /ping - kiểm tra tình trạng

  • /health - kiểm tra tình trạng

  • /version - lấy phiên bản MLflow

  • /invocations - chấm điểm mô hình

  • Cổng 5000

Giới thiệu về MLflow

Endpoint Invocations

/invocations

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

Content-Type:application/json hoặc application/csv

{
    "1": {
        "No": "1",
        "Name": "Bill Johnson",
        "Subject": "English"
    },
    "2": {
        "No": "2",
        "Name": "Gary Valentine",
        "Subject": "Mathematics"
    }
}
Giới thiệu về MLflow

Định dạng CSV

  • DataFrame của Pandas

  • pandas_df.to_csv()

Định dạng JSON

  • dataframe_split - DataFrame của pandas theo orientation split

  • dataframe_records - DataFrame của pandas theo orientation records

Giới thiệu về MLflow

DataFrame split

# Dataframe split orientation
{
  "dataframe_split": {
      "columns": ["sex", "age", "weight"],
      "data": [["male", 23, 160], ["female", 33, 120]]
  }
}
Giới thiệu về MLflow

Phục vụ mô hình

# Lệnh phục vụ MLflow
mlflow models serve --help
Usage: mlflow models serve [OPTIONS]
Giới thiệu về MLflow

Serve URI

# Hệ thống tệp cục bộ
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
Giới thiệu về MLflow

Ví dụ phục vụ

# Phục vụ mô hình từ 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
Giới thiệu về MLflow

Yêu cầu Invocations

# Gửi payload orientation dataframe_split đến 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]}
Giới thiệu về MLflow

Ayo berlatih!

Giới thiệu về MLflow

Preparing Video For Download...