agnapprox.utils.error_stats
#
Implementations for several probabilistic error models
Module Contents#
Functions#
|
Generate error mean and standard deviation using Monte Carlo |
|
Generate error mean and standard deviation using the |
|
Randomly select samples from a tensor that cover the receptive field of one neuron |
|
Generate prediction of mean and standard deviation using several |
|
Turn tensor of weights/activations into a frequency distribution (i.e. build a histogram) |
|
Calculate mean and standard deviation of the observed error between |
- agnapprox.utils.error_stats.single_dist_mc(emap: numpy.ndarray, x_dist: numpy.ndarray, w_dist: numpy.ndarray, fan_in: float, num_samples: int = int(100000.0)) Tuple[float, float] [source]#
Generate error mean and standard deviation using Monte Carlo approach as described in: https://arxiv.org/abs/1912.00700
- Parameters:
emap – The multiplier’s error map
x_dist – Operand distribution of activations
w_dist – Operand distribution of weights
fan_in – Incoming connections for layer
num_samples – Number of Monte Carlo simulation runs. Defaults to int(1e5).
- Returns:
Mean and standard deviation for a single operation
- agnapprox.utils.error_stats.error_prediction(emap: numpy.ndarray, x_dist: numpy.ndarray, w_dist: numpy.ndarray, fan_in: float) Tuple[float, float] [source]#
Generate error mean and standard deviation using the global distribution of activations and weights
- Parameters:
emap – The multiplier’s error map
x_dist – Operand distribution of activations
w_dist – Operand distribution of weights
fan_in – Incoming connections for layer
- Returns:
Mean and standard deviation for a single operation
- agnapprox.utils.error_stats.get_sample_population(tensor: numpy.ndarray, num_samples: int = 512) numpy.ndarray [source]#
Randomly select samples from a tensor that cover the receptive field of one neuron
- Parameters:
tensor – Tensor to draw samples from
num_samples – Number of samples to draw. Defaults to 512.
- Returns:
Sampled 2D Tensor of shape [num_samples, tensor.shape[-1]]
- agnapprox.utils.error_stats.population_prediction(emap: numpy.ndarray, x_multidist: numpy.ndarray, w_dist: numpy.ndarray, fan_in: float) Tuple[float, float] [source]#
Generate prediction of mean and standard deviation using several sampled local distributions
- Parameters:
emap – The multiplier’s error map
x_multidist – Array of several operand distributions for activations
w_dist – Operand distribution of weights
fan_in – Incoming connections for layer
- Returns:
Mean and standard deviation for a single operation
- agnapprox.utils.error_stats.to_distribution(tensor: Optional[numpy.ndarray], min_val: int, max_val: int) Tuple[numpy.ndarray, numpy.ndarray] [source]#
Turn tensor of weights/activations into a frequency distribution (i.e. build a histogram)
- Parameters:
tensor – Tensor to build histogram from
min_val – Lowest possible operand value in tensor
max_val – Highest possible operand value in tensor
- Returns:
Tuple of Arrays where first array contains the full numerical range between min_val and max_val inclusively and second array contains the relative frequency of each operand
- Raises:
ValueError – If run before features maps have been populated
by call to utils.model.get_feature_maps –
- agnapprox.utils.error_stats.error_calculation(accurate: numpy.ndarray, approximate: numpy.ndarray, fan_in: float) Tuple[float, float] [source]#
Calculate mean and standard deviation of the observed error between accurate computation and approximate computation
- Parameters:
accurate – Accurate computation results
approximate – Approximate computation results
fan_in – Number of incoming neuron connections
- Returns:
Mean and standard deviation for a single operation