aihwkit.nn.modules.conv_mapped module

Mapped convolution layers.

class aihwkit.nn.modules.conv_mapped.AnalogConv1dMapped(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', rpu_config=None, tile_module_class=None)[source]

Bases: _AnalogConvNdMapped

1D convolution layer that maps to analog tiles.

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

The module will split the weight matrix onto multiple tiles if necessary. Physical max tile sizes are specified with MappingParameter in the RPU configuration, see RPUConfigBase.

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:
  • in_channels (int) – number of channels in the input image.

  • out_channels (int) – number of channels produced by the convolution.

  • kernel_size (Tuple[int, ...]) – size of the convolving kernel.

  • stride (Tuple[int, ...]) – stride of the convolution.

  • padding (str | Tuple[int, ...]) – zero-padding added to both sides of the input.

  • dilation (Tuple[int, ...]) – spacing between kernel elements.

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

  • bias (Tensor | None) – whether to use a bias row on the analog tile or not.

  • padding_mode (str) – padding strategy. Only 'zeros' is supported.

  • rpu_config (MappableRPU | None) – resistive processing unit configuration.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

classmethod from_digital(module, rpu_config, tile_module_class=None)[source]

Return an AnalogConv1dMapped layer from a torch Conv1d layer.

Parameters:
  • module (Conv1d) – The torch module to convert. All layers that are defined in the conversion_map.

  • rpu_config (RPUConfigBase) – RPU config to apply to all converted tiles. Applied to all converted tiles.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

Returns:

an AnalogConv1d layer based on the digital Conv1d module.

Raises:

ConfigError – In case the RPUConfig is not of type MappableRPU

Return type:

AnalogConv1dMapped

get_tile_size(in_channels, groups, kernel_size)[source]

Calculate the tile size.

Parameters:
  • in_channels (int) –

  • groups (int) –

  • kernel_size (Tuple[int, ...]) –

Return type:

int

classmethod to_digital(module, realistic=False)[source]

Return an nn.Conv1d layer from an AnalogConv1dMapped layer.

Parameters:
  • module (AnalogConv1dMapped) – The analog module to convert.

  • realistic (bool) – whehter to estimate the weights with the non-ideal forward pass. If not set, analog weights are (unrealistically) copies exactly

Returns:

an torch Linear layer with the same dimension and weights as the analog linear layer.

Return type:

Conv1d

class aihwkit.nn.modules.conv_mapped.AnalogConv2dMapped(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', rpu_config=None, tile_module_class=None, use_indexed=None)[source]

Bases: _AnalogConvNdMapped

2D convolution layer that maps to analog tiles.

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 module will split the weight matrix onto multiple tiles if necessary. Physical max tile sizes are specified with MappingParameter in the RPU configuration, see RPUConfigBase.

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:
  • in_channels (int) – number of channels in the input image.

  • out_channels (int) – number of channels produced by the convolution.

  • kernel_size (Tuple[int, ...]) – size of the convolving kernel.

  • stride (Tuple[int, ...]) – stride of the convolution.

  • padding (str | Tuple[int, ...]) – zero-padding added to both sides of the input.

  • dilation (Tuple[int, ...]) – spacing between kernel elements.

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

  • bias (Tensor | None) – whether to use a bias row on the analog tile or not.

  • padding_mode (str) – padding strategy. Only 'zeros' is supported.

  • rpu_config (MappableRPU | None) – resistive processing unit configuration.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

  • use_indexed (bool | None) – Whether to use explicit unfolding or implicit indexing. If None (default), it will use implicit indexing for CUDA and explicit unfolding for CPU

classmethod from_digital(module, rpu_config, tile_module_class=None)[source]

Return an AnalogConv2dMapped layer from a torch Conv2d layer.

Parameters:
  • module (Conv2d) – The torch module to convert. All layers that are defined in the conversion_map.

  • rpu_config (RPUConfigBase) – RPU config to apply to all converted tiles. Applied to all converted tiles.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

Returns:

an AnalogConv2dMapped layer based on the digital Conv2d module.

Raises:

ConfigError – In case the RPUConfig is not of type MappableRPU

Return type:

AnalogConv2dMapped

get_tile_size(in_channels, groups, kernel_size)[source]

Calculate the tile size.

Parameters:
  • in_channels (int) –

  • groups (int) –

  • kernel_size (Tuple[int, ...]) –

Return type:

int

classmethod to_digital(module, realistic=False)[source]

Return an nn.Conv2d layer from an AnalogConv2dMapped layer.

Parameters:
  • module (AnalogConv2dMapped) – The analog module to convert.

  • realistic (bool) – whehter to estimate the weights with the non-ideal forward pass. If not set, analog weights are (unrealistically) copies exactly

Returns:

an torch Linear layer with the same dimension and weights as the analog linear layer.

Return type:

Conv2d

class aihwkit.nn.modules.conv_mapped.AnalogConv3dMapped(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', rpu_config=None, tile_module_class=None)[source]

Bases: _AnalogConvNdMapped

3D convolution layer that maps to analog tiles.

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

The module will split the weight matrix onto multiple tiles if necessary. Physical max tile sizes are specified with MappingParameter in the RPU configuration, see RPUConfigBase.

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:
  • in_channels (int) – number of channels in the input image.

  • out_channels (int) – number of channels produced by the convolution.

  • kernel_size (Tuple[int, ...]) – size of the convolving kernel.

  • stride (Tuple[int, ...]) – stride of the convolution.

  • padding (str | Tuple[int, ...]) – zero-padding added to both sides of the input.

  • dilation (Tuple[int, ...]) – spacing between kernel elements.

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

  • bias (Tensor | None) – whether to use a bias row on the analog tile or not.

  • padding_mode (str) – padding strategy. Only 'zeros' is supported.

  • rpu_config (MappableRPU | None) – resistive processing unit configuration.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

Raises:

ModuleError – Tiling weight matrices is always done across channels only. If the kernel number of elements is larger than the maximal tile size, mapping cannot be done

classmethod from_digital(module, rpu_config, tile_module_class=None)[source]

Return an AnalogConv3dMapped layer from a torch Conv3d layer.

Parameters:
  • module (Conv3d) – The torch module to convert. All layers that are defined in the conversion_map.

  • rpu_config (RPUConfigBase) – RPU config to apply to all converted tiles. Applied to all converted tiles.

  • tile_module_class (Type | None) – Class for the tile module (default will be specified from the RPUConfig).

Returns:

an AnalogConv3d layer based on the digital Conv3d module.

Raises:

ConfigError – In case the RPUConfig is not of type MappableRPU

Return type:

AnalogConv3dMapped

get_tile_size(in_channels, groups, kernel_size)[source]

Calculate the tile size.

Parameters:
  • in_channels (int) –

  • groups (int) –

  • kernel_size (Tuple[int, ...]) –

Return type:

int

classmethod to_digital(module, realistic=False)[source]

Return an nn.Conv3d layer from an AnalogConv3dMapped layer.

Parameters:
  • module (AnalogConv3dMapped) – The analog module to convert.

  • realistic (bool) – whehter to estimate the weights with the non-ideal forward pass. If not set, analog weights are (unrealistically) copies exactly

Returns:

an torch Linear layer with the same dimension and weights as the analog linear layer.

Return type:

Conv3d