aihwkit.nn.modules.rnn.cells module

Analog cells for RNNs.

class aihwkit.nn.modules.rnn.cells.AnalogGRUCell(input_size, hidden_size, bias, rpu_config=None, realistic_read_write=False)[source]

Bases: aihwkit.nn.modules.container.AnalogSequential

Analog GRU Cell.

Parameters
  • input_size (int) – in_features size for W_ih matrix

  • hidden_size (int) – in_features and out_features size for W_hh matrix

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

  • rpu_config (Optional[Union[FloatingPointRPUConfig, SingleRPUConfig, UnitCellRPUConfig, InferenceRPUConfig, DigitalRankUpdateRPUConfig]]) – configuration for an analog resistive processing unit

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

forward(input_, state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters
  • input_ (torch.Tensor) –

  • state (torch.Tensor) –

Return type

Tuple[torch.Tensor, torch.Tensor]

get_zero_state(batch_size)[source]

Returns a zeroed state.

Parameters

batch_size (int) – batch size of the input

Returns

Zeroed state tensor

Return type

torch.Tensor

class aihwkit.nn.modules.rnn.cells.AnalogLSTMCell(input_size, hidden_size, bias, rpu_config=None, realistic_read_write=False)[source]

Bases: aihwkit.nn.modules.container.AnalogSequential

Analog LSTM Cell.

Parameters
  • input_size (int) – in_features size for W_ih matrix

  • hidden_size (int) – in_features and out_features size for W_hh matrix

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

  • rpu_config (Optional[Union[FloatingPointRPUConfig, SingleRPUConfig, UnitCellRPUConfig, InferenceRPUConfig, DigitalRankUpdateRPUConfig]]) – configuration for an analog resistive processing unit

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

forward(input_, state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters
  • input_ (torch.Tensor) –

  • state (Tuple[torch.Tensor, torch.Tensor]) –

Return type

Tuple[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]

get_zero_state(batch_size)[source]

Returns a zeroed state.

Parameters

batch_size (int) – batch size of the input

Returns

Zeroed state tensor

Return type

torch.Tensor

class aihwkit.nn.modules.rnn.cells.AnalogLSTMCellCombinedWeight(input_size, hidden_size, bias, rpu_config=None, realistic_read_write=False)[source]

Bases: aihwkit.nn.modules.container.AnalogSequential

Analog LSTM Cell that use a combined weight for storing gates and inputs.

Parameters
  • input_size (int) – The number of expected features in the input x

  • hidden_size (int) – The number of features in the hidden state h

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

  • rpu_config (Optional[Union[FloatingPointRPUConfig, SingleRPUConfig, UnitCellRPUConfig, InferenceRPUConfig, 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.

forward(input_, state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters
  • input_ (torch.Tensor) –

  • state (Tuple[torch.Tensor, torch.Tensor]) –

Return type

Tuple[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]

get_zero_state(batch_size)[source]

Returns a zeroed state.

Parameters

batch_size (int) – batch size of the input

Returns

Zeroed state tensor

Return type

torch.Tensor

class aihwkit.nn.modules.rnn.cells.AnalogVanillaRNNCell(input_size, hidden_size, bias, rpu_config=None, realistic_read_write=False)[source]

Bases: aihwkit.nn.modules.container.AnalogSequential

Analog Vanilla RNN Cell.

Parameters
  • input_size (int) – in_features size for W_ih matrix

  • hidden_size (int) – in_features and out_features size for W_hh matrix

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

  • rpu_config (Optional[Union[FloatingPointRPUConfig, SingleRPUConfig, UnitCellRPUConfig, InferenceRPUConfig, DigitalRankUpdateRPUConfig]]) – configuration for an analog resistive processing unit

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

forward(input_, state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters
  • input_ (torch.Tensor) –

  • state (torch.Tensor) –

Return type

Tuple[torch.Tensor, torch.Tensor]

get_zero_state(batch_size)[source]

Returns a zeroed state.

Parameters

batch_size (int) – batch size of the input

Returns

Zeroed state tensor

Return type

torch.Tensor

class aihwkit.nn.modules.rnn.cells.LSTMState(hx, cx)

Bases: tuple

property cx

Alias for field number 1

property hx

Alias for field number 0