aihwkit.nn.modules.linear module¶
Analog layers.
-
class
aihwkit.nn.modules.linear.
AnalogLinear
(in_features, out_features, bias=True, rpu_config=None, realistic_read_write=False, weight_scaling_omega=0.0)[source]¶ Bases:
aihwkit.nn.modules.base.AnalogModuleBase
,torch.nn.modules.linear.Linear
Linear layer that uses an analog tile.
Linear layer that uses an analog tile during its forward, backward and update passes.
Note
The tensor parameters of this layer (
.weight
and.bias
) are not guaranteed to contain the same values as the internal weights and biases stored in the analog tile. Please useset_weights
andget_weights
when attempting to read or modify the weight/bias. This read/write process can simulate the (noisy and inexact) analog writing and reading of the resistive elements.- Parameters
in_features – input vector size (number of columns).
out_features – output vector size (number of rows).
rpu_config – resistive processing unit configuration.
bias – whether to use a bias row on the analog tile or not.
realistic_read_write – whether to enable realistic read/write for setting initial weights and during reading of the weights.
weight_scaling_omega – the weight value that the current max weight value will be scaled to. If zero, no weight scaling will be performed.
-
analog_bias
: bool¶
-
digital_bias
: bool¶
-
forward
(x_input)[source]¶ Compute the forward pass.
- Parameters
x_input (torch.Tensor) –
- Return type
torch.Tensor
-
classmethod
from_digital
(module, rpu_config=None, realistic_read_write=False, weight_scaling_omega=0.0)[source]¶ Return an AnalogLinear layer from a torch Linear layer.
- Parameters
module (torch.nn.modules.linear.Linear) – The torch module to convert. All layers that are defined in the
conversion_map
.rpu_config (Optional[Union[aihwkit.simulator.configs.configs.FloatingPointRPUConfig, aihwkit.simulator.configs.configs.SingleRPUConfig, aihwkit.simulator.configs.configs.UnitCellRPUConfig, aihwkit.simulator.configs.configs.InferenceRPUConfig, aihwkit.simulator.configs.configs.DigitalRankUpdateRPUConfig]]) – RPU config to apply to all converted tiles. Applied to all converted tiles.
realistic_read_write (bool) – Whether to use closed-loop programming when setting the weights. Applied to all converted tiles.
weight_scaling_omega (float) –
If non-zero, the analog weights will be scaled by
weight_scaling_omega
divided by the absolute maximum value of the original weight matrix.Note
Make sure that the weight max and min settings of the device support the desired analog weight range.
- Returns
an AnalogLinear layer based on the digital Linear
module
.- Return type
-
in_features
: int¶
-
out_features
: int¶
-
realistic_read_write
: bool¶
-
use_bias
: bool¶
-
weight_scaling_omega
: float¶