Appendix C. Energy consumption evaluation
Throughout this book, we've focused on transforming models to make them more efficient and adapted to our goals using techniques such as pruning and distillation. However, in production, energy consumption also matters, both for the operational cost and for the environmental impact of a model.
To quantify this impact, you've used CodeCarbon, a library that has become the de facto standard for measuring energy consumption and carbon footprint in machine learning research. CodeCarbon tracks CPU and GPU energy usage during code execution and, based on the server location, estimates the equivalent CO2 emissions.
However, GPUs draw power even when idle. If you measure directly with CodeCarbon, you get the total energy: what your model uses plus what the GPU consumes anyway. To compare models fairly, you need net energy, which you get with the two functions from the practical chapters: calibrate_idle_power measures your hardware's baseline consumption, and measure_energy_consumption subtracts that idle from the total consumption, giving you the energy your model actually consumes.
This appendix explains how these functions work internally.