API documentation

GATorch principal class is GA.

GATorch.GA

class GATorch.GA[source]
attach_model(model, loss=None, named_layer=True, profiler='pyjoules', disable_measurements=[])[source]

Attach a model to the GA profiler. You can add also a loss function. The profiler will then track the energy consumption of the attached model.

Parameters
  • model (torch.nn.module) – PyTorch model you want to track.

  • loss (torch.nn.module) – Loss function to be passed for tracking the consumption of the loss computation.

  • named_layers (boolean) – Set to False to not track individual named layers.

  • profiler (string) – Typed of profiler used to track the energy consumption. Currently only ‘pyjoules’ is implemented.

  • disable_measurements (list) – Set which hardware components you are not intrested in tracking between cpu, ram and gpu.

detach_model()[source]

Detach the current model from the GA profiler.

get_full_measurements()[source]

Get the full measurements collected by the profiler.

Returns

The energy consumptions for each pass and model component.

Return type

dict

get_mean_measurements()[source]

Get the mean of the measurements collected by the profiler.

Returns

The mean energy consumption for each model component.

Return type

dict

get_sum_measurements()[source]

Get the sum of the measurements collected by the profiler.

Returns

The full energy consumption for each model component.

Return type

dict

get_losses()[source]
to_pandas()[source]

Convert the energy measurements into a pandas.DataFrame object.

Returns

The dataframe of the energy consumption for each model component.

Return type

pandas.DataFrame

to_csv(filename)[source]

Save the energy measurements into a csv file.

Parameters

filename (string) – Name of the csv file.

visualize_data(layers='all', complete_model=True, loss=False, phase='total', kind='line', smoothing=0.3, figsize=None, filename=None)[source]

Generate a matplotlib plot for the energy measurements.

Parameters
  • layers (list or string) – Pass in a list which named layers you want to display. Pass ‘all’ if you want to see all of them.

  • complete_model (boolean) – Set to False if you don’t want to see the data for the complete model.

  • loss (boolean) – Set to True to display also the loss function data.

  • phase (string) – Select which phase to display between ‘total’, ‘forward’ or ‘backward’.

  • kind (string) – Select which type of plot to generate between ‘line’, ‘violin’ or ‘box’.

  • smoothing (float) – Only used for lineplots. Value between 0 and 1 used to add smoothing to the displayed data.

  • figsize (Tuple) – Size of the figure generated.

  • filename (string) – Pass a filename if you want to save the image created.

Returns

The matplotlib axes containing the plot.

Return type

Axes

start_tracker_emissions(save_to_file=False)[source]

Start a tracker for carbon emission. Implemented using codecarbon.

Parameters

save_to_file (boolean) – Save the tracking results in a file called ‘emissions’.

stop_tracker_emissions()[source]

Stop the tracker for carbon emission.

Returns

The total emissions produced by the model since the tracker was started.

Return type

float

set_tensorboard_stats(writer=None, experiment=0, named_layer=True, sample_size=500)[source]

Sets the tensorboard data that can be viewed through the tensorboard dashboard.

Parameters
  • writer (torch.utils.tensorboard.SummaryWriter) – Optionally pass an already existing tensorboard writer.

  • experiment (int) – Set an identifier for the displayed data.

  • named_layer (boolean) – Indicate if the named layers should also be displayed in tensorboard.

  • sample_size (int) – Size of the sample size used to define a loss step. Used to compute the grap for energy per loss step.

reset(emission_tracker=True)[source]

Reset all the measurements.

Parameters

emission_tracker (boolean) – Indicates if the emissions tracker needs to be reset as well.