Modelimplementatie

Introductie tot MLflow

Weston Bassler

Senior MLOps Engineer

ML-levenscyclus

Stappen van de ML-levenscyclus

1 datacamp.com
Introductie tot MLflow

Modelversies en -stages

  • Modelversies

    • Versie +1
  • Modelstages

    • Staging
    • Production
    • Archived

Modelversies en -stages

Introductie tot MLflow

Manieren om modellen te deployen

Model laden

# MLflow-flavor
mlflow.FLAVOR.load_model()

Model serveren

# MLflow-serve-opdrachtregel
mlflow models serve
Introductie tot MLflow

Models-URI

Conventie

models:/

Modelversie

models:/model_name/version

Modelstage

models:/model_name/stage
Introductie tot MLflow

Modellen laden

# Flavor importeren
import mlflow.FLAVOR

# Versie laden mlflow.FLAVOR.load_model("models:/model_name/version")
# Stage laden mlflow.FLAVOR.load_model("models:/model_name/stage")
Introductie tot MLflow

Voorbeeld: modellen laden

# Flavor importeren
import mlflow.sklearn


# Unicorn-model in Staging laden model = mlflow.sklearn.load_model("models:/Unicorn/Staging")
# Model afdrukken model
LogisticRegression()
# Inference
model.predict(data)
Introductie tot MLflow

Modellen serveren

# Unicorn-model serveren 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
Introductie tot MLflow

Invocations-endpoint

api

http://localhost:5000/invocations

  • Indelingen
    • CSV
    • JSON
1 Flaticon.com
Introductie tot MLflow

CSV-indeling

pandas_df.to_csv()

JSON-indeling

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

Modelvoorspelling

# Payload naar het invocations-endpoint sturen
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]]
Introductie tot MLflow

Laten we oefenen!

Introductie tot MLflow

Preparing Video For Download...