From the course: MLOps Tools: MLflow and Hugging Face
Installing and using MLflow - Hugging Face Tutorial
From the course: MLOps Tools: MLflow and Hugging Face
Installing and using MLflow
- [Instructor] Installing MLflow is very straightforward if you have a Python environment, I have something that I've already activated here. It doesn't matter if it's a virtual environment, or a conda environment, or something else. In this case, it just happens to be a conda environment. But we're going to go ahead and install MLflow. So I'm going to say pip install mlflow, and that should work pretty straightforward. It should take a couple of seconds, and then complete. That is effectively how you install MLflow. Just using Pip, if you have some other ways of installing, well, primarily Pip would be the one thing that you want to be using. So, once MLflow completes installing, there's a few things that you can actually do. Before I show you kind of how to interact with MLflow directly, I want to show you what MLflow UI will look like. So I'm going to say mlflow, space, ui, and return. And that will run a server. Now, this UI is running locally, so you can see here it's running a port of 5,000 so I'm going to click here. And it's opening up on our window which I'm going to pull into the view here. So you can see that it has some minimal interface with a few things that look interesting. However, there's nothing here that you could say, well, I can't see anything that would be related to models except for you have like a chart here. But the thing is that this is empty so not entirely super useful. But you will see once we start putting things in there, then things will start looking much, much interesting. So let's switch the view back to VS Code. And we're going to create here a new file, and we're going to call it... This is going to be test-mlflow. So it's a very simple script, it's just a Python script. I'm going to leave the terminal there running because it's our UI. So we're going to say, for example, from mlflow import log_metric, and log_param, and log_artifact. This is something that we'll see later into more detail. But basically we'll do the infamous if_name is main that basically tells Python, hey, run this, or straight away, like if I run it on the terminal, execute this as a script. So we can start logging some params. So for example, we can say, let's say threshold here, and we can say something like 3. So that's a parameter. Or we could say verbosity, can't type verbosity. We can say, let's say for example, DEBUG. You're logging parameters, you're logging things that you are requiring for your training to effectively work, and then be trained, and it could be anything that you want. Similarly, we can log some metrics. So if you're capturing, say, for example, timestamp, we could say, this would be any arbitrary number. And we could say, time to complete, let's call it TTC for abbreviation purposes, and let's say this took 33 seconds. So you start seeing that you can start logging other kinds of things. And finally, we can actually log an artifact which can be an actual file. So we can say, this file could exist already, but we can say, for example, well, we don't need to write it with Python. We can go here and say, new file. And we can say, this is our produced-dataset.csv. So we can say this is empty, and doesn't have anything there, we're going to save it. I'm going to close it out. And then when we want to log an artifact, we are going to say log_artifact. And then we are going to say that the artifact is going to be produced-dataset.csv. All right, so I'm going to save these, and then I'm going to run a new terminal. And I am going to say python test-mlflow, and see what happens. Alright, so that completed, and I'm going to go back to the web UI, and see what happened. So I'm going to refresh, and we should start seeing that nine seconds ago, I was able to run some things. So this is a little bit big so let me try to make it slightly more readable there. It's going to be a little bit smaller. But you can see here that it's capturing things. So metrics, which we talked about time to complete. Now I call the TTC, and you could see that that's captured here and timestamp. So you have metrics separated there, and we have parameters, we said threshold was going to be 3. And verbosity was going to be DEBUG. So you start seeing those things there, and then the source is right there. Let's click here and see what happens. How about the artifacts? Well, this is the nice thing is that we can click here, and it tells me lots of metadata about the parameter. So that's a very, very quick overview on how to install MLflow, and how to start using it with the tracking UI.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.