Demystifying MLOps


Isabel Zimmerman, RStudio PBC

rstudio::conf(2022)

cartoon cookie smiling

what is MLOps?

set of practices to deploy and maintain machine learning models in production reliably and efficiently

version

how do we track and manage change?

cartoon recipe card

version

model

model_final

model_final_ACTUALLY

model_final_ACTUALLY_1

version

versioning is useful to track changes across time, but it should also be for different implementations

version::vetiver

in r

library(vetiver)
library(pins)

model_board <- board_temp()

in python

import vetiver
import pins

model_board = board_temp(
    allow_pickle_read = True)

pins hex sticker

version::vetiver

in r

library(vetiver)
library(pins)

model_board <- board_temp()

v <- vetiver_model(model, "name")

in python

import vetiver
import pins

model_board = board_temp(
    allow_pickle_read = True)

v = VetiverModel(model, "name", 
    ptype_data = mtcars)

version::vetiver

in r

library(vetiver)
library(pins)

model_board <- board_temp()

v <- vetiver_model(model, "name")

model_board %>% 
    vetiver_pin_write(v)

in python

import vetiver
import pins

model_board = board_temp(
    allow_pickle_read = True)

v = VetiverModel(model, "name", 
    ptype_data = mtcars)
vetiver_pin_write(model_board, v)

version::vetiver

model_board %>% pin_meta("name")
model_board.pin_meta("name")
created: 20220719T142221Z
description: Scikit-learn  model
file: name.joblib
file_size: 1087
pin_hash: 4db397b49e7bff0b
title: 'name: a pinned LinearRegression object'
type: joblib
user:
  ptype: '{"cyl": 6.0, "disp": 160.0, "hp": 110.0, "drat": 3.9, "wt": 2.62, "qsec":
    16.46, "vs": 0.0, "am": 1.0, "gear": 4.0, "carb": 4.0}'
  required_pkgs:
  - vetiver
  - scikit-learn

deploy

cartoon cookie smiling

deploy

  • in XML (with PMML)
    • flexible in integration
    • not flexible in modeling

cartoon cookie in this is fine fire meme

deploy

  • in XML (with PMML)

  • in databases (with SQL stored procedures)

    • flexible in modeling
    • not flexible in integration

cartoon cookie with waffle iron pattern

deploy

  • in XML (with PMML)

  • in databases (with SQL stored procedures)

  • in an API (with RESTful APIs)

    • highly flexible in modeling
    • highly flexible in integration

cartoon cookie holding hands with cartoon oven

vetiver

in r

library(plumber)

pr() %>%
  vetiver_api(v)

in python

api = VetiverAPI(v)
api.run()

monitor

cartoon cookie, slightly burnt

monitor

  • monitor for data drift

monitor

  • monitor for data drift
  • monitor for model drift

monitor

  • monitor for data drift
  • monitor for model drift
  • know what to do when things go wrong

vetiver

in r

metrics <-
    augment(v, new_data = new) %>%
    vetiver_compute_metrics(
        date_col, 
        "week", 
        mpg, 
        .pred
        )

in python

metrics = vetiver.compute_metrics(
    new_data, 
    "date_col", 
    timedelta(weeks = 1), 
    metric_set, 
    "mpg", 
    "preds"
    )

vetiver

in r

# compute, then ... 

model_board %>%
    vetiver_pin_metrics(
        metrics, 
        "metrics_pin_name", 
        overwrite = TRUE
        )

in python

# compute, then ... 

vetiver.pin_metrics(
    model_board, 
    metrics, 
    "metrics_pin_name", 
    overwrite = True
    )

vetiver

in r

# compute and pin, then ...

vetiver_plot_metrics(metrics)

in python

# compute and pin, then ...

vetiver.plot_metrics(metrics)

line chart showing model performance metrics over time

putting it all together

best practices:

  • version your model
  • deploy your model
  • monitor your model

but also!

  • responsible reporting
  • data validation
  • more!

cartoon cookies holding hands, with the last cookie in thought about the MLOps cycle