The ai-ranker consists of two main scripts:
The system relies on an MLflow instance to manage model versions and a Kafka instance to handle message-based communication for both training and inference. The Kafka instance is not mandatory, as messages can also be read from a local file, although this is intended for debugging purposes only. Currently, only models built with the Scikit-learn library are supported.
The typical usage pattern is as follows:
training queue, preprocesses them, and uses them to train two types of ML models: a classification model for predicting the success or failure of a deployment, and a regression model for estimating deployment creation or failure time. The trained models, along with their metadata, are stored in the MLflow registry.inference queue, reads new messages as they arrive, preprocesses them, loads the latest ML models from the MLflow registry, and uses them to make predictions for each Cloud provider in the message. The predictions are then combined to produce an ordered list of providers based on expected performance.You need to have docker installed on your system, a running MLflow instance with version up to 2.22.1, and a running Kafka instance. The minimum and recommended resources to use the ai-ranker for training and inference are the following
| Resource | Minimum (dev/test) | Recommended (prod) | Notes |
|---|---|---|---|
| CPU | 1 core | 2–4 cores | Scikit-learn does not use GPU but benefits from parallel processing |
| RAM | 2 GB | 4–8 GB | Increase for large datasets or ensemble models |
| Disk (Storage) | 1 GB (small models and minimal artifacts) | 5–10 GB | For storing models, scalers, CSVs, feature importances, etc. |
| Network | 10 Mbps | 100 Mbps+ | Useful if saving/loading artifacts from remote tracking server |
In production mode you should run the application using the dedicated image indigopaas/ai-ranker available on DockerHub.
The application does not require persistent volumes. It uses environment variables to configure the service: the connection to the MLflow and Kafka instances, the models and features to use, whether to remove outliers, whether to scale the features, and which feature to use for classification and regression.
The command to correctly start up the application for training inside a container using the default environment variables is:
docker run indigopaas/ai-ranker python /app/src/main.py --training
whereas for inference is:
docker run indigopaas/ai-ranker python /app/src/main.py --inference
Below is the list of all environment variables that can be passed to the command using the -e flag, grouped by category. You can also create a .env file with all the variables you want to override.
LOCAL_MODE
boolfalseLOCAL_DATASET
str or nullnullLOCAL_DATASET_VERSION
str"1.1.0"KAFKA_HOSTNAME
str"localhost:9092"KAFKA_TRAINING_TOPIC
str"training"KAFKA_TRAINING_TOPIC_PARTITION
int or nullnullKAFKA_TRAINING_TOPIC_OFFSET
int0KAFKA_TRAINING_TOPIC_TIMEOUT
int1000KAFKA_MAX_REQUEST_SIZE
int104857600KAFKA_SSL_ENABLE
boolfalseKAFKA_SSL_CACERT_PATH
str or nullnullKAFKA_SSL_CERT_PATH
str or nullnullKAFKA_SSL_KEY_PATH
str or nullnullKAFKA_SSL_PASSWORD
str or nullnullKAFKA_ALLOW_AUTO_CREATE_TOPICS
boolfalseTEMPLATE_COMPLEX_TYPES
list[]MLFLOW_TRACKING_URI
str (URL)http://localhost:5000MLFLOW_EXPERIMENT_NAME
strDefaultMLFLOW_HTTP_REQUEST_TIMEOUT
int20MLFLOW_HTTP_REQUEST_MAX_RETRIES
int5MLFLOW_HTTP_REQUEST_BACKOFF_FACTOR
int2MLFLOW_HTTP_REQUEST_BACKOFF_JITTER
float1.0CLASSIFICATION_MODELS
dict[str, dict]{"RandomForestClassifier": {}}REGRESSION_MODELS
dict[str, dict]{"RandomForestRegressor": {}}KFOLDS
int5REMOVE_OUTLIERS
boolfalseTEST_SIZE
float0.2Q1_FACTOR
float0.25Q3_FACTOR
float0.75THRESHOLD_FACTOR
float1.5X_FEATURES
list[
"cpu_diff",
"ram_diff",
"storage_diff",
"instances_diff",
"floatingips_diff",
"gpu",
"test_failure_perc_30d",
"overbooking_ram",
"avg_success_time",
"avg_failure_time",
"failure_percentage",
"complexity"
]
Y_CLASSIFICATION_FEATURES
list["status"]Y_REGRESSION_FEATURES
list["deployment_time"]SCALING_ENABLE
boolfalseSCALER_FILE
str"scaler.pkl"KAFKA_TRAINING_CLIENT_NAME
str"ai-ranker-training"CLASSIFICATION_MODEL_NAME
str"RandomForestClassifier"CLASSIFICATION_MODEL_VERSION
str"latest"CLASSIFICATION_WEIGHT
float0.75REGRESSION_MODEL_NAME
str"RandomForestRegressor"REGRESSION_MODEL_VERSION
str"latest"LOCAL_IN_MESSAGES
str or nullnullLOCAL_OUT_MESSAGES
str or nullnullFILTER
boolfalseTHRESHOLD
float0.7EXACT_RESOURCES_PRECEDENCE
booltrueKAFKA_INFERENCE_CLIENT_NAME
str"ai-ranker-inference"KAFKA_INFERENCE_TOPIC
str"inference"KAFKA_INFERENCE_TOPIC_PARTITION
int or nullnullKAFKA_INFERENCE_TOPIC_OFFSET
int0KAFKA_INFERENCE_TOPIC_TIMEOUT
int0KAFKA_RANKED_PROVIDERS_TOPIC
str"ranked_providers"KAFKA_RANKED_PROVIDERS_TOPIC_PARTITION
int or nullnullKAFKA_RANKED_PROVIDERS_TOPIC_OFFSET
int0KAFKA_RANKED_PROVIDERS_TOPIC_TIMEOUT
int1000To function correctly, the application requires running instances of both MLflow and Kafka.
If you don’t already have them running, we recommend deploying them using the official Docker images:
As said at the beginning, the Kafka instance is not mandatory, as messages can also be read from a local file, although this is intended for debugging purposes only.
As previously said you can use a container job scheduler to execute the ai-ranker training script contained in the docker image at fixed intervals. Here, we suggest to use ofelia and we provide an example configuration for a docker-compose.yaml.
services:
ai-ranker-training:
image: indigopaas/ai-ranker
container_name: ai-ranker-training
env_file:
- .env
restart: unless-stopped
command: bash -c "while true; do sleep 1; done"
labels:
ofelia.enabled: true
ofelia.job-exec.feed.schedule: "@every 1h"
ofelia.job-exec.feed.command: "python /app/src/main.py --training"
ofelia.job-exec.feed.save-folder: /var/log
ofelia.job-exec.feed.no-overlap: false
ofelia:
image: mcuadros/ofelia:latest
container_name: training-job-scheduler
depends_on:
- ai-ranker-training
restart: unless-stopped
command: daemon --docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- training-logs:/var/log
volumes:
training-logs:
Clone this repository and move inside the project top folder.
git clone https://github.com/infn-datacloud/ai-ranker
cd ai-ranker
Developers can launch the project locally or using containers. In both cases, developers need a MLflow service and a Kafka service. Both can be started using docker. An easy way to configure the environment is to use poetry. Through poetry developers can install the libraries needed to start the python app and the tools to manage the code versioning, linting and formatting. We suggest to configure poetry to create the virtual environment inside the project folder to help VSCode environment discover (if you use it).
poetry config virtualenvs.in-project true
poetry install
The previous commands should be execute just the first time. You shall run the install step again when downloading a newer version of the project.
To activate the virtual environment you can run the following command:
source $(poetry env info -p)/bin/activate
To run the application in development mode for training and for inference you can use the following commands from the project top folder:
python src/main.py --training
python src/main.py --inference
Automatic tests have been implemented using pytest. To run the test suite with information about coverage you can run, from the project top folder, the following command:
pytest --cov=.
A Jenkins file has been written to build and push a new docker image version on DockerHub with the name indigopaas/ai-ranker on each push or merge on the main branch. To have a local build on your PC you can run this command:
docker build -t indigopaas/ai-ranker .
Content type
Image
Digest
sha256:ad50e30b1…
Size
303.6 MB
Last updated
9 months ago
docker pull indigopaas/ai-ranker:PR-27-python3.11