跟踪和预测培训深度学习模型的碳足迹。
carbontracker的Python项目详细描述
carbontracker
关于
carbontracker是一个跟踪和预测培训深度学习模型的能耗和碳足迹的工具,如Anthony et al. (2020)所述。在
引文
如果您在科学出版物中使用carbontracker,请引用我们的工作:
@misc{anthony2020carbontracker,
title={Carbontracker: Tracking and Predicting the Carbon Footprint of Training Deep Learning Models},
author={Lasse F. Wolff Anthony and Benjamin Kanding and Raghavendra Selvan},
howpublished={ICML Workshop on Challenges in Deploying and monitoring Machine Learning Systems},
month={July},
note={arXiv:2007.03051},
year={2020}}
安装
PyPi
^{pr2}$基本用途
必需参数
epochs
: 训练循环的总时间。在
可选参数
epochs_before_pred
(默认值=1): 在输出预测消耗之前要监视的时间段。所有时间段都设置为-1。设置为0表示没有预测。在monitor_epochs
(默认值=1): 要监视的时段总数。达到时输出实际消耗量。所有时间段都设置为-1。不能小于epochs_before_pred
或等于0。在update_interval
(默认值=10): 以秒为单位进行功率使用测量。在interpretable
(默认值=True): 如果设置为真,则CO2eq也会转换为可解释的数字,如汽车行驶的等效距离等。否则,不进行转换。在stop_and_confirm
(默认值=False): 如果设置为True,则在epochs_before_pred
个周期之后,主线程(带有训练循环)将暂停,以输出预测,用户需要确认是否继续训练。否则,输出预测并立即继续训练。在ignore_errors
(默认值=False): 如果设置为True,则所有错误将导致能量监测停止,培训将继续。否则,培训将因常规错误而中断。在components
(默认为“全部”): 要监视的组件的逗号分隔字符串。选项包括:“all”、“gpu”、“cpu”或“gpu,cpu”。在devices_by_pid
(默认值=False): 如果为True,则仅测量运行与主进程关联的进程的设备(在所选组件下)。如果为False,则测量所有可用设备(请参阅“注释”部分,了解在SLURM或容器中运行的作业)。请注意,这要求您的设备在实例化CarbonTracker
类之前必须有活动进程。在log_dir
(默认值=无): 写入日志文件所需目录的路径。如果没有,则不会进行日志记录。在verbose
(默认值=1): 设置详细级别。在decimal_precision
(默认值=6): 所报告值的所需十进制精度。在
示例用法
fromcarbontracker.trackerimportCarbonTrackertracker=CarbonTracker(epochs=max_epochs)# Training loop.forepochinrange(max_epochs):tracker.epoch_start()# Your model training.tracker.epoch_end()# Optional: Add a stop in case of early termination before all monitor_epochs has# been monitored to ensure that actual consumption is reported.tracker.stop()输出
默认设置
CarbonTracker:
Actual consumption for 1 epoch(s):
Time: 0:00:10
Energy: 0.000038 kWh
CO2eq: 0.003130 g
This is equivalent to:
0.000026 km travelled by car
CarbonTracker:
Predicted consumption for 1000 epoch(s):
Time: 2:52:22
Energy: 0.038168 kWh
CO2eq: 4.096665 g
This is equivalent to:
0.034025 km travelled by car
CarbonTracker: Finished monitoring.
详细=2
CarbonTracker: The following components were found: CPU with device(s) cpu:0.
CarbonTracker: Average carbon intensity during training was 82.00 gCO2/kWh at detected location: Copenhagen, Capital Region, DK.
CarbonTracker:
Actual consumption for 1 epoch(s):
Time: 0:00:10
Energy: 0.000041 kWh
CO2eq: 0.003357 g
This is equivalent to:
0.000028 km travelled by car
CarbonTracker: Carbon intensity for the next 2:59:06 is predicted to be 107.49 gCO2/kWh at detected location: Copenhagen, Capital Region, DK.
CarbonTracker:
Predicted consumption for 1000 epoch(s):
Time: 2:59:06
Energy: 0.040940 kWh
CO2eq: 4.400445 g
This is equivalent to:
0.036549 km travelled by car
CarbonTracker: Finished monitoring.
正在分析日志文件
聚合日志文件
CarbonTracker:
Actual consumption for 1 epoch(s):
Time: 0:00:10
Energy: 0.000038 kWh
CO2eq: 0.003130 g
This is equivalent to:
0.000026 km travelled by car
CarbonTracker:
Predicted consumption for 1000 epoch(s):
Time: 2:52:22
Energy: 0.038168 kWh
CO2eq: 4.096665 g
This is equivalent to:
0.034025 km travelled by car
CarbonTracker: Finished monitoring.
CarbonTracker: The following components were found: CPU with device(s) cpu:0.
CarbonTracker: Average carbon intensity during training was 82.00 gCO2/kWh at detected location: Copenhagen, Capital Region, DK.
CarbonTracker:
Actual consumption for 1 epoch(s):
Time: 0:00:10
Energy: 0.000041 kWh
CO2eq: 0.003357 g
This is equivalent to:
0.000028 km travelled by car
CarbonTracker: Carbon intensity for the next 2:59:06 is predicted to be 107.49 gCO2/kWh at detected location: Copenhagen, Capital Region, DK.
CarbonTracker:
Predicted consumption for 1000 epoch(s):
Time: 2:59:06
Energy: 0.040940 kWh
CO2eq: 4.400445 g
This is equivalent to:
0.036549 km travelled by car
CarbonTracker: Finished monitoring.
carbontracker支持将指定目录中的所有日志文件聚合为碳足迹的单个估计值。在
示例用法
fromcarbontrackerimportparserparser.print_aggregate(log_dir="./my_log_directory/")
示例输出
The training of models in this work is estimated to use 4.494 kWh of electricity contributing to 0.423 kg of CO2eq. This is equivalent to 3.515 km travelled by car. Measured by carbontracker (https://github.com/lfwa/carbontracker).
将日志转换为字典对象
可以使用parser.parse_all_logs()
或parser.parse_logs()
将日志文件解析为字典。在
示例用法
fromcarbontrackerimportparserlogs=parser.parse_all_logs(log_dir="./logs/")first_log=logs[0]print(f"Output file name: {first_log['output_filename']}")print(f"Standard file name: {first_log['standard_filename']}")print(f"Stopped early: {first_log['early_stop']}")print(f"Measured consumption: {first_log['actual']}")print(f"Predicted consumption: {first_log['pred']}")print(f"Measured GPU devices: {first_log['components']['gpu']['devices']}")
示例输出
Output file name: ./logs/2020-05-17T19:02Z_carbontracker_output.log
Standard file name: ./logs/2020-05-17T19:02Z_carbontracker.log
Stopped early: False
Measured consumption: {'epochs': 1, 'duration (s)': 8.0, 'energy (kWh)': 6.5e-05, 'co2eq (g)': 0.019201, 'equivalents': {'km travelled by car': 0.000159}}
Predicted consumption: {'epochs': 3, 'duration (s)': 25.0, 'energy (kWh)': 1000.000196, 'co2eq (g)': 10000.057604, 'equivalents': {'km travelled by car': 10000.000478}}
Measured GPU devices: ['Tesla T4']
兼容性
carbontracker兼容:
- 支持NVIDIA Management Library (NVML)的NVIDIA gpu
- 支持Intel RAPL的Intel CPU
- 泥巴
- 谷歌Colab/Jupyter笔记本电脑
注释
GPU和Slurm的可用性
- 可用的GPU设备是通过首先检查环境变量
CUDA_VISIBLE_DEVICES
来确定的(只有当devices_by_pid
=False时,否则我们通过PID找到设备)。这确保对于Slurm,我们只获取与当前作业相关联的GPU设备,而不是整个集群。如果失败,我们将测量所有可用的GPU。在 - NVML找不到没有
--pid=host
生成的容器的进程。这会影响device_by_pids
参数,并意味着它永远不会在受影响的容器中为gpu找到任何活动进程。在
扩展carbontracker
介质中的碳跟踪器
- 项目
标签: