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=None)[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 use set_weights and get_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
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)[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[FloatingPointRPUConfig, SingleRPUConfig, UnitCellRPUConfig, InferenceRPUConfig, 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.

    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

AnalogLinear

in_features: int
out_features: int
realistic_read_write: bool
reset_parameters()[source]

Reset the parameters (weight and bias).

Return type

None

use_bias: bool