MLflow is a platform to streamline machine learning development, including tracking experiments, packaging code into reproducible runs, and sharing and deploying models. MLflow offers a set of lightweight APIs that can be used with any existing machine learning application or library (TensorFlow, PyTorch, XGBoost, etc), wherever you currently run ML code (e.g. in notebooks, standalone applications or the cloud).
Here is a quick step by step walkthrough to guide you through the different steps of how to run a MLflow pipeline on Qarnot, so follow along!
If you are interested in another version, please send us an email at firstname.lastname@example.org.
Before starting a calculation with the Python SDK, a few steps are required:
Note: in addition to the Python SDK, Qarnot provides C# and Node.js SDKs and a Command Line.
This test case will show you how to train an ElasticNet model. It is a type of regularized linear regression that combines two popular penalties, specifically the
L2 penalty functions. This combination allows for learning a sparse model where few of the weights are non-zero like Lasso, while still maintaining the regularization properties of Ridge. We control the combination of
L2 using the
We will use MLflow to run two experiments with different values of
l1_ratio. In each experiment, we will fix one of the hyper-parameters, vary the other and record how the model’s performance changes.
alphabeing a float that multiplies the penalty terms.
Alpha= 0 is equivalent to an ordinary least square.
- The ElasticNet mixing parameter, with
0 <= l1_ratio <= 1. For
l1_ratio = 0the penalty is an
l1_ratio = 1it is an
0 < l1_ratio < 1, the penalty is a combination of
The data used here is the Wine Quality Data Set. The goal is to predict the quality of the wine (a score between 0 and 10) based on various properties (pH, density, alcohol, etc…).
The necessary input files needed for this tutorial can be downloaded here.
Once you have downloaded everything, your working directory should look like this:
sklearn_elasticnet_wine:MLflow project content
conda.yaml: YAML file for defining the conda environment to be used
MLproject: file defining the MLflow pipeline
train.py: python script for training the elastic net model
mlflow_driver.py: script for launching the experiments
run-mlflow.py: launchs the computation on Qarnot (code found below)
Launching the test case
Once everything is set up, use the following script to launch the computation on Qarnot. Be sure to copy your authentication token in the script (instead of
<<<MY_SECRET_TOKEN>>>) to be able to launch the task on Qarnot.
To launch this script, simply copy the following code in a Python script and execute
python3 run-mlflow.py & in your terminal.
At any given time, you can monitor the status of your task on Tasq.
Once training is done, the task status should change to green and the results should be downloaded automatically in a
output directory. There you will find all the files generated by MLflow for each run of each experiment. This includes: logs, metrics, parameters, the actual model and more.
You can visualize these results in the integrated MLflow ui.
- To do so, make sure you have
mlflowinstalled on your machine by running
pip install mlflow
- Change directories to
This will launch the UI on
localhost:5000 which you can access from your browser.
From this dashboard you have access to:
- Your experiments
- The training runs with all the metrics and parameters you have defined
- You also have access to the model corresponding to each run
It is also possible to compare different runs from the same experiment. For example, the image below shows the comparison of 5 runs to see the effect of the
alpha. You can see a scatter plot with
alpha on the x-axis and the
RMSE score on the y-axis.
That’s it! If you have any questions, please contact email@example.com and we will help you with pleasure!