agnapprox.utils.select_multipliers
#
Utility functions to select approximate multipliers based on reference data
Module Contents#
Classes#
Multiplier Matching result for a single layer |
|
Multiplier Matching result for the entire model |
Functions#
|
Select a matching approximate multiplier for a single layer |
|
Deploy selected approximate multipliers to network |
|
Select matching Approximate Multipliers for all layers in a model |
Attributes#
- agnapprox.utils.select_multipliers.logger#
- agnapprox.utils.select_multipliers.select_layer_multiplier(intermediate_results: agnapprox.utils.model.IntermediateLayerResults, multipliers: List[evoapproxlib.ApproximateMultiplier], max_noise: float, num_samples: int = 512) Tuple[str, float] [source]#
Select a matching approximate multiplier for a single layer
- Parameters:
layer_ref_data – Reference input/output data generated from a model run with accurate multiplication. This is used to calibrate the layer standard deviation for the error estimate and determine the distribution of numerical values in weights and activations.
multipliers – Approximate Multiplier Error Maps, Performance Metrics and name
max_noise – Learned allowable noise parameter (sigma_l)
num_samples – Number of samples to draw from features for multi-population prediction. Defaults to 512.
- Returns:
Dictionary with name and performance metric of selected multiplier
- class agnapprox.utils.select_multipliers.LayerInfo[source]#
Multiplier Matching result for a single layer
- name :str#
- multiplier_name :str#
- multiplier_performance_metric :float#
- opcount :float#
- relative_opcount(total_opcount: float)[source]#
Calculate the relative contribution of this layer to the network’s total operations
- Parameters:
total_opcount – Number of operations in the entire networks
- Returns:
0: layer contributes no operations to the network’s opcount
1: layer conttibutes all operations to the network’s opcount
- Return type:
float between 0..1 where
- relative_energy_consumption(metric_max: float)[source]#
Relative energy consumption of selected approximate multiplier
- Parameters:
metric_max – Highest possible value for performance metric (typically that of the respective accurate multiplier)
- Returns:
0: selected multiplier consumes no energy
1: selected multiplier consumes the maximum amount of energy
- Return type:
float between 0..1 where
- class agnapprox.utils.select_multipliers.MatchingInfo[source]#
Multiplier Matching result for the entire model
- layers :List[LayerInfo]#
- metric_max :float#
- opcount :float#
- property relative_energy_consumption#
Relative Energy Consumption compared to network without approximation achieved by the current AM configuration
- Returns:
sum relative energy consumption for each layer, weighted with the layer’s contribution to overall operations
- agnapprox.utils.select_multipliers.deploy_multipliers(model: agnapprox.nets.ApproxNet, matching_result: MatchingInfo, library)[source]#
Deploy selected approximate multipliers to network
- Parameters:
model – Model to deploy multipliers to
matching_result – Results of multiplier matching
library – Library to load Lookup tables from
- agnapprox.utils.select_multipliers.select_multipliers(model: agnapprox.nets.ApproxNet, datamodule: pytorch_lightning.LightningDataModule, multipliers: List[evoapproxlib.ApproximateMultiplier], trainer: pytorch_lightning.Trainer) MatchingInfo [source]#
Select matching Approximate Multipliers for all layers in a model
- Parameters:
model – Approximate Model with learned layer robustness parameters
datamodule – Data Module to use for sampling runs
library – Approximate Multiplier Library provider
trainer – PyTorch Lightning Trainer instance to use for sampling run
signed – Whether to select signed or unsigned instances from Multiplier library provide. Defaults to True.
- Returns:
Dictionary of Assignment results