This lab gives an overview of some of the fundamental mlops concepts using mlflow:
- starter.ipynb: mlflow - autolog(), logging a model, loading a saved model
- linear_regression.ipynb: mlflow - logging parameters and metrics
- serving.ipynb: mlflow - serving models
- serving.py: mlflow - creating custom artifacts(e.g extra_pip_requirements.txt)
Prerequisites
- Github Lab-1
- Jupyter Lab installed in your system (important to have it installed)
Setting up the lab
- Open the local mlops_labs directory using Visual Studio Code(VSC) and open a new terminal inside VSC.
- Create a new working directory for this lab(e.g. mlflow_lab1).
- Move into the working directory using the command cd mlflow_lab1 in your terminal.
- Create a requirements.txt file and add packages similar to this.
- Create a virtual environment(e.g. mlflow_lab1_env).
- Activate the environment and install the required packages using pip install -r requirements.txt.
Cloning the necessary files
Copy the following files into your working directory.
Project Structure:
mlops_labs/
└── mlflow_lab1/
├── requirements.txt
├── mlflow_lab1_env/
├── starter.ipynb
├── linear_regression.ipynb
├── serving.ipynb
└── serving.py
1. starter.ipynb
- To run starter.ipynb in jupyter lab, you have to link your virtual environment to jupyter lab.
- Run the following command in your terminal to do this. Pass the name of your virtual environment to –name.
python -m ipykernel install --user --name=mlflow_lab1_env
- Run jupyter lab
jupyter-lab
- Select your virtual environment as your notebook’s kernel by going to the Kernel menu -> Change kernel -> select your virtual environment.
- Continue with the jupyter notebook.
Note:
- In case you cannot run the !mlflow ui commands inside your jupyter lab, open a new terminal in VSC, activate your virtual environment and run the same command in your new terminal.
2. linear_regession.ipynb
- Make sure you selected your virtual environment as your notebook’s kernel.
- Continue with the jupyter notebook.
- If you are unable to run the mlflow commands inside your notebook, open a new terminal inside your VSC, activate your virtual environment and run them there.
3. serving.ipynb
- Make sure you selected your virtual environment as your notebook’s kernel.
- Once your model is ready to serve, get it’s run id from mlruns/0/.
- Open a new terminal inside your VSC and activate your virtual environment.
- Run the following command replacing run_id.
mlflow models serve --env-manager=local -m mlruns/0/<run_id>/artifacts/model -h 127.0.0.1 -p 5001
- Make sure the url, port in your notebook and in the above command matches.
url = 'http://127.0.0.1:5001/invocations'
4. serving.py
- Make sure you selected your virtual environment as your notebook’s kernel.
- Run the file
python serving.py
- Run the mlflow ui
mlflow ui
- Check the artifacts.