Machine Learning engineering project for models deployment to showcase front-to-back modern way of deploying and running ML models in production.
We use simple linear regression model that was trained to predict a stock price (Exxon Mobile stock) based on Oil prices. Model training is not in scope for this project. Pre-trained model serialised and saved to be loaded into memory for service predictions.
- FastAPI service for model inference (http://localhost:5000/redoc)
- Prometheus for monitoring (http://localhost:9090)
- Grafana dashboard for monitoring metrics integration (http://localhost:3000)
- Evidently for Data/Logical drift (WIP)
- MinIO for persistent layer (TODO)
- MLFlow for model training, features store, models registry (TODO)
Model Service API definition
Grafana ML Metrics Dashboard
-
Build and run the containers with
docker-composedocker compose up -d --build
Python dependencies are managed by pip-tools. You need to create conda or venv for your env first.
pip-compile generates a requirements.txt file using the latest versions that fulfil the dependencies you specify in the supported files.
If pip-compile finds an existing requirements.txt file that fulfils the dependencies then no changes will be made, even if updates are available.
To force pip-compile to update all packages in an existing requirements.txt, run pip-compile --upgrade.
-
Prepapre Python env
Create conda environment from env file:
conda env create -f environment.ymlAlternatively, create create a virtual envrionment with 'venv'
python3 -m venv env -
Activate the environment:
conda activate mlops source env/bin/activate
pip-compile requirements.in
-
Install model in editable mode for active development
pip install -e . -
Install as a package
pip install -
If a new package is added to the requirements.txt file:
pip install --upgrade -r requirements.txt -
Removing installed virtual environment
For conda:
conda remove --name mlops --allFor pip env - delete associated directory
-
Updating with new dependenciespip-compile --upgrade
pip-compile --upgrade pip install --ignore-installed -r requirements.txt Or pip install --upgrade --force-reinstall -r requirements.txt
docker build . -t yevdeveloper/ml-ops:latest
docker run --name=ml-ops --rm -p 5000:5000 -d yevdeveloper/ml-ops:latest
docker run --name=ml-ops -p 5000:5000 -d yevdeveloper/ml-ops:latest
docker run --name=ml-ops -d yevdeveloper/ml-ops:latest
-
Check stdout
docker logs ml-ops docker logs -f ml-ops
-
Login running docker container
docker exec -it yevdeveloper/ml-ops bash -
Stopping containers
docker stop $(docker ps -a -q) -
Removing containers
docker rm $(docker ps -a -q) docker container prune
- Single request
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"data": [85]}'
Or you can simulate sending a 1000 requests using the simulate_requests.sh script to view metrics in log file.
docker rmi $(docker images -a)
docker rm $(docker ps -a -f status=exited -q)
docker rm $(docker ps -a -f status=created -q)
# Lists all created containers but potentually not run containers
docker container ls --all
docker run --rm -it --name MYCONTAINER yevdeveloper/ml-ops:latest bash


