amago.nets.ff#

Feed-forward network components.

Classes

FFBlock(d_model, d_ff[, dropout, activation])

Feed-forward block with a residual connection.

MLP(d_inp, d_hidden, n_layers, d_output[, ...])

Basic multi-layer feed-forward network.

Normalization(method, d_model)

Quick-switch between different normalization methods.

class FFBlock(d_model, d_ff, dropout=0.0, activation='leaky_relu')[source]#

Bases: Module

Feed-forward block with a residual connection.

Parameters:
  • d_model (int) – Dimension of the input.

  • d_ff (int) – Dimension of the hidden layer.

  • dropout (float) – Dropout rate.

  • activation (str) – Activation function.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

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.

class MLP(d_inp, d_hidden, n_layers, d_output, activation='leaky_relu', dropout_p=0.0)[source]#

Bases: Module

Basic multi-layer feed-forward network.

d_inp –> d_hidden –> … –> d_hidden –> d_output

Parameters:
  • d_inp (int) – Dimension of the input.

  • d_hidden (int) – Dimension of the hidden layer.

  • n_layers (int) – Number of non-output layers (including the input layer)

  • d_output (int) – Dimension of the output.

  • activation (str) – Activation function. See amago.nets.utils.activation_switch for options. Default is “leaky_relu”.

  • dropout_p (float) – Dropout rate. Default is 0.0.

forward(x)[source]#

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

class Normalization(method, d_model)[source]#

Bases: Module

Quick-switch between different normalization methods.

Parameters:
  • method (str) – Normalization method to use. Options are: “layer”, “batch”, “rmsnorm”, “unitball”, “unitball-detach”, “none”. “unitball” is (x / ||x||), “unitball-detach” is (x / ||x||.detach()). “none” is a no-op and the rest are standard LayerNorm, BatchNorm, RMSNorm.

  • d_model (int) – Expected dimension of the input to normalize (scalar). Operates on the last dimensions of the input sequence.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

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.