xnn.common.models.blocks.GatedMLP#

class xnn.common.models.blocks.GatedMLP(sizes, activation='silu')[source]#

Bases: Module

A dense stack multiplied by a sigmoid gate of the same input (Chen and Ong, M3GNet 2022).

out = mlp(x) * sigmoid(gate(x)): two stacks of the same sizes, the activation between consecutive layers, the gate’s last layer through a sigmoid.

Parameters:
  • sizes (sequence of int) – Feature sizes from the input to the output, at least two.

  • activation (str or torch.nn.Module, optional) – Activation between the layers (see make_activation()), by default "silu".

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.

Parameters:

x (Tensor)

Return type:

Tensor