Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.




Table of Contents



About MLFow

MLflow is an open source platform for managing the end-to-end machine learning lifecycle. It tackles four primary functions:

Tracking experiments to record and compare parameters and results (MLflow Tracking). Packaging ML code in a reusable, reproducible form in order to share with other data scientists or transfer to production (MLflow Projects). Managing and deploying models from a variety of ML libraries to a variety of model serving and inference platforms (MLflow Models). Providing a central model store to collaboratively manage the full lifecycle of an MLflow Model, including model versioning, stage transitions, and annotations (MLflow Model Registry). MLflow is library-agnostic. You can use it with any machine learning library, and in any programming language, since all functions are accessible through a REST API and CLI. For convenience, the project also includes a Python API, R API, and Java API.
(more details... https://mlflow.org/docs/latest/index.html)

Table of Contents

...





Make Python3 default


Python2 and Python3 are already installed on Debian 10, but the default version is Python2. How to check it...

...

In my case it returns Python 3.7.3

...




Download and install Miniforge3


Miniforge is the community (conda-forge) driven minimalistic conda installer. Subsequent package installations come thus from conda-forge channel, and it started because miniconda didn't support aarch64,

...

Code Block
languagebash
export PATH=$PATH:~/miniforge3/bin

...




Install MLFlow using Conda


Code Block
languagebash
conda install -c https://conda.anaconda.org/paulscherrerinstitute mflow
conda update conda
conda --version

In my case the version is 4.9.2

...




Create and activate a conda virtual environment and install MLFlow


A conda environment is a directory that contains a specific collection of conda packages that you have installed. For example, you may have one environment with NumPy 1.7 and its dependencies. The name of the environment is env_mlflow.
Use your Python's version to create an environment...

...

Code Block
languagebash
pip3 install mlflow

...




Install Sklearn using pip3 and other dependencies


We need GCC and G++ compilers as dependencies to build Sklearn.

...

Code Block
languagebash
pip3 install sklearn
pip3 install Cython
pip3 install --upgrade setuptools

...





Install Matplotlib


Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+.

...

The return must be "Requirement already satisfied"

...





Install PostgreSQL


PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasising extensibility and SQL compliance.

Code Block
languagebash
sudo apt-get install postgresql
sudo apt-get install postgresql-contrib 
sudo apt-get install postgresql-server-dev-all

...





Install Psycopg


Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).

Code Block
languagebash
pip3 install psycopg2

...




Download and run MLFlow examples


Check if Git is already installed...

...

MLflow runs can be recorded either locally in files or remotely to a tracking server. By default, the MLflow Python API logs runs to files in an mlruns directory wherever you ran your program. You can then the "mlruns" directory which is being created during the execution of the "python train_diabetes.py x.x x.x" in the directory of the code.

~/mlflow/examples/sklearn_elasticnet_diabetes/linux/mlruns

Code Block
languagebash
$ ls ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/

You will see the directory "mlruns" among the others.

In this directory has been created a numerical directory (0, 1, 2, e.t.c.) which has all the results of every execution. In the example we had 3 executions (python train_diabetes.py x.x x.x), so in this numerical directory has been created 3 encrypted directories that correspond to every single execution. Also there is a 4th file which is called "meta.yaml".

Code Block
languagebash
ls ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/mlruns

It returns a number like this... 0

Code Block
languagebash
ls ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/mlruns/0

The return must be something like that...

1f8d0c25da6f4634a31f445a3e2fe987
9514eac210f447e2b2e0c1af7374dcbc
f54784481e294434918dfccd63a24d4d
meta.yaml




Change working directory


To change the default working directory (mlruns) to a custom of our choice, we have to add one more line in the source code. Go to the source file and edit it using a text editor.
For our example the file lives.
$ nano ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/train_diabetes.py
I use "nano" in order to modify the file. You can use any editor you want to modify it (vi is the default terminal editor).

Find the following lines...

import mlflow
import mlflow.sklearn


at the next line add this...

Code Block
languagepy
mlflow.set_tracking_uri('file:myDirectory')

The directory "myDirectory" will be created in the directory of the source file (~/mlflow/examples/sklearn_elasticnet_diabetes/linux/myDirectory) when the source code will executed.


Code Block
languagebash
ls ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/myDirectory/0

# The return must be something like this (as the default working directory)...
1f8d0c25da6f4634a31f445a3e2fe987
9514eac210f447e2b2e0c1af7374dcbc
f54784481e294434918dfccd63a24d4d
meta.yaml




Get the results on the Web Browser


In the directory of the source file that has been also created the directory "mlruns", we can run "mlflow ui" to see the logged runsresults.

Code Block
languagebash
cd ~/mlflow/examples/sklearn_elasticnet_diabetes/linux/
mlflow ui

The return must be something like that...

2020-12-03 14:17:36 +0000] [1267] [INFO] Starting gunicorn 20.0.4
[2020-12-03 14:17:36 +0000] [1267] [INFO] Listening at: http://127.0.0.1:5000 (1267)
[2020-12-03 14:17:36 +0000] [1267] [INFO] Using worker: sync
[2020-12-03 14:17:36 +0000] [1270] [INFO] Booting worker with pid: 1270

NOTICE - When executing "mlflow ui" it looks for the directory "mlruns", if it does not exist then it creates an empty one (only with the file "meta.yaml").


For the custom working directory we have to run...

Code Block
languagebash
mlflow ui --backend-store-uri file:myDirectory \
--default-artifact-root file:myDirectory \
--host 127.0.0.1 \
--port 5000

At the local Web browser URL bar type... 127.0.0.1:5000

NOTE - The command "mlflow ui" should be on run in order to have access at the 127.0.0.1:5000





SSH Tunnel Forwarding


When running "mlruns ui" you can notice the 2nd line of the return, there is the localhost's IP and the port (127.0.0.1:5000) which corresponds to the working directory ("mlruns" as default or anything else we have declared as custom). Now we can use them the IP and the Port to get the results.
Using a remote machine (OpenStack), the instances does do not have a Desktop Environment (GNOME, XFCE, e.t.c.) in order to see the results. But we can check if it has created the "index.html" file at http://127.0.0.1:5000...

Code Block
languagebash
cd ~/Download
wget 127.0.0.1:5000
cat index.html

But, using SSH Tunneling Tunnel Forward we can see the OpenStack's instance localhost results on the local Web browser.

Syntax: ssh -L port:localhost:port userName@FloatingIPinstanceUserName@FloatingIP

Open a new window of the local terminal and type...
Example: ssh -L 5000:localhost127.0.0.1:5000 debian@214.152.131.68(We can replace the localhost with

NOTE - In this case the user name of Openstack instance is "debian" and the Floating IP 214.152.131.68





Mozilla Firefox modification for the SSH Tunnel Forward


To modify the local Web browser. The following description take place for the Mozilla Firefox.
Preferences -> General -> Scroll down to find "Network Settings" and click the "Settings" button -> "Configure Proxy Access to the Internet" click "No proxy" -> OK
At the local Web browser URL bar type... 127.0.0.1:5000

NOTE - The command "mlflow ui" should be on run in order to have access at the 127.0.0.1:5000





Understanding the files and folders of MLFlow directory by matching the elements of the GUI environment


For cases where there is no GUI for accessing the produced data (when "mlflow ui" cannot be executed). In this case we need to know the folders and the files that the graphical environment uses to extract the data and present them on the screen. This means that, we have to get them manually through their files.
The following image shows the correspondence between files/folders and GUI's elements.


Image Added