carbonai.PowerMeter.measure_power¶
- PowerMeter.measure_power(package, algorithm, step='other', data_type='', data_shape='', algorithm_params='', comments='')¶
A decorator to measure the power consumption of a given function
- Parameters
- packagestr
A string describing the package used by this function (e.g. sklearn, Pytorch, …)
- algorithmstr
A string describing the algorithm used in the function monitored (e.g. RandomForestClassifier, ResNet121, …)
- step{‘inference’, ‘training’, ‘other’, ‘test’, ‘run’, ‘preprocessing’}, optional
A string to provide useful information on the current stage of the algorithm
- data_type{‘tabular’, ‘image’, ‘text’, ‘time series’, ‘other’}, optional
A string describing the type of data used for training
- data_shapestr or tuple, optional
A string or tuple describing the quantity of data used
- algorithm_paramsstr, optional
A string describing the parameters used by the algorithm
- commentsstr, optional
A string to provide any useful information
See also
PowerMeter.from_config
Create a PowerMeter object from a config file
PowerMeter.__call__
Measure the power usage using a with statement
Examples
First, create a PowerMeter (you only do to this step once).
>>> power_meter = PowerMeter.from_config("config.json")
Decorate the function you wish to monitor.
>>> @power_meter.measure_power( ... package="pandas, numpy", ... algorithm="data cleaning", ... step="preprocessing", ... data_type="tabular", ... comments="Cleaning of csv files + train-test splitting" ... ) ... def example_func(): ... # do something
Each time this function will be called, the PowerMeter will monitor the power usage and log the function’s carbon footprint.
>>> example_func() result_of_your_function