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[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]]) – 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]
- 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[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]]) – 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]]
- 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[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]]) – 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]
- 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])