Training Green and Sustainable Recommendation Models: Introducing Carbon Footprint Data into Early Stopping Criteria
With the growing focus on Green AI, there is an urgent need for algorithms that are designed to minimize their environmental impact while maintaining satisfying performance. In this paper, we introduce a novel early stopping strategy that considers carbon foot print data while training a recommendation algorithm. In particular, during the training phase, our criterion epoch-by-epoch analyzes the improvement in terms of predictive accuracy and compares it to the increase in carbon emissions. Then, we analyze the trade-off between the scores, and when the accuracy improves at a rate that is not favorable, the training is stopped. In the experimental evaluation, we showed that our strategy could significantly reduce the carbon footprint of several state-of-the-art recommendation models, with a limited decrease in accuracy and fairness. While more work is needed to automatically balance the trade-off between accuracy and emissions, this paper sheds light on the need for more sustainable recommendation models and takes a significant step toward designing green training strategies.
Since our GES criterion has been implemented in the RecBole framework, we refer to the requirements and the original documentation of RecBole.
Moreover, we track carbon footprint by means of CodeCarbon.
Accordingly, in order to install all the requirements and the dependencies to run our code, you need to create a new python environment (version 3.8 or more should work fine - we used 3.11), and install the two libraries.
# create the env and activate it
virtualenv -p python3.11 ges_env
source ges_env/bin/activate
# install recbole and codecarbon
pip install recbole
pip install codecarbon
In addition, we share the requirements req_ges.txt file of the environment we used to perform our esperiments.
Now, in order to implement our GES, we have edited 3 files in RecBole; our implementations are available in the src/recbole_edit/ folder:
trainer/trainer.py- we edited thefit()methodquick_start/quick_start.py- we edited therun_recbole()methodutils/utils.py- we edited theearly_stop()method
You just need to copy the edited methods or the whole files into your RecBole installation, that is typically located in ges_env/lib/python3.11/site-packages/recbole/.
Once you have updated the RecBole library, you can edit the src/run.py script, set your data and your models (or use ours, to replicate our experiments; our data is in the data/movielens_1m folder); finally, run the experiments with:
python run.py
You will find your results in the results/{dataset}/{model} folder, which will contain two files:
params.csv: it will contain the output of CodeCarbon (emissions, energy consumed, etc.)metrics.csv: it will contain the output of the RecBole evaluation (all the metrics)
We report in the results/ folder the reuslts reported in the paper, together with the graphs (results/graphs/) and the scripts to generate those graphs (results/paper_graphs.ipynb).