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
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
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
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

aihwkit.nn.modules.rnn.cells.sigmoid(input, *, out=None)Tensor

Alias for torch.special.expit().

aihwkit.nn.modules.rnn.cells.tanh(input, *, out=None)Tensor

Returns a new tensor with the hyperbolic tangent of the elements of input.

\[\text{out}_{i} = \tanh(\text{input}_{i})\]
Parameters

input (Tensor) – the input tensor.

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.8986, -0.7279,  1.1745,  0.2611])
>>> torch.tanh(a)
tensor([ 0.7156, -0.6218,  0.8257,  0.2553])