blog bg left
Back to Blog

Streamlining data monitoring with whylogs and MLflow

Everyone who has worked with machine learning models in production is familiar with their complexity of deployment and lifecycle management, from storing trained models to Model Deployment and Data Monitoring. The task becomes particularly grueling given the current fragmented tooling ecosystem.

Model lifecycle chart. Source: Google

Enter MLflow — an open source framework created by Databricks to unify the model lifecycle management, used by Facebook, Zillow, Microsoft, and a host of other AI-first companies. MLflow seeks to directly address the key problems of model tracking and interoperability between different ML tools. MLflow works with any ML library, framework, or language, removing barriers to rapid prototyping and leading to quicker turnaround times for solving business problems in production.

For the perspicacious ML engineer, MLflow provides an intuitive and straightforward approach to model deployment while solving many of the common problems, such as tracking model metadata and persisting models in a registry, within the framework itself. Instead of building complicated in-house infrastructure for keeping track of your models (and their performance), MLflow provides simple, powerful tools to manage your models from inception to serving happy customers.

Model monitoring in MLflow

One of the key features in MLflow is the ability to capture detailed metrics for your models. The framework is not opinionated about what you should log. Instead it provides a simple API for recording whatever data you might find useful. This is accomplished via calls to mlflow.log_metrics in your MLflow runs, and you can find additional examples and documentation here.

These metrics can later be visualized via the MLflow server interface, which is super handy for tracking model metrics across different iterations of a model, or over time.

MLflow metrics visualization. Source: MLflow

Finally, MLflow has autologging integrations with all the commonly used ML frameworks, providing a straightforward method to logging performance metrics.

However, the logging solutions native to these frameworks generally focus on model performance itself, such as its precision, recall, and also hyperparameters used to reach those numbers, and do not adequately capture information about the context and environment in which your models operate. Figuring out why your models may be underperforming is a nigh impossible task if you don’t capture this context.

Data quality monitoring with whylogs

Luckily, MLflow makes it easy to add integration with third party libraries, so that various additional metrics can be collected both during the training process and once the model is live. By integrating whylogs into the MLflow runtime, we can add data quality monitoring to the model pipeline. whylogs is an open source, lightweight, and high performance statistical data logging library that enables a fire-and-forget approach to logging data quality by profiling the data during training and as it flows through the model once it has been deployed.

Profiling data with whylogs allows engineers and data scientists to catch data quality issues during training as well as detect data drift after deployment, which ultimately enables a more informed analysis of the model’s performance over time. Rapid response to issues in production is also made possible, as data quality degradation can be uncovered in near real-time.

Why use whylogs over an in-house solution or another library? Great question!

  • whylogs is entirely open source. No hidden rocks, undocumented interactions, or unsolvable data governance concerns.
  • It profiles data in an extremely efficient manner, with a constant memory footprint and low CPU overhead, letting it easily scale from megabytes to terabytes of incoming data. Save those GPU cycles for your models!
whylogs Java performance metrics. Source: whylogs Java
  • It works with both structured and unstructured data. The general approach can be applied to any type of data. To profile data, simply add this line of code to your existing training pipeline:
why.log(training_df)

See the full image logging notebook for more information.

  • whylogs is platform-agnostic. Use it with MLflow, SageMaker, and on your Spark Pipelines — the more you log, the more transparency you enable, the more proactive you are about catching model failures and preventing their costs from accumulating. To profile your pyspark job, you can use our experimental API like the following code shows:
from whylogs.api.experimental.pyspark import collect_dataset_profile_view
 
spark_df = spark.read.csv("fire_dept.csv")
 
profile = collect_dataset_profile_view(df)

Data logging with whylogs with MLflow

whylogs can be used to log data metrics when running MLflow jobs:

with mlflow.start_run(run_name=”whylogs demo”):
predicted_output = model.predict(batch)
 
mae = mean_absolute_error(actuals, predicted_output)
 
mlflow.log_params(model_params)
mlflow.log_metric("mae", mae)
 
# whylogs profiles are collected in one line,
# similar to other MLflow Tracking APIs
profile_results = why.log(df)
profile_results.writer("mlflow").write()

Once whylogs profiles have been generated, they are stored by MLflow along with all the other artifacts from the run. They can be retrieved from the MLflow backend and explored further:

from whylogs.viz import NotebookProfileVisualizer
 
profile = client.download_artifacts(run_id, "profile.bin", local_dir)
 
viz = NotebookProfileVisualizer()
viz.set_profiles(target_profile=profile)
viz.profile_summary()
Image: Distribution plot for the reference profile we have created when training our model.

For a more complete (and hands-on!) overview of the whylogs integration with MLflow, check out our example notebook.

Resources

Other posts

Get Early Access to the First Purpose-Built Monitoring Solution for LLMs

We’re excited to announce our private beta release of LangKit, the first purpose-built large language model monitoring solution! Join the responsible LLM revolution by signing up for early access.

Mind Your Models: 5 Ways to Implement ML Monitoring in Production

We’ve outlined five easy ways to monitor your ML models in production to ensure they are robust and responsible by monitoring for concept drift, data drift, data quality, AI explainability and more.

Simplifying ML Deployment: A Conversation with BentoML's Founder & CEO Chaoyu Yang

A summary of the live interview with Chaoyu Yang, Founder & CEO at BentoML, on putting machine learning models in production and BentoML's role in simplifying deployment.

Data Drift vs. Concept Drift and Why Monitoring for Them is Important

Data drift and concept drift are two common challenges that can impact ML models on production. In this blog, we'll explore the differences between these two types of drift and why monitoring for them is crucial.

Robust & Responsible AI Newsletter - Issue #5

Every quarter we send out a roundup of the hottest MLOps and Data-Centric AI news including industry highlights, what’s brewing at WhyLabs, and more.

Detecting Financial Fraud in Real-Time: A Guide to ML Monitoring

Fraud is a significant challenge for financial institutions and businesses. As fraudsters constantly adapt their tactics, it’s essential to implement a robust ML monitoring system to ensure that models effectively detect fraud and minimize false positives.

How to Troubleshoot Embeddings Without Eye-balling t-SNE or UMAP Plots

WhyLabs' scalable approach to monitoring high dimensional embeddings data means you don’t have to eye-ball pretty UMAP plots to troubleshoot embeddings!

Achieving Ethical AI with Model Performance Tracing and ML Explainability

With Model Performance Tracing and ML Explainability, we’ve accelerated our customers’ journey toward achieving the three goals of ethical AI - fairness, accountability and transparency.

Detecting and Fixing Data Drift in Computer Vision

In this tutorial, Magdalena Konkiewicz from Toloka focuses on the practical part of data drift detection and fixing it on a computer vision example.
pre footer decoration
pre footer decoration
pre footer decoration

Run AI With Certainty

Book a demo
loading...