aihwkit.simulator.noise_models module¶
Phenomenological noise models for inference.
-
class
aihwkit.simulator.noise_models.
BaseConductanceConverter
¶ Bases:
object
Base class for converting DNN weights into conductances.
-
convert_back_to_weights
(conductances, params)¶ Converting a matrix of conductances into weights.
Caution
The conversion is assumed deterministic and repeatable.
- Parameters
conductances – list of conductance tensors representing a weight matrix
params – param dictionary that was returned from the conversion
- Returns
weight matrix
- Return type
torch.Tensor
-
convert_to_conductances
(weights)¶ Converting a weight matrix into conductances.
Caution
The conversion is assumed deterministic and repeatable.
- Parameters
weights – weight matrix tensor.
- Returns
Tuple of the list of conductance tensors and a params dictionary that is used for the reverse conversion.
- Return type
Tuple[List[torch.Tensor], Dict]
-
-
class
aihwkit.simulator.noise_models.
BaseDriftCompensation
¶ Bases:
object
Base class for drift compensations.
-
apply
(forward_output, ref_value)¶ Read out the current value from the output of the forward pass and returns the drift compensation alpha scale.
- Return type
torch.Tensor
-
get_readout_tensor
(in_size)¶ Return the read-out tensor.
Called once during
init_baseline()
.- Return type
torch.Tensor
-
init_baseline
(forward_output)¶ Initialize the base line for applying the compensation.
Uses a all one tensor for read_out.
- Parameters
forward_output – forward output of the read out vector to compensate
- Returns
reference tensor readout
- Return type
Tuple[torch.Tensor, torch.Tensor]
-
readout
(out_tensor)¶ Implements the read out math.
- Return type
torch.Tensor
-
-
class
aihwkit.simulator.noise_models.
BaseNoiseModel
(g_converter=None)¶ Bases:
object
Base class for phenomenological noise models for inference.
-
apply_drift_noise
(weights, nu_drift_list, t_inference)¶ Applies the expected drift noise to weights.
Uses the
apply_drift_noise_to_conductances()
on each of the conductance slices.- Parameters
weights – weights tensor (usually with programming noise already applied)
nu_drift_list – list of drift nu for each conductance slice
t_inference – assumed time of inference (in sec)
- Returns
weight tensor with drift noise applied
- Return type
torch.Tensor
-
apply_drift_noise_to_conductance
(g_prog, nu_drift, t_inference)¶ Apply the noise and drift up to the assumed inference time point.
- Parameters
g_prog – Tensor of conductance values after programming (in \(\muS\))
nu_drift – drift nu
t_inference – assumed time of inference (in sec)
- Returns
conductance Tensor with applied noise and drift
- Return type
torch.Tensor
-
apply_noise
(weights, t_inference)¶ Applies the expected noise.
Applies the noise to a non-perturbed conductance matrix
weights
at time of inferencet_inference
(in seconds) where 0 sec refers to the time when weight programming has finished.Note
The drift coefficients and intermediate noises etc. are sampled for each application of this function anew from the distributions, thus it samples the expected noise and drift behavior at time
t_inference
but not a continual trajectory of a given device instance over time (having e.g. constant drift coefficients).- Return type
torch.Tensor
-
apply_programming_noise
(weights)¶ Applies the expected programming noise to weights.
Uses the
apply_programming_noise_to_conductances()
on each of the conductance slices.- Parameters
weights – weights tensor
- Returns
weight tensor with programming noise applied, and tuple of all drift coefficients (per conductances slice) that are determined during programming.
- Return type
Tuple[torch.Tensor, List[torch.Tensor]]
-
apply_programming_noise_to_conductance
(g_target)¶ Apply programming noise to a target conductance
Tensor
.- Parameters
g_target – Target conductances
- Returns
Tensor of sampled drift coefficients \(\nu\), one for each target conductance value.
- Return type
torch.Tensor
-
generate_drift_coefficients
(g_target)¶ Generates drift coefficients
nu
based on the target conductances.- Return type
torch.Tensor
-
-
class
aihwkit.simulator.noise_models.
GlobalDriftCompensation
¶ Bases:
aihwkit.simulator.noise_models.BaseDriftCompensation
Global drift compensation.
Uses a constant factor for compensating the drift.
-
get_readout_tensor
(in_size)¶ Returns the read-out tensor.
Uses a single all one vector.
- Return type
torch.Tensor
-
readout
(out_tensor)¶ Read outs the abs max.
- Return type
torch.Tensor
-
-
class
aihwkit.simulator.noise_models.
PCMLikeNoiseModel
(prog_coeff=None, g_converter=None, g_max=None, t_read=2.5e-07, t_0=20.0)¶ Bases:
aihwkit.simulator.noise_models.BaseNoiseModel
Noise model that was fitted and characterized on real PCM devices.
Expected weight noise at assumed time of inference with expected programming noise at 0.
The statistical noise model is based on measured PCM devices.
- Parameters
prog_coeff – programming polynomial coeffs in \(\mu S\), c(0) + c(1)*gt + c(2)*gt^2)
g_converter – instantiated class of the conductance converter (defaults to single pair)
t_read – parameter of the 1/f fit (in seconds)
t_0 – parameter of the drift fit (first reading time)
Note – The
t_inference
is relative to this time t0 e.g. t_inference counts from the completion of the programming of a device.
-
apply_drift_noise_to_conductance
(g_prog, nu_drift, t_inference)¶ Apply the noise and drift up to the assumed inference time point based on PCM measurements.
- Return type
torch.Tensor
-
apply_programming_noise_to_conductance
(g_target)¶ Apply programming noise to a target conductance Tensor.
Programming noise with additive Gaussian noise with conductance dependency of the variance given by a 2-degree polynomial.
- Return type
torch.Tensor
-
generate_drift_coefficients
(g_target)¶ Return drift coefficients
nu
based on PCM measurements.- Return type
torch.Tensor
-
class
aihwkit.simulator.noise_models.
SinglePairConductanceConverter
(g_max=None, g_min=None)¶ Bases:
aihwkit.simulator.noise_models.BaseConductanceConverter
Single pair of devices.
Assuming a single pair of devices per cross-point, taking positive and negative weights, respectively, where one device is always at 0.
- Parameters
g_max – In \(\mu S\), the maximal conductance, ie the value the absolute max of the weights will be mapped to.
g_min – In \(\mu S\), the minimal conductance, ie the value the logical zero of the weights will be mapped to.
-
convert_back_to_weights
(conductances, params)¶ Converting a matrix of conductances into weights.
Caution
The conversion is assumed deterministic and repeatable.
- Parameters
conductances – list of conductance tensors representing a weight matrix
params – param dictionary that was returned from the conversion
- Returns
weight matrix
- Return type
torch.Tensor
-
convert_to_conductances
(weights)¶ Converting a weight matrix into conductances.
Caution
The conversion is assumed deterministic and repeatable.
- Parameters
weights – weight matrix tensor.
- Returns
Tuple of the list of conductance tensors and a params dictionary that is used for the reverse conversion.
- Return type
Tuple[List[torch.Tensor], Dict]