amago.nets.ff#
Feed-forward network components.
Classes
|
Feed-forward block with a residual connection. |
|
Basic multi-layer feed-forward network. |
|
Quick-switch between different normalization methods. |
- class FFBlock(d_model, d_ff, dropout=0.0, activation='leaky_relu')[source]#
Bases:
ModuleFeed-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:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance 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:
ModuleBasic 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. Seeamago.nets.utils.activation_switchfor 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
Moduleinstance 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:
ModuleQuick-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:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.