aihwkit.nn.modules.conv module

Convolution layers.

class aihwkit.nn.modules.conv.AnalogConv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', rpu_config=None, realistic_read_write=False)

Bases: torch.nn.modules.conv.Conv2d, aihwkit.nn.modules.base.AnalogModuleBase

2D convolution layer that uses an analog tile.

Applies a 2D convolution over an input signal composed of several input planes, using an analog tile for its forward, backward and update passes.


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.

  • in_channels – number of channels in the input image.

  • out_channels – number of channels produced by the convolution.

  • kernel_size – size of the convolving kernel.

  • stride – stride of the convolution-

  • padding – zero-padding added to both sides of the input.

  • dilation – spacing between kernel elements.

  • groups – number of blocked connections from input channels to output channels.

  • bias – whether to use a bias row on the analog tile or not

  • padding_mode – padding strategy. Only 'zeros' is supported.

  • rpu_config – resistive processing unit configuration.

  • realistic_read_write – whether to enable realistic read/write for setting initial weights and read out of weights

dilation: Tuple[int, int]

Set the extra representation of the module

To print customized extra information, you should reimplement this method in your own modules. Both single-line and multi-line strings are acceptable.

Return type


fold_indices: Tensor

Computes the forward pass.


x_input (torch.Tensor) –

Return type


in_channels: int
in_features: int
input_size: float
kernel_size: Tuple[int, int]
out_channels: int
out_features: int
padding: Tuple[int, int]
realistic_read_write: bool

Reset the parameters (weight and bias).

Return type


stride: Tuple[int, int]