Implementarea modelelor

Introducere în MLflow

Weston Bassler

Senior MLOps Engineer

Ciclul de viață ML

Etapele ciclului de viață ML

1 datacamp.com
Introducere în MLflow

Versiuni și etape ale modelului

  • Versiuni de model

    • Versiunea +1
  • Etape de model

    • Staging
    • Production
    • Archived

Versiuni și etape ale modelului

Introducere în MLflow

Modalități de implementare a modelelor

Încărcarea modelului

# MLflow flavor
mlflow.FLAVOR.load_model()

Servirea modelului

# MLflow serve command-line
mlflow models serve
Introducere în MLflow

URI pentru modele

Convenție

models:/

Versiunea modelului

models:/model_name/version

Etapa modelului

models:/model_name/stage
Introducere în MLflow

Încărcarea modelelor

# Import flavor
import mlflow.FLAVOR

# Load version mlflow.FLAVOR.load_model("models:/model_name/version")
# Load stage mlflow.FLAVOR.load_model("models:/model_name/stage")
Introducere în MLflow

Exemplu de încărcare a unui model

# Import flavor
import mlflow.sklearn


# Load Unicorn model in Staging model = mlflow.sklearn.load_model("models:/Unicorn/Staging")
# Print model model
LogisticRegression()
# Inference
model.predict(data)
Introducere în MLflow

Servirea modelelor

# Serve Unicorn model in Production stage
mlflow models serve -m "models:/Unicorn/Production"
2023/03/26 15:07:00 INFO mlflow.models.flavor_backend_registry: 
Selected backend for flavor 'python_function'
2023/03/26 15:07:00 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-26 15:07:00 -0400] [86409] [INFO] Starting gunicorn 20.1.0
[2023-03-26 15:07:00 -0400] [86409] [INFO] Listening at: http://127.0.0.1:5000
[2023-03-26 15:07:00 -0400] [86409] [INFO] Using worker: sync
[2023-03-26 15:07:00 -0400] [86410] [INFO] Booting worker with pid: 86410
Introducere în MLflow

Endpoint-ul de invocare

1 Flaticon.com
Introducere în MLflow

Format CSV

pandas_df.to_csv()

Format JSON

{
  "dataframe_split": {
      "columns": ["R&D Spend", "Administration", "Marketing Spend", "State"],
      "data": [["165349.20", 136897.80, 471784.10, 1]]
  }
}
Introducere în MLflow

Predicția modelului

# Send payload to invocations endpoint
curl http://127.0.0.1:5000/invocations -H 'Content-Type: application/json' -d
{
  "dataframe_split": {
      "columns": ["R&D Spend", "Administration", "Marketing Spend", "State"],
      "data": [["165349.20", 136897.80, 471784.10, 1]]
  }
}
[[104055.1842384]]
Introducere în MLflow

Să exersăm!

Introducere în MLflow

Preparing Video For Download...