amago.nets.ff#

Feed-forward network components.

Classes

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

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.

SimNorm([dim])

Simplicial normalization. Adapted from https://arxiv.org/abs/2204.00616. .. tip::.

class FFBlock(d_model, d_ff, dropout=0.0, activation='leaky_relu', norm=None, layer_type=<class 'torch.nn.modules.linear.Linear'>)[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.

  • norm (str | None) – Normalization method for hidden layers. Defaults to None.

  • layer_type (Type[Module]) – Type of linear layer. Defaults to nn.Linear.

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', normalization=None, dropout_p=0.0, layer_type=<class 'torch.nn.modules.linear.Linear'>)[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”.

  • normalization (str | None) – Normalization method for hidden layers. See Normalization for options. Default is None (no normalization).

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

  • layer_type (Type[Module]) – Type of linear layer. Defaults to standard nn.Linear.

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 | None) – 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.

class SimNorm(dim=8)[source]#

Bases: Module

Simplicial normalization. Adapted from https://arxiv.org/abs/2204.00616. .. tip:

This class is ``@gin.configurable``. Default values of kwargs can be overridden using `gin <https://github.com/google/gin-config>`_.
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.