A quick demo on how to use MLFlow.
The main.py file is an example of MLFlow run.
Link to the doc: https://www.mlflow.org/docs/latest/tracking.html
MLflow is a tool that allows you to manage machine learning models lifecycle. It is used to track runs, save parameters, metrics and models in order to compare them. Moreover, it is possible to package your model and to serve it onto a server.
-
mlflow.set_tracking_uri(http://10.3.15.100:8080)
connects the run to the right server. If not specified, default port is localhost:5000. -
Use
mlflow.start_run()
to start a run and write your code underneath. The function can take optional parameters if needed, such asexperiment_id [str]
,run_name [str]
ordescription [str]
. More details here. -
Log parameters using
mlflow.log_params(name, parameter)
. More details here. -
Log metrics using
mlflow.log_metric(name, metric)
. More details here. -
Log artifacts using
mlflow.log_artifact(path_to_file, artifact_path)
.artifact_path
is the path to the folder that will contain the artifact. More details here. Artifacts can be viewed by clicking on the run's name on MLFlow server. They also can be retrieved directly from Minio where they are stored. -
Log models using
log_model(model, artifact_path)
function. The function depends on the model you are using. For example, if your model is from scikit-learn, you would usemlflow.sklearn.log_model()
, if it is from keras, then usemlflow.keras.log_model()
and so on. The model will then be saved as an artifact. You can find details onmlflow.sklearn.log_model()
here.
After running your python script, logs are saved on the server and you can view them on http://10.3.15.100:8080.
On the main page, you'll find the list of runs for each experiment along with their metrics and parameters. The experiment selected here is named Default.
MLflow is organized in experiments. One experiment can contain as many runs as needed but one run is associated with only one experiment.
You can create a new experiment from your python code, by using mlflow.create_experiment(name)
. But for more convenience, a python script has been made
for this purpose. From the terminal, go to the folder containing create-experiment.py and enter the command python create-experiment [name].
Here I entered python create-experiment my-new-experiment. It is immediately visible from the UI.
Experiments can also be created from MLFLow UI by clicking on the top-left + button.