aihwkit.nn.modules.conv module¶
Convolution layers.
- class aihwkit.nn.modules.conv.AnalogConv1d(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, weight_scaling_omega=None)[source]¶
Bases:
aihwkit.nn.modules.conv._AnalogConvNd
1D convolution layer that uses an analog tile.
Applies a 1D convolution over an input signal composed of several input planes, using an analog tile for 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_channels (int) – number of channels in the input image.
out_channels (int) – number of channels produced by the convolution.
kernel_size (Union[int, Tuple]) – size of the convolving kernel.
stride (Union[int, Tuple]) – stride of the convolution.
padding (Union[int, Tuple]) – zero-padding added to both sides of the input.
dilation (Union[int, Tuple]) – spacing between kernel elements.
groups (int) – number of blocked connections from input channels to output channels.
bias (bool) – whether to use a bias row on the analog tile or not.
padding_mode (str) – padding strategy. Only
'zeros'
is supported.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]]) – resistive processing unit configuration.
realistic_read_write (bool) – whether to enable realistic read/write for setting initial weights and during reading of the weights.
weight_scaling_omega (Optional[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.
- analog_bias: bool¶
- digital_bias: bool¶
- dilation: Tuple[int, ...]¶
- fold_indices: torch.Tensor¶
- classmethod from_digital(module, rpu_config=None, realistic_read_write=False)[source]¶
Return an AnalogConv1d layer from a torch Conv1d layer.
- Parameters
module (torch.nn.modules.conv.Conv1d) – 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.
Note
Make sure that the weight max and min settings of the device support the desired analog weight range.
- Returns
an AnalogConv1d layer based on the digital Conv1d
module
.- Return type
- 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
- groups: int¶
- in_channels: int¶
- in_features: int¶
- input_size: float¶
- kernel_size: Tuple[int, ...]¶
- out_channels: int¶
- out_features: int¶
- output_padding: Tuple[int, ...]¶
- padding: Tuple[int, ...]¶
- padding_mode: str¶
- realistic_read_write: bool¶
- stride: Tuple[int, ...]¶
- transposed: bool¶
- use_bias: bool¶
- weight_scaling_omega: float¶
- 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, weight_scaling_omega=None)[source]¶
Bases:
aihwkit.nn.modules.conv._AnalogConvNd
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.
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_channels (int) – number of channels in the input image.
out_channels (int) – number of channels produced by the convolution.
kernel_size (Union[int, Tuple]) – size of the convolving kernel.
stride (Union[int, Tuple]) – stride of the convolution.
padding (Union[int, Tuple]) – zero-padding added to both sides of the input.
dilation (Union[int, Tuple]) – spacing between kernel elements.
groups (int) – number of blocked connections from input channels to output channels.
bias (bool) – whether to use a bias row on the analog tile or not.
padding_mode (str) – padding strategy. Only
'zeros'
is supported.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]]) – resistive processing unit configuration.
realistic_read_write (bool) – whether to enable realistic read/write for setting initial weights and read out of weights.
weight_scaling_omega (Optional[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.
- analog_bias: bool¶
- digital_bias: bool¶
- dilation: Tuple[int, ...]¶
- fold_indices: torch.Tensor¶
- classmethod from_digital(module, rpu_config=None, realistic_read_write=False)[source]¶
Return an AnalogConv2d layer from a torch Conv2d layer.
- Parameters
module (torch.nn.modules.conv.Conv2d) – 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.
Note
Make sure that the weight max and min settings of the device support the desired analog weight range.
- Returns
an AnalogConv2d layer based on the digital Conv2d
module
.- Return type
- 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
- groups: int¶
- in_channels: int¶
- in_features: int¶
- input_size: float¶
- kernel_size: Tuple[int, ...]¶
- out_channels: int¶
- out_features: int¶
- output_padding: Tuple[int, ...]¶
- padding: Tuple[int, ...]¶
- padding_mode: str¶
- realistic_read_write: bool¶
- stride: Tuple[int, ...]¶
- transposed: bool¶
- use_bias: bool¶
- weight_scaling_omega: float¶
- class aihwkit.nn.modules.conv.AnalogConv3d(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, weight_scaling_omega=None)[source]¶
Bases:
aihwkit.nn.modules.conv._AnalogConvNd
3D convolution layer that uses an analog tile.
Applies a 3D convolution over an input signal composed of several input planes, using an analog tile for 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_channels (int) – number of channels in the input image.
out_channels (int) – number of channels produced by the convolution.
kernel_size (Union[int, Tuple]) – size of the convolving kernel.
stride (Union[int, Tuple]) – stride of the convolution.
padding (Union[int, Tuple]) – zero-padding added to both sides of the input.
dilation (Union[int, Tuple]) – spacing between kernel elements.
groups (int) – number of blocked connections from input channels to output channels.
bias (bool) – whether to use a bias row on the analog tile or not.
padding_mode (str) – padding strategy. Only
'zeros'
is supported.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]]) – resistive processing unit configuration.
realistic_read_write (bool) – whether to enable realistic read/write for setting initial weights and read out of weights.
weight_scaling_omega (Optional[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.
- analog_bias: bool¶
- digital_bias: bool¶
- dilation: Tuple[int, ...]¶
- fold_indices: torch.Tensor¶
- classmethod from_digital(module, rpu_config=None, realistic_read_write=False)[source]¶
Return an AnalogConv3d layer from a torch Conv3d layer.
- Parameters
module (torch.nn.modules.conv.Conv3d) – 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.
Note
Make sure that the weight max and min settings of the device support the desired analog weight range.
- Returns
an AnalogConv3d layer based on the digital Conv3d
module
.- Return type
- 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
- groups: int¶
- in_channels: int¶
- in_features: int¶
- input_size: float¶
- kernel_size: Tuple[int, ...]¶
- out_channels: int¶
- out_features: int¶
- output_padding: Tuple[int, ...]¶
- padding: Tuple[int, ...]¶
- padding_mode: str¶
- realistic_read_write: bool¶
- stride: Tuple[int, ...]¶
- transposed: bool¶
- use_bias: bool¶
- weight_scaling_omega: float¶